apple / tensorflow_macos

TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.
Other
3.67k stars 308 forks source link

Op type not registered MLCDropout when loading M1 saved model on non-M1, need "universal" models? #233

Open zazula opened 3 years ago

zazula commented 3 years ago

When I load a model created on an M1 mac with savemodel() using load mode() on a non-M1 machine, I get the following error:

Op type not registered 'MLCDropout' in binary running on XXX. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) tf.contrib.resampler should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.

Is there support or planned support for a "universal" model format?

I see in the JSON format that the names are the base class name (e.g., 'Dropout'). I'll see if that works for a cross-platform format.

Maybe that error message could do a check against the library and be more specific? e.g.,

MLCDropout is not available for the current architecture... or somesuch...

zazula commented 3 years ago

Note : loading from JSON seems to work across architectures.

leonlowitzki commented 3 years ago

Same here. Thank you for posting this workaround!

zazula commented 3 years ago

You will have to manually save/load weights when using the JSON representation:

model.save_weights('my.file')

You might be able to fish them out of the HDF5 file from model.save('mymodel.hdf5'), I see keys for the weights, but I haven't tried this.