Skip to content

docs: explain save vs save_weights for TFQ layers - #1120

Open
SripriyaDevarapalli wants to merge 1 commit into
tensorflow:masterfrom
SripriyaDevarapalli:docs-save-vs-save-weights
Open

SripriyaDevarapalli wants to merge 1 commit into
tensorflow:masterfrom
SripriyaDevarapalli:docs-save-vs-save-weights

Conversation

@SripriyaDevarapalli

Copy link
Copy Markdown

Description

This pull request addresses the documentation issue in #899 regarding the behavior of tf.keras.Model.save() versus save_weights() for TensorFlow Quantum (TFQ) layers.

Summary of changes

  • Documents the reported serialization issue when saving complete Keras models containing TFQ layers that may not support configuration serialization.
  • Explains save_weights() as an alternative when complete model serialization fails.
  • Provides a Python example showing how to save weights and load them into a recreated model architecture.
  • Links to the TFQ installation guide and notes that saving and loading behavior may depend on the TensorFlow and Keras versions in use.

Related to #899 and #56.

How Has This Been Tested?

  • Ran git diff --cached --check successfully.
  • Reviewed the documentation changes.
    • A TFQ runtime save/load test could not be completed because the local checkout lacks the compiled native operation library required to import TFQ.
  • This is a documentation-only change; no source code or tests were modified.

Test Configuration:

  • Python version: 3.11
  • Operating system: Windows
  • TensorFlow version: 2.19.1
  • tf-keras version: 2.19.0

AI use

  • No AI tool was used.
  • AI-assisted: I did the research and wrote the change, and used an AI tool for parts of it (for example completion, editing or review).
  • AI-generated: an AI tool did most of the research or wrote most of the change. I have read all of it and can explain it.
  • Translated into English with an AI tool.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new errors or warnings
  • My code and tests pass locally and have at least 80% line coverage
  • Any dependent changes have been merged and published in downstream modules

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the design documentation in docs/design.md to include a new section on saving Keras models. It explains why saving a complete model with tf.keras.Model.save() can fail for certain layers and provides a code example demonstrating how to use save_weights() and load_weights() as a workaround. There are no review comments, so there is no feedback to provide.

@SripriyaDevarapalli

SripriyaDevarapalli commented Oct 13, 2026 •

Copy link
Copy Markdown
Author

Hey @mhucka I've created a PR #1120 addressing the documentation issue regarding the behavior of save() versus save_weights() for TensorFlow Quantum layers.

The changes explain the reported serialization issue, document save_weights() as an alternative, and include a usage example, and if you have any suggestions for improvement please do let me know .

Thank you!

@SripriyaDevarapalli

Copy link
Copy Markdown
Author

I also noticed that the CI run failed in the Tutorial tests job.

The logs show an ImportError indicating that pydot and/or Graphviz are missing when tf.keras.utils.plot_model() is called. The file format and lint checks, wheel test, and library tests all passed.

This appears to be a missing dependency in the tutorial test environment rather than an issue caused by my documentation changes. I wanted to bring this to your attention for investigation.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant