-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keras create/load model fails on Apple M2 cpu. Same code works on Ryzen #46
Comments
@drmatthewclark, |
Can confirm having the same issue (M1). Haven't had the chance to test on non-Apple Silicon hardware (that I own) yet, but it appears to be fine on Colab... |
Same here, on M1, python3.10, and tensorflow 2.13.0. Training, inference, and saving works fine. Loading fails. Code extract:
Output:
|
@drmatthewclark, |
Hey @tilakrayal, thank you for your input. I did a bit of digging because I found the issue too annoying and it is clearly a tensorflow problem and not a macos problem. So, here's what I found:
[EDIT] @drmatthewclark to fix your problem install the nightly version of tensorflow and keras while we wait for a new release.
|
There is an alternative workaround to make AdamW work on Apple Silicon with the latest version of tensorflow, tensorflow-addons. |
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you. |
Can confirm same issue on m2 max mac. nightly tensorflow builds don't work and neither does tensorflow-addons. |
Also tried this and got the same result (M2 Mac): Tried also the suggested solutions from this thread without any success |
Same error with the SGD omptimizer. M1 Macbook Air.
|
same issue here also. M1 mac. |
Go back to use .h5 files instead of .keras due to a problem in Keras loading .keras files on MacOS ARM (see https://github.com/keras-team/keras/issues/18278 )
Go back to use .h5 files instead of .keras due to a problem in Keras loading .keras files on MacOS ARM (see https://github.com/keras-team/keras/issues/18278 )
Same issue here, fix plz. |
Ditto. I am using TensorFlow 2.13 on macOS with M2. |
Go back to use .h5 files instead of .keras due to a problem in Keras loading .keras files on MacOS ARM (see https://github.com/keras-team/keras/issues/18278 )
Same issue, using Tensorflow 2.13.0 and Python 3.10.13 on Mac M2. |
Saving the model to a different format (h5) solved the issue^ for me. |
Go back to use .h5 files instead of .keras due to a problem in Keras loading .keras files on MacOS ARM (see https://github.com/keras-team/keras/issues/18278 )
Go back to use .h5 files instead of .keras due to a problem in Keras loading .keras files on MacOS ARM (see https://github.com/keras-team/keras/issues/18278 )
any news on this issue? |
This workaround is not suitable for us because the h5 format doesn't support some attributes/parameters of our models |
I just tried to run this code in my MacOS M1 (using
|
Adding Neel for the saving issue. |
@drmatthewclark, Thank you! |
@tilakrayal i confirm that with tf-nightly the error it seems to be fixed
it seems it solves the error
I also reported the same finding here: tensorflow/tensorflow#61915 (comment) |
I'm using mac m1 pro and tensorflow version is 2.14.0. I was facing the same error "AttributeError: 'Adam' object has no attribute 'build'" while loading the saved model, if I save the model as below
I updated the optimizer as below and it is working fine now
|
@EswarJanjanam The fix is on tf-nightly. Please do |
|
Crap, it's my mirroring problem, sorry! But it didn't solve the problem.
|
Same error exists on M2 mac.
.h5 format is one of solution instead of .keras format for now. |
Yeah, I mean can't he just automatically adapt to the solution? |
Having the exact same issue, and can confirm that |
same issue |
Having the same issue as well on Mac M1. The same code works on cloud workstation on linux. |
After much trial and error, installing keras-nightly solved the issue and my model started working. |
tf_env.txt
You can obtain the TensorFlow version with:
python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"
result:
v2.13.0-rc2-7-g1cb1a030a62 2.13.0
Can't load a keras model that I just created. The issue is not specific to Adam; all of the optimizers have the same issue.
Describe the problem.
code:
output:
the legacy Adam is missing the method "build". This same code works on non-mac platforms.
WARNING:absl:At this time, the v2.11+ optimizer
tf.keras.optimizers.Adam
runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located attf.keras.optimizers.legacy.Adam
.WARNING:absl:There is a known slowdown when using v2.11+ Keras optimizers on M1/M2 Macs. Falling back to the legacy Keras optimizer, i.e.,
tf.keras.optimizers.legacy.Adam
.WARNING:absl:At this time, the v2.11+ optimizer
tf.keras.optimizers.Adam
runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located attf.keras.optimizers.legacy.Adam
.WARNING:absl:There is a known slowdown when using v2.11+ Keras optimizers on M1/M2 Macs. Falling back to the legacy Keras optimizer, i.e.,
tf.keras.optimizers.legacy.Adam
.Traceback (most recent call last):
File "/Users/matthewclark/eclipse-workspace/antibody_classification/test/test.py", line 17, in
test = keras.models.load_model('nn_model.keras')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/saving/saving_api.py", line 230, in load_model
return saving_lib.load_model(
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/saving/saving_lib.py", line 275, in load_model
raise e
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/saving/saving_lib.py", line 240, in load_model
model = deserialize_keras_object(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/saving/serialization_lib.py", line 710, in deserialize_keras_object
instance.compile_from_config(compile_config)
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/engine/training.py", line 3582, in compile_from_config
self.optimizer.build(self.trainable_variables)
^^^^^^^^^^^^^^^^^^^^
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/optimizers/legacy/optimizer_v2.py", line 997, in getattribute
raise e
File "/Users/Shared/anaconda3/envs/ability/lib/python3.11/site-packages/keras/src/optimizers/legacy/optimizer_v2.py", line 987, in getattribute
return super().getattribute(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Adam' object has no attribute 'build'
The text was updated successfully, but these errors were encountered: