Repository navigation
docs: clarify save vs save_weights for TFQ models - #1115
akhil9tiet wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
| 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()`. |
There was a problem hiding this comment.
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.Layersubclasses.model.save()fails on TFQ's built-in layers. Referring to them as "custom quantum layers" implies that built-in TFQ layers supportmodel.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 ascirq.Circuitandcirq.PauliSum) in__init__and do not implement Keras'sget_config()method. -
The whole motivation for #899 (from #56) is that
model.save()fails with an uninformativeNotEncodableErrororNotImplementedError(mentioningget_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 modelssubsection referencingmodel.save(),model.save_weights(), andmodel.load_weights()here does not fit the surrounding document context.
|
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. |
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).