tensorflow / tensorflow/quantum
Document behavior of `save` versus `save_weights`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 665
- PR merge metrics
- No merged PRs in 30d
Description
In issue https://github.com/tensorflow/quantum/issues/56, there is a request for improving the docs:
Would like to +1 this, and ask that it is made clear(er) in the documentation that although
savewon't work,save_weightswill.This is because the error given when calling
savedoesn't indicate that this is the problem; in my case, I gotFile "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 98, in encode_structure return self._map_structure(nested_structure, self._get_encoders()) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 82, in _map_structure return do(pyobj, recursion_fn) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 237, in do_encode pair.value.CopyFrom(encode_fn(named_tuple_value._asdict()[key])) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 82, in _map_structure return do(pyobj, recursion_fn) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 206, in do_encode encoded_dict.dict_value.fields[key].CopyFrom(encode_fn(value)) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 83, in _map_structure raise NotEncodableError( tensorflow.python.saved_model.nested_structure_coder.NotEncodableError: No encoder for object [<tensorflow.python.keras.initializers.initializers_v2.RandomUniform object at 0x7f241a041880>] of type [<class 'tensorflow.python.keras.initializers.initializers_v2.RandomUniform'>].Only when explicitly calling the model's
get_config()method did I getFile "learn_params.py", line 194, in <module> print(model.get_config()) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 598, in get_config return copy.deepcopy(get_network_config(self)) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 1278, in get_network_config layer_config = serialize_layer_fn(layer) File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 250, in serialize_keras_object raise e File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 245, in serialize_keras_object config = instance.get_config() File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 676, in get_config raise NotImplementedError('Layer %s has arguments in `__init__` and ' NotImplementedError: Layer ControlledPQC has arguments in `__init__` and therefore must override `get_config`.
Originally posted by @mikeevmm in #56
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the behavior described in issue #56 and the reported save and save_weights methods. Update the relevant documentation to explain that save may fail for models with non-serializable configuration while save_weights works, and include enough context for users to recognize the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100