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 both pydantic 1.x and 2.x #37055

Merged
merged 9 commits into from
Jul 14, 2023

Conversation

alanwguo
Copy link
Contributor

@alanwguo alanwguo commented Jul 3, 2023

Why are these changes needed?

These changes fixes a couple of things when ray and pydantic 2.0 is installed:

  • ray can start up now
  • ray jobs works now
  • gets rid of some deprecation warnings when using old pydantic field names.

Some things are still broken:

  • ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
  • Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Alan Guo <aguo@anyscale.com>
@alanwguo alanwguo force-pushed the support-pydantic-2 branch from d3212fa to 71b30ba Compare July 3, 2023 21:55
@alanwguo alanwguo mentioned this pull request Jul 5, 2023
alanwguo added 2 commits July 5, 2023 16:45
Signed-off-by: Alan Guo <aguo@anyscale.com>
Signed-off-by: Alan Guo <aguo@anyscale.com>
@alanwguo alanwguo marked this pull request as ready for review July 5, 2023 23:55
@rkooo567
Copy link
Contributor

rkooo567 commented Jul 6, 2023

Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.

Is this required for ray serve?

Btw, maybe we need a guard against ray serve (or at least warning)? cc @edoakes @sihanwang41

Copy link
Contributor

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

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

nit comments

python/ray/serve/_private/version.py Show resolved Hide resolved
except ImportError:
# pydantic is not available in the dashboard.
# We will use the dataclass from the standard library.
from dataclasses import dataclass

JobDetails = object
is_pydantic_2 = False
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we just call it pydantic_1_available? This seems to be more clear with code below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that naming doesn't quite work, because when pydantic is not installed at all, also want init=True. Setting the variable pydantic_1_available = True is weird.

)

if ModelField is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Can't we just check if pydantic is 1 or 2 here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure why that's better. I thought it's better to check existance of features/variables over doing a version check.

Copy link
Contributor

Choose a reason for hiding this comment

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

just the logic seems pretty complicated (1 vs 2 is just one line?) I am okay with this approach too.

Copy link
Contributor

Choose a reason for hiding this comment

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

in this case, do you think it is possible to add a simple unit test?

@rkooo567 rkooo567 added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jul 6, 2023
@shawnpanda
Copy link
Contributor

General question: does this mean that ray serve will be broken until fastapi uses pydantic v2?

@rkooo567
Copy link
Contributor

rkooo567 commented Jul 6, 2023

Btw, this is a release blocker right? Are we tracking the issue @alanwguo ?

@alanwguo
Copy link
Contributor Author

alanwguo commented Jul 6, 2023

Btw, this is a release blocker right? Are we tracking the issue @alanwguo ?

We pinned pydantic to <2 so this is not a release blocker. But I am still targetting to get this merged for 2.6

@alanwguo
Copy link
Contributor Author

alanwguo commented Jul 6, 2023

General question: does this mean that ray serve will be broken until fastapi uses pydantic v2?

yes, but only if user is using pydanatic 2.0

Signed-off-by: Alan Guo <aguo@anyscale.com>
Copy link
Contributor

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

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

I perfer to have an unit test for serialization_addon.py logic (it seems pretty complicated to me). maybe you can do it using runtime _env (runtime_env with pydantic 1 vs 2). Other than that it lgtm

)

if ModelField is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

just the logic seems pretty complicated (1 vs 2 is just one line?) I am okay with this approach too.

)

if ModelField is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case, do you think it is possible to add a simple unit test?

Signed-off-by: Alan Guo <aguo@anyscale.com>
@alanwguo
Copy link
Contributor Author

alanwguo commented Jul 7, 2023

I perfer to have an unit test for serialization_addon.py logic (it seems pretty complicated to me). maybe you can do it using runtime _env (runtime_env with pydantic 1 vs 2). Other than that it lgtm

Added a unit test! Verified the test fails if i comment out my serialization_addons.py stuff

@rkooo567
Copy link
Contributor

