Skip to content
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

Fix PipelineModel transformer issue 3648 #1623

Merged
merged 1 commit into from
May 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pathlib
from typing import Type

from pyspark.ml import PipelineModel
Expand All @@ -24,22 +23,17 @@ def to_literal(
python_type: Type[PipelineModel],
expected: LiteralType,
) -> Literal:
local_path = ctx.file_access.get_random_local_path()
pathlib.Path(local_path).parent.mkdir(parents=True, exist_ok=True)
python_val.save(local_path)

# Must write to remote directory
remote_dir = ctx.file_access.get_random_remote_directory()
ctx.file_access.upload_directory(local_path, remote_dir)
python_val.write().overwrite().save(remote_dir)

return Literal(scalar=Scalar(blob=Blob(uri=remote_dir, metadata=BlobMetadata(type=self._TYPE_INFO))))

def to_python_value(
self, ctx: FlyteContext, lv: Literal, expected_python_type: Type[PipelineModel]
) -> PipelineModel:
local_dir = ctx.file_access.get_random_local_directory()
ctx.file_access.download_directory(lv.scalar.blob.uri, local_dir)

return PipelineModel.load(local_dir)
remote_dir = lv.scalar.blob.uri
return PipelineModel.load(remote_dir)


TypeEngine.register(PySparkPipelineModelTransformer())