Skip to content

Migrate to Pydantic v2#1748

Merged
jesse-c merged 32 commits intoSeldonIO:masterfrom
jesse-c:use-pydantic-v2
May 10, 2024
Merged

Migrate to Pydantic v2#1748
jesse-c merged 32 commits intoSeldonIO:masterfrom
jesse-c:use-pydantic-v2

Conversation

@jesse-c
Copy link
Copy Markdown
Contributor

@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 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 24 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 8 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.
```
@jesse-c jesse-c requested a review from mauicv May 9, 2024 09:47
Copy link
Copy Markdown

@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!

@jesse-c
Copy link
Copy Markdown
Contributor Author

jesse-c commented May 10, 2024

Ran some manual smoke tests with no issues.

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