rkooo567 commented Jul 7, 2023

Lint failure + can you remove the pin from the PR?

@alanwguo
Copy link
Contributor Author

alanwguo commented Jul 7, 2023

Lint failure + can you remove the pin from the PR?

I don't know if we should remove the pin so quickly. There are still issues with Serve and we can't pickle pydantic models with v 2.x.

@pcmoritz thoughts?

alanwguo added 2 commits July 7, 2023 09:48
Signed-off-by: Alan Guo <aguo@anyscale.com>
Signed-off-by: Alan Guo <aguo@anyscale.com>
@alanwguo alanwguo removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jul 11, 2023
@rkooo567
Copy link
Contributor

Lmk when this is ready to be merged!

@alanwguo
Copy link
Contributor Author

alanwguo commented Jul 12, 2023

Lmk when this is ready to be merged!

I think it's ready... it's hard to tell with all these test failures, but I looked through them and they look unrelated

Different tests seem to fail between each run.

@rkooo567
Copy link
Contributor

@alanwguo before we merge, is it possible to run CI with pydantic version > 2.0? And then let's merge this by today?

@edoakes
Copy link
Contributor

edoakes commented Jul 12, 2023

@alanwguo
Copy link
Contributor Author

@edoakes , thanks for bringing that to my attention!

I don't think I'm the right person to get serve working with pydantic 2.0,
@akshay-anyscale , can we have someone working on serve pick up the remaining work here?

@rkooo567
Copy link
Contributor

The failing tests seem new to me, so I am rerunning it just in case. Highly likely it is not releated

@alanwguo
Copy link
Contributor Author

The failing tests seem new to me, so I am rerunning it just in case. Highly likely it is not releated

Looks ready to merge?

@rkooo567 rkooo567 merged commit 965ddf3 into ray-project:master Jul 14, 2023
alanwguo added a commit to alanwguo/ray that referenced this pull request Jul 17, 2023
These changes fixes a couple of things when ray and pydantic 2.0 is installed:

ray can start up now
ray jobs works now
gets rid of some deprecation warnings when using old pydantic field names.
Some things are still broken:

ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.
@alanwguo alanwguo mentioned this pull request Jul 17, 2023
8 tasks
can-anyscale pushed a commit that referenced this pull request Jul 17, 2023
These changes fixes a couple of things when ray and pydantic 2.0 is installed:

ray can start up now
ray jobs works now
gets rid of some deprecation warnings when using old pydantic field names.
Some things are still broken:

ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.
NripeshN pushed a commit to NripeshN/ray that referenced this pull request Aug 15, 2023
These changes fixes a couple of things when ray and pydantic 2.0 is installed:

ray can start up now
ray jobs works now
gets rid of some deprecation warnings when using old pydantic field names.
Some things are still broken:

ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.

Signed-off-by: NripeshN <nn2012@hw.ac.uk>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
These changes fixes a couple of things when ray and pydantic 2.0 is installed:

ray can start up now
ray jobs works now
gets rid of some deprecation warnings when using old pydantic field names.
Some things are still broken:

ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.

Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
@kerthcet
Copy link

I don't think I'm the right person to get serve working with pydantic 2.0, @akshay-anyscale , can we have someone working on serve pick up the remaining work here?

Sorry for the ping, any plan to support pydantic 2.0 on ray serve?

@kerthcet
Copy link

Found the answer, targeting for release 2.8, sorry for the bothering.

vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
These changes fixes a couple of things when ray and pydantic 2.0 is installed:

ray can start up now
ray jobs works now
gets rid of some deprecation warnings when using old pydantic field names.
Some things are still broken:

ray serve doesn't work because it depends on fastapi and fastapi does not support pydantic 2.0 yet: Prepare for Pydantic V2 release fastapi/fastapi#6051
Pickling pydantic 2 models is not possible, although users can still pickle pydantic 1.0 models via the compatibility pydantic.v1 import.

Signed-off-by: Victor <vctr.y.m@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants