keras icon indicating copy to clipboard operation
keras copied to clipboard

model trainable params have changed after saving and reloading

Open innat opened this issue 1 year ago • 2 comments

Shortly

  • [env Keras V2] I have keras model in .h5 format and SavedModel format.
  • [env Keras V2] I saved keras model in .weights.h5 format.
  • [env Keras V3] I loaded .weights.h5 fromat (model_a) and inference matched properly with previous .h5.
  • [env Keras V3] I saved .weights.h5 loaded Keras V3 model in .keras format (model_b). It saved and later reloaded properly.
  • Issue 1 is, the model's parameter of model_a and model_b are different despite being the same arch, initialized with same input. How best way to inspect these weights? Further, if I saved model_a to SavedModel format using tf.saved_model.save and reloaded with keras.layers.TFSMLayer, it remains safe unlike .keras format. So, shortly using Keras V3, the .weights.h5 and SavedModel file works fine but not in .keras format.
  • Issue 2 is, with torch backend, the inference with .weights.h5 format works as expected but changing to tensorflow and jax give different logits. I can ensure the low-level ops are properly set. So, I'm wondering, is there any known fact we need to care while using keras API with different backend? In other word, I used keras.ops, keras.layers which suppose to behave same for different backend, or no!

innat avatar Jan 04 '24 10:01 innat

@nkovela1 , Could you please take a look into this issue. Thanks!

sachinprasadhs avatar Jan 04 '24 23:01 sachinprasadhs

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Jan 15 '24 10:01 google-ml-butler[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Mar 25 '24 19:03 google-ml-butler[bot]