diff --git a/deepspeed/comm/config.py b/deepspeed/comm/config.py index 138badebe5a9..1c441bb6bfe9 100644 --- a/deepspeed/comm/config.py +++ b/deepspeed/comm/config.py @@ -3,8 +3,8 @@ # DeepSpeed Team -from pydantic import BaseModel from .constants import * +from ..pydantic_v1 import BaseModel class CommsConfig(BaseModel): diff --git a/deepspeed/inference/config.py b/deepspeed/inference/config.py index 70f1c0dbd5b7..1d5018aaa75b 100644 --- a/deepspeed/inference/config.py +++ b/deepspeed/inference/config.py @@ -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 diff --git a/deepspeed/monitor/config.py b/deepspeed/monitor/config.py index 2706764290fd..5a8ca6ecf5cd 100644 --- a/deepspeed/monitor/config.py +++ b/deepspeed/monitor/config.py @@ -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 diff --git a/deepspeed/pydantic_v1.py b/deepspeed/pydantic_v1.py new file mode 100644 index 000000000000..6aba072ad929 --- /dev/null +++ b/deepspeed/pydantic_v1.py @@ -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 diff --git a/deepspeed/runtime/config_utils.py b/deepspeed/runtime/config_utils.py index 0fb1372deac8..5522a8e79d69 100755 --- a/deepspeed/runtime/config_utils.py +++ b/deepspeed/runtime/config_utils.py @@ -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 diff --git a/deepspeed/runtime/zero/config.py b/deepspeed/runtime/zero/config.py index 1fc11f0e46f5..35d60b5b3290 100644 --- a/deepspeed/runtime/zero/config.py +++ b/deepspeed/runtime/zero/config.py @@ -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 diff --git a/deepspeed/runtime/zero/offload_config.py b/deepspeed/runtime/zero/offload_config.py index c3a6dc7af530..1bd79412d39f 100644 --- a/deepspeed/runtime/zero/offload_config.py +++ b/deepspeed/runtime/zero/offload_config.py @@ -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 diff --git a/environment.yml b/environment.yml index e55fe96e5a5a..28c298717d80 100644 --- a/environment.yml +++ b/environment.yml @@ -18,4 +18,4 @@ dependencies: - certifi - openssl - python=3.10 - - pydantic<2.0.0 + - pydantic diff --git a/requirements/requirements-readthedocs.txt b/requirements/requirements-readthedocs.txt index a6d7915e0ea5..fcd0ec5a9a6a 100644 --- a/requirements/requirements-readthedocs.txt +++ b/requirements/requirements-readthedocs.txt @@ -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 diff --git a/tests/unit/runtime/test_ds_config_model.py b/tests/unit/runtime/test_ds_config_model.py index b9c67c9a30dd..87ea747cf423 100644 --- a/tests/unit/runtime/test_ds_config_model.py +++ b/tests/unit/runtime/test_ds_config_model.py @@ -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