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

Migrate to Pydantic v2 #1748

Merged
merged 32 commits into from
May 10, 2024
Merged

Migrate to Pydantic v2 #1748

merged 32 commits into from
May 10, 2024

Conversation

jesse-c
Copy link
Member

@jesse-c jesse-c commented May 8, 2024

We're going for a wholesale update to Pydantic v2. Whilst I've tried to be as minimal as possible [1], I've fixed some things that were exposed during the migration [2]. Since we plan on this being a minor release, I've avoided any breaking changes in MLServer's interfaces.

It's a hefty PR. Each commit is an attempt at a self-contained part of the migration, and thus is best reviewed commit-by-commit. In saying that, it is of course a holistic change and a long line of dominoes.

For many of the commits, I've linked to the relevant part of the Pydantic v2 (migration) docs.

There will be manual integration testing as well.

[1] There's some deprecation warnings for v3 that I've looked past
[2] Example: Some incorrect tests

FIXES #1419

@jesse-c jesse-c self-assigned this May 8, 2024
@jesse-c jesse-c force-pushed the use-pydantic-v2 branch 3 times, most recently from 115baaf to e607afc Compare May 8, 2024 11:49
@jesse-c jesse-c marked this pull request as ready for review May 8, 2024 12:38
@jesse-c jesse-c mentioned this pull request May 8, 2024
jesse-c added 21 commits May 8, 2024 16:37
> underscore_attrs_are_private — the Pydantic V2 behavior is now the
same as if this was always set to True in Pydantic V1. [1]

[1] https://docs.pydantic.dev/latest/migration/#changes-to-config
jesse-c added 11 commits May 8, 2024 16:37
> In Pydantic V2, the performance gap between BaseModel.__init__ and
BaseModel.model_construct has been narrowed considerably. For simple
models, calling BaseModel.__init__ may even be faster. If you are
using model_construct() for performance reasons, you may want to
profile your use case before assuming that model_construct() is
faster. [1]

[1] https://docs.pydantic.dev/latest/concepts/models/#creating-models-without-validation
It was previously a `MagicMock` for the model's `predict` function
response. This ensures that there's a dummy value available.
I've changed tasks as well avoid a `can_generate` error on the default
chosen model for the question-answering task.

```
E               ValueError: Asked to export a gpt2 model for the task question-answering, but the Optimum ONNX exporter only supports the tasks feature-extraction, feature-extraction-with-past, text-generation, text-generation-with-past, text-classification, token-classification for gpt2. Please use a supported task. Please open an issue at https://github.com/huggingface/optimum/issues if you would like the task question-answering to be supported in the ONNX export for gpt2.
```
Copy link

@mauicv mauicv left a comment

Choose a reason for hiding this comment

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

Couple of minor questions but otherwise LGTM!

mlserver/types/dataplane.py Show resolved Hide resolved
mlserver/types/model_repository.py Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
runtimes/huggingface/tests/conftest.py Show resolved Hide resolved
@jesse-c
Copy link
Member Author

jesse-c commented May 10, 2024

Ran some manual smoke tests with no issues.

@jesse-c jesse-c merged commit 58cf8dc into SeldonIO:master May 10, 2024
46 of 50 checks passed
@jesse-c jesse-c deleted the use-pydantic-v2 branch May 10, 2024 15:14
jesse-c added a commit to jesse-c/MLServer that referenced this pull request May 13, 2024
jesse-c added a commit to jesse-c/MLServer that referenced this pull request May 13, 2024
jesse-c added a commit to jesse-c/MLServer that referenced this pull request May 13, 2024
jesse-c added a commit that referenced this pull request May 13, 2024
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.

Add support for Pydantic V2
2 participants