Skip to content

Commit 545d07e

Browse files
authored
Fix tensorflow transformer (#3346)
1 parent 9f3ec96 commit 545d07e

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

flytekit/extras/tensorflow/model.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_literal_type(self, t: Type[tf.keras.Model]) -> LiteralType:
2020
return LiteralType(
2121
blob=_core_types.BlobType(
2222
format=self.TENSORFLOW_FORMAT,
23-
dimensionality=_core_types.BlobType.BlobDimensionality.MULTIPART,
23+
dimensionality=_core_types.BlobType.BlobDimensionality.SINGLE,
2424
)
2525
)
2626

@@ -34,14 +34,14 @@ async def async_to_literal(
3434
meta = BlobMetadata(
3535
type=_core_types.BlobType(
3636
format=self.TENSORFLOW_FORMAT,
37-
dimensionality=_core_types.BlobType.BlobDimensionality.MULTIPART,
37+
dimensionality=_core_types.BlobType.BlobDimensionality.SINGLE,
3838
)
3939
)
4040

41-
local_path = ctx.file_access.get_random_local_path()
41+
local_path = ctx.file_access.get_random_local_path() + ".keras"
4242
pathlib.Path(local_path).parent.mkdir(parents=True, exist_ok=True)
4343

44-
# save model in SavedModel format
44+
# save model in Keras format
4545
tf.keras.models.save_model(python_val, local_path)
4646

4747
remote_path = await ctx.file_access.async_put_raw_data(local_path)
@@ -55,16 +55,16 @@ async def async_to_python_value(
5555
except AttributeError:
5656
TypeTransformerFailedError(f"Cannot convert from {lv} to {expected_python_type}")
5757

58-
local_path = ctx.file_access.get_random_local_path()
59-
await ctx.file_access.async_get_data(uri, local_path, is_multipart=True)
58+
local_path = ctx.file_access.get_random_local_path() + ".keras"
59+
await ctx.file_access.async_get_data(uri, local_path, is_multipart=False)
6060

6161
# load model
6262
return tf.keras.models.load_model(local_path)
6363

6464
def guess_python_type(self, literal_type: LiteralType) -> Type[tf.keras.Model]:
6565
if (
6666
literal_type.blob is not None
67-
and literal_type.blob.dimensionality == _core_types.BlobType.BlobDimensionality.MULTIPART
67+
and literal_type.blob.dimensionality == _core_types.BlobType.BlobDimensionality.SINGLE
6868
and literal_type.blob.format == self.TENSORFLOW_FORMAT
6969
):
7070
return tf.keras.Model

tests/flytekit/unit/extras/tensorflow/model/test_transformations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_tf_model() -> tf.keras.Model:
3939
)
4040
def test_get_literal_type(transformer, python_type, format):
4141
lt = transformer.get_literal_type(python_type)
42-
assert lt == LiteralType(blob=BlobType(format=format, dimensionality=BlobType.BlobDimensionality.MULTIPART))
42+
assert lt == LiteralType(blob=BlobType(format=format, dimensionality=BlobType.BlobDimensionality.SINGLE))
4343

4444

4545
@pytest.mark.parametrize(
@@ -58,7 +58,7 @@ def test_to_python_value_and_literal(transformer, python_type, format, python_va
5858
assert lv.scalar.blob.metadata == BlobMetadata(
5959
type=BlobType(
6060
format=format,
61-
dimensionality=BlobType.BlobDimensionality.MULTIPART,
61+
dimensionality=BlobType.BlobDimensionality.SINGLE,
6262
)
6363
)
6464
assert lv.scalar.blob.uri is not None

0 commit comments

Comments
 (0)