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

Support pydantic plugin in 2.xx version #2217

Merged
merged 18 commits into from
Mar 11, 2024
Merged

Conversation

Future-Outlier
Copy link
Member

@Future-Outlier Future-Outlier commented Feb 27, 2024

Tracking Issues

https://flyte-org.slack.com/archives/CP2HDHKE1/p1708960554466059

Why are the changes needed?

When pydantic version >= 2, this current plugin will not work.

What changes were proposed in this pull request?

  • use as pydantic to support 2 cases , pydantic version < 2 and pydantic version >= 2
  • remove lazy_load to support 2 cases , pydantic version < 2 and pydantic version >= 2

How was this patch tested?

We test it in 2 scenarios, pydantic version < 2 and pydantic version >= 2.
We need to use

  • from pydantic import BaseModel when pydantic version < 2
  • from pydantic.v1 import BaseModel when pydantic version >= 2
from flytekit import task
from pydantic.v1 import BaseModel

class TrainConfig(BaseModel):
    lr: float = 1e-3
    batch_size: int = 32

@task
# def train() -> TrainConfig:
def train() -> TrainConfig:
    return TrainConfig(lr=1.1, batch_size=64)

if __name__ == "__main__":
    print(train(cfg=TrainConfig(lr=1.1, batch_size=64)))
FROM python:3.9-slim-buster
USER root
WORKDIR /root
ENV PYTHONPATH /root
RUN apt-get update && apt-get install build-essential -y
RUN apt-get install git -y

RUN pip install -U git+https://github.com/flyteorg/flytekit.git@e85e6ec5dba79dc09791abd1f1eac1ce115f0ef6#subdirectory=plugins/flytekit-pydantic

RUN pip install -U git+https://github.com/flyteorg/flytekit.git@e85e6ec5dba79dc09791abd1f1eac1ce115f0ef6
pyflyte run --image futureoutlier/flytekit:pydantic-v2 --remote pydantic_example.py train

Setup process

Screenshots

when pydantic version < 2

from flytekit import task
from pydantic import BaseModel
image

when pydantic version >= 2

from flytekit import task
from pydantic.v1 import BaseModel
image

remote execution

image

warning message

image

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 27, 2024
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 48.00000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 82.00%. Comparing base (40b8614) to head (4614074).

Files Patch % Lines
flytekit/interaction/click_types.py 16.66% 5 Missing ⚠️
.../flytekitplugins/pydantic/basemodel_transformer.py 71.42% 2 Missing ⚠️
...dantic/flytekitplugins/pydantic/deserialization.py 50.00% 2 Missing ⚠️
...pydantic/flytekitplugins/pydantic/serialization.py 50.00% 2 Missing ⚠️
...s/flytekit-pydantic/tests/test_type_transformer.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2217      +/-   ##
==========================================
- Coverage   83.52%   82.00%   -1.53%     
==========================================
  Files         296      306      +10     
  Lines       23244    23894     +650     
  Branches     3481     3481              
==========================================
+ Hits        19415    19594     +179     
- Misses       3207     3672     +465     
- Partials      622      628       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 27, 2024
.github/workflows/pythonbuild.yml Show resolved Hide resolved
plugins/flytekit-pydantic/setup.py Outdated Show resolved Hide resolved
from flytekit.core import type_engine
from flytekit.models import literals, types

from . import deserialization, serialization

pydantic = lazy_module("pydantic")
# pydantic plugin is not suitable for lazy module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# pydantic plugin is not suitable for lazy module.

plugins/flytekit-pydantic/tests/test_type_transformer.py Outdated Show resolved Hide resolved
@Future-Outlier
Copy link
Member Author

will not show a warning message when import flytekit

image

will show warning message when using pydantic plugin

image

Copy link
Member

@pingsutw pingsutw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@dosubot dosubot bot added the lgtm This PR has been approved by maintainer label Mar 11, 2024
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Future-Outlier and others added 7 commits March 12, 2024 07:32
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
@Future-Outlier Future-Outlier merged commit 05fc527 into master Mar 11, 2024
44 of 47 checks passed
austin362667 pushed a commit to austin362667/flytekit that referenced this pull request Mar 16, 2024
* support pydantic when 2.xx version

Signed-off-by: Future-Outlier <[email protected]>

* update import

Signed-off-by: Future-Outlier <[email protected]>

* update

Signed-off-by: Future-Outlier <[email protected]>

* Revert Dev Dependencies

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* pydantic

Signed-off-by: Future-Outlier <[email protected]>

* fix-plugin-ci

Signed-off-by: Future-Outlier <[email protected]>

* as pydantic, remove lazy load

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* warning messages

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* update pydantic version

Signed-off-by: Future-Outlier <[email protected]>

* fix build plugins CI

Signed-off-by: Future-Outlier <[email protected]>

* fix version problem

Signed-off-by: Future-Outlier <[email protected]>

* Update pingsu's advice

Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>

* update supported types

Signed-off-by: Future-Outlier <[email protected]>

* update pingsu's advice

Signed-off-by: Future-Outlier <[email protected]>

* remove tests

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
fiedlerNr9 pushed a commit that referenced this pull request Jul 25, 2024
* support pydantic when 2.xx version

Signed-off-by: Future-Outlier <[email protected]>

* update import

Signed-off-by: Future-Outlier <[email protected]>

* update

Signed-off-by: Future-Outlier <[email protected]>

* Revert Dev Dependencies

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* pydantic

Signed-off-by: Future-Outlier <[email protected]>

* fix-plugin-ci

Signed-off-by: Future-Outlier <[email protected]>

* as pydantic, remove lazy load

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* warning messages

Signed-off-by: Future-Outlier <[email protected]>

* lint

Signed-off-by: Future-Outlier <[email protected]>

* update pydantic version

Signed-off-by: Future-Outlier <[email protected]>

* fix build plugins CI

Signed-off-by: Future-Outlier <[email protected]>

* fix version problem

Signed-off-by: Future-Outlier <[email protected]>

* Update pingsu's advice

Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>

* update supported types

Signed-off-by: Future-Outlier <[email protected]>

* update pingsu's advice

Signed-off-by: Future-Outlier <[email protected]>

* remove tests

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants