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
microsoft#4407)

* Introduce pydantic_v1 compatibility module for pydantic>=2.0.0 support
  • Loading branch information
ringohoffman authored and amaurya committed Oct 9, 2023
1 parent 763341e commit fb0568f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deepspeed/comm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

# DeepSpeed Team

from pydantic import BaseModel
from .constants import *
from ..pydantic_v1 import BaseModel


class CommsConfig(BaseModel):
Expand Down
3 changes: 1 addition & 2 deletions deepspeed/inference/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import torch
import deepspeed
from deepspeed.pydantic_v1 import Field, validator
from deepspeed.runtime.config_utils import DeepSpeedConfigModel
from deepspeed.runtime.zero.config import DeepSpeedZeroConfig
from pydantic import Field
from pydantic import validator
from typing import Dict, Union
from enum import Enum

Expand Down
2 changes: 1 addition & 1 deletion deepspeed/monitor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# DeepSpeed Team

from pydantic import root_validator
from deepspeed.pydantic_v1 import root_validator
from deepspeed.runtime.config_utils import DeepSpeedConfigModel


Expand Down
16 changes: 16 additions & 0 deletions deepspeed/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
2 changes: 1 addition & 1 deletion deepspeed/runtime/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import collections
import collections.abc
from functools import reduce
from pydantic import BaseModel
from deepspeed.pydantic_v1 import BaseModel
from deepspeed.utils import logger


Expand Down
2 changes: 1 addition & 1 deletion deepspeed/runtime/zero/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# DeepSpeed Team

from pydantic import Field, validator
import sys
from typing import Optional
from enum import Enum
from deepspeed.pydantic_v1 import Field, validator
from deepspeed.runtime.config_utils import get_scalar_param, pp_int, DeepSpeedConfigModel
from deepspeed.utils import logger
from .offload_config import DeepSpeedZeroOffloadParamConfig, DeepSpeedZeroOffloadOptimizerConfig, OffloadDeviceEnum
Expand Down
2 changes: 1 addition & 1 deletion deepspeed/runtime/zero/offload_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

# DeepSpeed Team

from pydantic import Field, validator
from enum import Enum
from pathlib import Path
from deepspeed.pydantic_v1 import Field, validator
from deepspeed.runtime.config_utils import DeepSpeedConfigModel, pp_int


Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ dependencies:
- certifi
- openssl
- python=3.10
- pydantic<2.0.0
- pydantic
4 changes: 2 additions & 2 deletions requirements/requirements-readthedocs.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
autodoc_pydantic<2.0.0
autodoc_pydantic
docutils<0.18
hjson
packaging
psutil
py-cpuinfo
pydantic<2.0.0
pydantic
torch
tqdm
2 changes: 1 addition & 1 deletion tests/unit/runtime/test_ds_config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import pytest
import os
import json
from pydantic import Field, ValidationError
from typing import List
from deepspeed.pydantic_v1 import Field, ValidationError
from deepspeed.runtime import config as ds_config
from deepspeed.runtime.config_utils import DeepSpeedConfigModel

Expand Down

0 comments on commit fb0568f

Please sign in to comment.