Skip to content

Commit

Permalink
Introduce pydantic_v1 compatibility module for pydantic>=2.0.0 support (
Browse files Browse the repository at this point in the history
#240)

* Introduce pydantic_v1 compatibility module for pydantic>=2.0.0 support

Co-authored-by: Michael Wyatt <[email protected]>
  • Loading branch information
ringohoffman and mrwyattii authored Oct 9, 2023
1 parent 3cd6112 commit ab6b544
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mii/aml_related/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,6 @@
"""torch>=2.0.0
grpcio
grpcio-tools
pydantic<2.0.0
pydantic
asyncio
"""
2 changes: 1 addition & 1 deletion mii/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import os
import string
from typing import List, Optional, Dict, Any
from pydantic import validator, root_validator, Field
import mii
from .constants import DeploymentType, TaskType, MII_MODEL_PATH_DEFAULT
from .pydantic_v1 import validator, root_validator, Field

from deepspeed.runtime.config_utils import DeepSpeedConfigModel
from deepspeed.inference.config import DtypeEnum
Expand Down
16 changes: 16 additions & 0 deletions mii/pydantic_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team
"""Pydantic v1 compatibility module.
Pydantic v2 introduced breaking changes that hinder its adoption:
https://docs.pydantic.dev/latest/migration/. To provide deepspeed users the option to
migrate to pydantic v2 on their own timeline, deepspeed uses this compatibility module
as a pydantic-version-agnostic alias for pydantic's v1 API.
"""

try:
from pydantic.v1 import * # noqa: F401
except ImportError:
from pydantic import * # noqa: F401
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# DeepSpeed Team

import pytest
import pydantic

import mii
from mii import pydantic_v1


@pytest.mark.parametrize("port_number", [12345])
Expand All @@ -23,7 +23,7 @@ def test_base_configs(deployment_name, mii_config, model_config):
@pytest.mark.parametrize("port_number", ["fail"])
@pytest.mark.parametrize("tensor_parallel", [3.5])
def test_base_configs_literalfail(deployment_name, mii_config, model_config):
with pytest.raises(pydantic.ValidationError):
with pytest.raises(pydantic_v1.ValidationError):
mii_config["deployment_name"] = deployment_name
mii_config["model_config"] = model_config
mii_config = mii.config.MIIConfig(**mii_config)
4 changes: 2 additions & 2 deletions tests/test_deployment_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import pytest
import json
import requests
import pydantic
import mii
from mii import pydantic_v1


@pytest.mark.deepspeed
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_zero_config(deployment, query):


@pytest.mark.deepspeed
@pytest.mark.parametrize("expected_failure", [pydantic.ValidationError])
@pytest.mark.parametrize("expected_failure", [pydantic_v1.ValidationError])
@pytest.mark.parametrize(
"enable_deepspeed, enable_zero, dtype",
[(True,
Expand Down

0 comments on commit ab6b544

Please sign in to comment.