Skip to content

docs: clarify save vs save_weights for TFQ models - #1115

Closed
akhil9tiet wants to merge 6 commits into
tensorflow:masterfrom
akhil9tiet:docs/899-save-vs-save-weights
Closed

akhil9tiet wants to merge 6 commits into
tensorflow:masterfrom
akhil9tiet:docs/899-save-vs-save-weights

Conversation

@akhil9tiet

Copy link
Copy Markdown

Fixes #899

Adds a short note to docs/concepts.md clarifying that model.save() does not work for TFQ models with custom quantum layers, and that model.save_weights() should be used instead (with the model architecture rebuilt in Python before loading).

@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 docs/concepts.md documentation by replacing curly apostrophes with straight apostrophes, updating a link for 'Quantum convolutional neural networks' to point to an arXiv paper, and adding a new 'Saving models' section that explains how to save and load TensorFlow Quantum models using weights serialization. There are no review comments, so I have no feedback to provide.

Comment thread docs/concepts.md Outdated
@akhil9tiet
akhil9tiet requested a review from mhucka October 12, 2026 18:56

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A recent fix in the main branch solves the notebook test failures. You can remove the changes to this file. (BTW, this would have mixed two unrelated types of changes into one PR, which is bad practice.)

Comment thread docs/concepts.md
Comment on lines +90 to +94
Note: `model.save()` does not work for TensorFlow Quantum models containing
custom quantum layers, because full model serialization requires the layer
to be reconstructable without the original Python code. Instead, use
`model.save_weights()` to save the trained parameters, then rebuild the model
architecture in Python and restore them with `model.load_weights()`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is incorrect in multiple ways.

  • Using the term "custom quantum layers" here is misleading. In Keras terminology, "custom layers" refers to user-defined tf.keras.layers.Layer subclasses. model.save() fails on TFQ's built-in layers. Referring to them as "custom quantum layers" implies that built-in TFQ layers support model.save() and only user-subclassed layers fail.

  • Stating "because full model serialization requires the layer to be reconstructable without the original Python code" describes the purpose of model.save(), not why it fails in TFQ. It fails because TFQ layers accept non-TensorFlow objects (such as cirq.Circuit and cirq.PauliSum) in __init__ and do not implement Keras's get_config() method.

  • The whole motivation for #899 (from #56) is that model.save() fails with an uninformative NotEncodableError or NotImplementedError (mentioning get_config). This doesn't actually help the user.

  • The file docs/concepts.md ("Quantum machine learning concepts") is a high-level conceptual overview of quantum computing, quantum data, and QML research. It contains no code snippets or Keras/TFQ API references. Dropping a #### Saving models subsection referencing model.save(), model.save_weights(), and model.load_weights() here does not fit the surrounding document context.

@mhucka

mhucka commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

I am sorry to say this, but this PR does not adequately address the issue, and shows signs of being the result of applying an AI agent without sufficient human review or understanding of the subject matter. Closing this PR because it is not constructive and the repository maintainers cannot afford the time to iterate on low-quality LLM output.

@mhucka mhucka closed this Oct 14, 2026
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.

Document behavior of save versus save_weights

2 participants