-
Notifications
You must be signed in to change notification settings - Fork 309
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
Flytekit remote updates for notebooks and versions #3109
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Ketan Umare <[email protected]>
Code Review Agent Run #7eedadActionable Suggestions - 1
Additional Suggestions - 1
Review Details
|
flytekit/remote/remote.py
Outdated
def _resolve_version( | ||
self, version: typing.Optional[str], entity: typing.Any, ss: SerializationSettings | ||
) -> typing.Tuple[str, typing.Optional[PickledEntity]]: | ||
if version is None and self.interactive_mode_enabled: | ||
md5_bytes, pickled_target_dict = _get_pickled_target_dict(entity) | ||
return self._version_from_hash( | ||
md5_bytes, ss, entity.python_interface.default_inputs_as_kwargs, *self._get_image_names(entity) | ||
), pickled_target_dict | ||
elif version is not None: | ||
return version, None | ||
raise ValueError( | ||
"Version must be provided when not in interactive mode. If you want to use latest version pass 'latest'" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the version resolution logic into a separate method for better code organization. The _resolve_version
method currently handles both version resolution and pickled entity management, which could be split for better maintainability.
Code suggestion
Check the AI-generated fix before applying
def _resolve_version( | |
self, version: typing.Optional[str], entity: typing.Any, ss: SerializationSettings | |
) -> typing.Tuple[str, typing.Optional[PickledEntity]]: | |
if version is None and self.interactive_mode_enabled: | |
md5_bytes, pickled_target_dict = _get_pickled_target_dict(entity) | |
return self._version_from_hash( | |
md5_bytes, ss, entity.python_interface.default_inputs_as_kwargs, *self._get_image_names(entity) | |
), pickled_target_dict | |
elif version is not None: | |
return version, None | |
raise ValueError( | |
"Version must be provided when not in interactive mode. If you want to use latest version pass 'latest'" | |
) | |
def _get_pickled_entity(self, entity: typing.Any) -> typing.Optional[PickledEntity]: | |
if not self.interactive_mode_enabled: | |
return None | |
md5_bytes, pickled_target_dict = _get_pickled_target_dict(entity) | |
return pickled_target_dict | |
def _resolve_version( | |
self, version: typing.Optional[str], entity: typing.Any, ss: SerializationSettings | |
) -> typing.Tuple[str, typing.Optional[PickledEntity]]: | |
if version is not None: | |
return version, None | |
if not self.interactive_mode_enabled: | |
raise ValueError( | |
"Version must be provided when not in interactive mode. If you want to use latest version pass 'latest'" | |
) | |
md5_bytes, pickled_target_dict = _get_pickled_target_dict(entity) | |
version = self._version_from_hash( | |
md5_bytes, ss, entity.python_interface.default_inputs_as_kwargs, *self._get_image_names(entity) | |
) | |
return version, pickled_target_dict |
Code Review Run #7eedad
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Signed-off-by: Samhita Alla <[email protected]>
Code Review Agent Run #dda473Actionable Suggestions - 2
Review Details
|
def _resolve_version( | ||
self, version: typing.Optional[str], entity: typing.Any, ss: SerializationSettings | ||
) -> typing.Tuple[str, typing.Optional[PickledEntity]]: | ||
if version is None and self.interactive_mode_enabled: | ||
md5_bytes, pickled_target_dict = _get_pickled_target_dict(entity) | ||
return self._version_from_hash( | ||
md5_bytes, ss, entity.python_interface.default_inputs_as_kwargs, *self._get_image_names(entity) | ||
), pickled_target_dict | ||
elif version is not None: | ||
return version, None | ||
raise ValueError( | ||
"Version must be provided when not in interactive mode. If you want to use latest version pass 'latest'" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding type hints for entity
parameter in _resolve_version()
. The current implementation accepts typing.Any
which could lead to runtime errors if invalid types are passed.
Code suggestion
Check the AI-generated fix before applying
- def _resolve_version(self, version: typing.Optional[str], entity: typing.Any, ss: SerializationSettings
+ def _resolve_version(self, version: typing.Optional[str], entity: typing.Union[WorkflowBase, PythonTask], ss: SerializationSettings
Code Review Run #dda473
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
project=self.default_project, | ||
domain=self.default_domain, | ||
) | ||
|
||
version, _ = self._resolve_version(version, entity, serialization_settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving the version resolution logic before the serialization settings initialization to avoid potential inconsistencies between version and settings.
Code suggestion
Check the AI-generated fix before applying
- serialization_settings = SerializationSettings(
- image_config=ImageConfig.auto_default_image(),
- project=self.default_project,
- domain=self.default_domain,
- )
-
- version, _ = self._resolve_version(version, entity, serialization_settings)
+ version, _ = self._resolve_version(version, entity, None)
+ serialization_settings = SerializationSettings(
+ image_config=ImageConfig.auto_default_image(),
+ project=self.default_project,
+ domain=self.default_domain,
+ version=version
+ )
Code Review Run #dda473
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
There's a breaking change here I wanted to highlight which may or may not be okay. I think it's technically more correct, but it is a change in behavior. Assuming you have a simple file like this from flytekit import task, workflow, ImageSpec, FlyteRemote, Config
image = ImageSpec(
name="yt_public",
builder="default",
registry="ghcr.io/wild-endeavor",
packages=["flytekit==v1.15.0b2"],
)
@task(container_image=image, enable_deck=True)
def print_hello():
print("hello")
@workflow
def wf():
print_hello()
if __name__ == "__main__":
remote = FlyteRemote(Config.for_sandbox(), default_project="flytesnacks", default_domain="development")
remote.register_workflow(wf, version="from_main_v4_pr") the behavior on master is as follows
The reason the code is built into the image in the second case is because the code currently is setting the project root. When the register workflow call triggers the downstream register task call, it gets set on the image spec, causing the user code to be built in. With this pr, without setting project root, pyflyte register remains the same, but If the user wants to make this work, they'd have to change to I think we can make a better experience actually - the register_workflow function right now never does fast register... even if the user passes in a serialization settings object with fast register enabled, so there's some discrepancy here to clean up. |
Problems:
latest
as a special versionExample cases, now works
![Screenshot 2025-02-04 at 9 35 13 PM](https://private-user-images.githubusercontent.com/16888709/409843455-27bfef6d-ad01-435d-a66c-c1f045ce228f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NDcxNzIsIm5iZiI6MTczODk0Njg3MiwicGF0aCI6Ii8xNjg4ODcwOS80MDk4NDM0NTUtMjdiZmVmNmQtYWQwMS00MzVkLWE2NmMtYzFmMDQ1Y2UyMjhmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDE2NDc1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk0ZTE0ZDFiNWM5OWQyY2IxMjFhODZlN2ExZDBkZTUwOWM3MzAzZDIzYzEwNGVhZmFkYzhmYTFjNDM0M2Q0NTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.JmmuhCaMYS-aw5TJ7ZjTtAJRS9L2nt4MnrA7yEEAA0Y)
Summary by Bito
This PR implements standardized version handling in Flytekit's remote operations, introducing 'latest' as the default version option. The changes include refining the _resolve_version method for consistent version resolution and making version parameters optional with proper defaults. The update improves behavior across interactive and non-interactive modes, particularly enhancing user experience in notebook environments while improving error messaging and documentation.Unit tests added: False
Estimated effort to review (1-5, lower is better): 2