Skip to content

Add Pydantic v2 support#213

Closed
mrwyattii wants to merge 3 commits into
mainfrom
mrwyattii/pydantic-v2-support
Closed

Add Pydantic v2 support#213
mrwyattii wants to merge 3 commits into
mainfrom
mrwyattii/pydantic-v2-support

Conversation

@mrwyattii

Copy link
Copy Markdown
Contributor

No description provided.

@ringohoffman

ringohoffman commented Sep 25, 2023

Copy link
Copy Markdown

From the migration guide:

Due to performance overhead and implementation complexity, we have now deprecated support for specifying json_encoders in the model config. This functionality was originally added for the purpose of achieving custom serialization logic, and we think the new serialization decorators are a better choice in most common scenarios.

I think this would be effectively the same as json_encoders={torch.dtype: lambda x: str(x)}:

    @field_serializer('dtype')
    def serialize_dtype(
        self, v: Union[torch.dtype, DtypeEnum], info: SerializationInfo
    ) -> str:
        if isinstance(v, torch.dtype):
            return str(v)
        return str(v.value)

@loadams

loadams commented Aug 19, 2024

Copy link
Copy Markdown
Contributor

Closing this instance as it is repetitive with the actual pydantic PR that will be merged

@loadams loadams closed this Aug 19, 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.

3 participants