-
Notifications
You must be signed in to change notification settings - Fork 299
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
Lazy load modules #1590
Merged
+257
−142
Merged
Lazy load modules #1590
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a565367
lazy load module
pingsutw 704d04d
lazy load module
pingsutw 4dc8ade
import
pingsutw d4d9f52
nit
pingsutw 4fde300
nit
pingsutw 1d02277
nit
pingsutw ffaa8d7
keep structured dataset in flytekit init
pingsutw fbcb2f2
nit
pingsutw 5d055ca
nit
pingsutw 6529118
fixed tess
pingsutw acd819b
merged master
pingsutw 44668e6
nit
pingsutw 31349d8
Merge branch 'master' of github.com:flyteorg/flytekit into lazy_import
pingsutw 3977964
fixed tests
pingsutw 6944658
merged master
pingsutw 6694dfa
fixed tests
pingsutw 53b0c52
nit
pingsutw feb3bed
move import pandas to __init__
pingsutw f34b1be
use lazy import loader instead
pingsutw 2fa180e
Fixed tests
pingsutw c46ef4b
Fixed tests
pingsutw 2a0ef85
wip
pingsutw be79371
fix tests
pingsutw eb7d523
regular import
pingsutw 90730be
fixed tests
pingsutw 318079c
merged master
pingsutw 82eafc4
test
pingsutw 56dc5d8
lint
pingsutw 33f8a3c
merged master
pingsutw 25076fa
nit
pingsutw 00a7c03
lint
pingsutw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Dict, Optional | ||
|
||
from kubernetes.client.models import V1PodSpec | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Dict, Optional | ||
|
||
from flytekit.exceptions import user as _user_exceptions | ||
|
||
if TYPE_CHECKING: | ||
from kubernetes.client import V1PodSpec | ||
|
||
PRIMARY_CONTAINER_DEFAULT_NAME = "primary" | ||
|
||
|
||
@dataclass(init=True, repr=True, eq=True, frozen=True) | ||
@dataclass(init=True, repr=True, eq=True, frozen=False) | ||
class PodTemplate(object): | ||
"""Custom PodTemplate specification for a Task.""" | ||
|
||
pod_spec: V1PodSpec = field(default_factory=lambda: V1PodSpec(containers=[])) | ||
pod_spec: "V1PodSpec" = None | ||
primary_container_name: str = PRIMARY_CONTAINER_DEFAULT_NAME | ||
labels: Optional[Dict[str, str]] = None | ||
annotations: Optional[Dict[str, str]] = None | ||
|
||
def __post_init__(self): | ||
if self.pod_spec is None: | ||
from kubernetes.client import V1PodSpec | ||
|
||
self.pod_spec = V1PodSpec(containers=[]) | ||
if not self.primary_container_name: | ||
raise _user_exceptions.FlyteValidationException("A primary container name cannot be undefined") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
from google.protobuf.message import Message | ||
from google.protobuf.struct_pb2 import Struct | ||
from marshmallow_enum import EnumField, LoadDumpOptions | ||
from marshmallow_jsonschema import JSONSchema | ||
from typing_extensions import Annotated, get_args, get_origin | ||
|
||
from flytekit.core.annotation import FlyteAnnotation | ||
|
@@ -326,6 +325,8 @@ def get_literal_type(self, t: Type[T]) -> LiteralType: | |
# https://github.com/fuhrysteve/marshmallow-jsonschema/blob/81eada1a0c42ff67de216923968af0a6b54e5dcb/marshmallow_jsonschema/base.py#L228 | ||
if isinstance(v, EnumField): | ||
v.load_by = LoadDumpOptions.name | ||
from marshmallow_jsonschema import JSONSchema | ||
|
||
schema = JSONSchema().dump(s) | ||
except Exception as e: | ||
# https://github.com/lovasoa/marshmallow_dataclass/issues/13 | ||
|
@@ -373,7 +374,7 @@ def _get_origin_type_in_annotation(self, python_type: Type[T]) -> Type[T]: | |
def _fix_structured_dataset_type(self, python_type: Type[T], python_val: typing.Any) -> T: | ||
# In python 3.7, 3.8, DataclassJson will deserialize Annotated[StructuredDataset, kwtypes(..)] to a dict, | ||
# so here we convert it back to the Structured Dataset. | ||
from flytekit import StructuredDataset | ||
from flytekit.types.structured import StructuredDataset | ||
|
||
if python_type == StructuredDataset and type(python_val) == dict: | ||
return StructuredDataset(**python_val) | ||
|
@@ -768,11 +769,38 @@ def get_transformer(cls, python_type: Type) -> TypeTransformer[T]: | |
|
||
raise ValueError(f"Type {python_type} not supported currently in Flytekit. Please register a new transformer") | ||
|
||
@classmethod | ||
def lazy_import_transformers(cls, python_type: Type): | ||
""" | ||
Only load the transformers if needed. | ||
""" | ||
if get_origin(python_type) is Annotated: | ||
python_type = get_args(python_type)[0] | ||
if not hasattr(python_type, "__name__"): | ||
return | ||
name = python_type.__name__ | ||
if name == "tensorflow": | ||
from flytekit.extras import tensorflow # noqa: F401 | ||
elif name == "torch": | ||
from flytekit.extras import pytorch # noqa: F401 | ||
elif name == "sklearn": | ||
from flytekit.extras import sklearn # noqa: F401 | ||
elif name in ["pandas", "pyarrow"]: | ||
from flytekit.types.structured.structured_dataset import ( # noqa: F401 | ||
StructuredDataset, | ||
StructuredDatasetFormat, | ||
StructuredDatasetTransformerEngine, | ||
StructuredDatasetType, | ||
) | ||
elif name == "numpy": | ||
from flytekit.types import numpy # noqa: F401 | ||
|
||
@classmethod | ||
def to_literal_type(cls, python_type: Type) -> LiteralType: | ||
""" | ||
Converts a python type into a flyte specific ``LiteralType`` | ||
""" | ||
cls.lazy_import_transformers(python_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a comment for why this is in to literal type but not in to python value and to literal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to get_transformer |
||
transformer = cls.get_transformer(python_type) | ||
res = transformer.get_literal_type(python_type) | ||
data = None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
needs optional now
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.
done