Ryan Saxe
09/19/2023, 2:30 PM_load
, it tries to load from a temporary directory that was created during _save
. However, at least on my computer, that temporary directory doesn't exist. If I patch the implementation of TensorflowModelDataset._load
such that it loads from _fs
instead of the temporary path, everything works fine since _save
copies over the model to _fs
.
Just putting this here to ask a few questions:
1. Should I create a PR that updates TensorflowModelDataset._load
to not use the temporary directory?
2. Can somebody with a non-M1 machine try and reproduce the error to see if it's an issue with this particular hardware? I'm happy to help with that as well
3. If it is hardware specific, then should the PR fix create a new dataset that's like TensorflowModelDatasetM1
for this special case?
Note that I'm relatively new to kedro, so if this is the wrong place to ask/discuss, let me know. Thanks!Merel
09/19/2023, 2:43 PMTensorFlowModelDataSet
is working fine for me. My suggestion would be to not create a completely new dataset but add a check in the load
and save
methods for the system type and deal with it differently if it’s arm
Ryan Saxe
09/19/2023, 3:27 PMTensorflowModelDataSet
with instead of my own custom case?
I also want to make sure that this is 100% due to hardware differences. Since another reason it could work for you and not me at the moment is that I'm using a custom model in tensorflow wrapped with @tf.keras.utils.register_keras_serializable()
arm
as the os. And if it does have something to do with the custom modelling, we can check if that also happens on windowsMerel
09/19/2023, 3:51 PMfrom kedro_datasets.tensorflow import TensorFlowModelDataSet
import tensorflow as tf
import numpy as np
data_set = TensorFlowModelDataSet("data/06_models/tensorflow_model.h5")
inputs = tf.keras.Input(shape=(3,))
x = tf.keras.layers.Dense(4, activation=tf.nn.relu)(inputs)
outputs = tf.keras.layers.Dense(5, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
input_data = np.array([[0.5, 0.3, 0.2]])
predictions = model.predict(input_data)
data_set.save(model)
loaded_model = data_set.load()
input_data2 = np.array([[0.8, 0.4, 0.8]])
new_predictions = loaded_model.predict(input_data2)
np.testing.assert_allclose(predictions, new_predictions, rtol=1e-6, atol=1e-6)
Ryan Saxe
09/19/2023, 5:42 PMOSError: SavedModel file does not exist at: /var/folders/bc/33y59_xn6yd3smds_z3wsl9r0000gp/T/kedro_tensorflow_tmpzqej8lam/{saved_model.pbtxt|saved_model.pb}
So I'm assuming this is a hardware issue.
One quick question, why do you have input_data != input_data2
. If you're testing the loaded model, shouldn't the input data be the same?
Anyways, I've confirmed that updating the object to not run with temporary files if platform.processor() == "arm":
works.
Is there a particular way that y'all do PRs? Or can I just clone, create a branch, and open a PR?Merel
09/20/2023, 8:22 AMtensorflow==2.12.0
and python 3.9William Caicedo
09/20/2023, 4:43 PMRyan Saxe
09/20/2023, 5:07 PMos.listdir(path)
inside the with statement in TensorFlowModelDataset._save
?
Prior to calling tf.keras.models.save_model
it returns an empty list. Afterwords it returns ['fingerprint.pb', 'keras_metadata.pb', 'variables', 'saved_model.pb', 'assets']
William Caicedo
09/20/2023, 5:13 PM_load
. The temporary path is needed because it is possible that the model is being stored remotely (e.g. S3).Ryan Saxe
09/20/2023, 5:34 PMos.listdir(path)
instead _load
because the statement with tempfile.TemporaryDirectory(prefix=self._tmp_prefix) as path:
generates the error, hence I never have access to path
with
statement I can execute os.listdir(load_path)
, which will point to the path specified in the data catalog. This works properly and returns ['fingerprint.pb', 'keras_metadata.pb', 'variables', 'saved_model.pb', 'assets']
because _save
copies over the files from the temp directory into the directory specified in the data catalog.William Caicedo
09/20/2023, 5:42 PMtempfile.TemporaryDirectory
?Ryan Saxe
09/20/2023, 6:17 PMos.listdir(path)
yields `['tensorflow_model.h5']`inside the _load
William Caicedo
09/20/2023, 6:24 PM.h5
format which is a single file and others to the SavedModel
format, which is a directory with multiple files.Ryan Saxe
09/20/2023, 6:42 PMos.listdir(path)
inside _save
, I see SavedModel
format. But when I do os.listdir(path)
inside _load
, I see the .h5
formatWilliam Caicedo
09/20/2023, 6:48 PMsave_format
to either h5
or tf
under both load_args
and save_args
to see what happensRyan Saxe
09/20/2023, 6:52 PMsave_format
in the kwargs for tf.keras.models.load_model
so I cannot specify that. Shifting save_format
to `h5`in save_args
yields a very similar error:
DatasetError: Failed while loading data from data set TensorFlowModelDataset(filepath=data/06_models/tensorflow_model.h5, protocol={}, save_args={'save_format': h5}).
No file or directory found at /var/folders/bc/33y59_xn6yd3smds_z3wsl9r0000gp/T/kedro_tensorflow_tmpy73clzrf/tmp_tensorflow_model.h5
_load
, the path
points to the temporary directory. That directory contains the folder that contains the model. So when I tell keras to load from that path
, it cant. But if I ask it to load from path/tensorflow_model.h5
, this actually works.William Caicedo
09/20/2023, 7:06 PMfsspec
worksRyan Saxe
09/27/2023, 12:33 PMfsspec
version? I'm on
>>> fsspec.__version__
'2023.9.0'
Either this is the wrong version and the reqs/toml should be more specific, or there's something to be patched.Juan Luis
09/29/2023, 8:18 AMfsspec==2023.1.0
. will give this another try