From 40aaf7a754966c50afdc3fa5f3f792a3c1f1b4e6 Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Tue, 26 Sep 2023 17:13:02 -0700 Subject: [PATCH 1/4] Introduce pydantic_v1 compatibility module for pydantic>=2.0.0 support Instead of upgrading deepspeed to pydantic v2, deepspeed can use pydantic v2's alias for the v1 API in order to unpin pydantic and allow greater flexibility for deepspeed users --- .github/workflows/nv-torch-latest-v100.yaml | 2 +- mii/aml_related/templates.py | 2 +- mii/config.py | 2 +- mii/pydantic_v1.py | 12 ++++++++++++ tests/test_config.py | 4 ++-- tests/test_deployment_options.py | 4 ++-- 6 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 mii/pydantic_v1.py diff --git a/.github/workflows/nv-torch-latest-v100.yaml b/.github/workflows/nv-torch-latest-v100.yaml index 4fe615d6..df801985 100644 --- a/.github/workflows/nv-torch-latest-v100.yaml +++ b/.github/workflows/nv-torch-latest-v100.yaml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - pip install git+https://github.com/microsoft/DeepSpeed.git + pip install git+https://github.com/ringohoffman/DeepSpeed.git@pydantic-compatibility-module pip install git+https://github.com/huggingface/transformers.git pip install -U accelerate ds_report diff --git a/mii/aml_related/templates.py b/mii/aml_related/templates.py index 65a1410d..66de070c 100644 --- a/mii/aml_related/templates.py +++ b/mii/aml_related/templates.py @@ -393,6 +393,6 @@ """torch>=2.0.0 grpcio grpcio-tools -pydantic<2.0.0 +pydantic asyncio """ diff --git a/mii/config.py b/mii/config.py index dcb5b6b4..8f4e49e6 100644 --- a/mii/config.py +++ b/mii/config.py @@ -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 diff --git a/mii/pydantic_v1.py b/mii/pydantic_v1.py new file mode 100644 index 00000000..5607d1ae --- /dev/null +++ b/mii/pydantic_v1.py @@ -0,0 +1,12 @@ +"""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/tests/test_config.py b/tests/test_config.py index 00e45d07..09d2b58e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,9 +4,9 @@ # DeepSpeed Team import pytest -import pydantic import mii +from mii import pydantic_v1 @pytest.mark.parametrize("port_number", [12345]) @@ -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) diff --git a/tests/test_deployment_options.py b/tests/test_deployment_options.py index 5b1dcf22..f0566ed7 100644 --- a/tests/test_deployment_options.py +++ b/tests/test_deployment_options.py @@ -6,8 +6,8 @@ import pytest import json import requests -import pydantic import mii +from mii import pydantic_v1 @pytest.mark.deepspeed @@ -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, From 2a0a0d0c9c9cb953628db2154345a6536c8b1780 Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Wed, 27 Sep 2023 10:16:46 -0700 Subject: [PATCH 2/4] Add license header --- mii/pydantic_v1.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mii/pydantic_v1.py b/mii/pydantic_v1.py index 5607d1ae..6aba072a 100644 --- a/mii/pydantic_v1.py +++ b/mii/pydantic_v1.py @@ -1,3 +1,7 @@ +# 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: From e0c36f26972b7a4eaf4ce24c91c956706b305eef Mon Sep 17 00:00:00 2001 From: Michael Wyatt Date: Mon, 9 Oct 2023 12:00:00 -0700 Subject: [PATCH 3/4] Update .github/workflows/nv-torch-latest-v100.yaml --- .github/workflows/nv-torch-latest-v100.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nv-torch-latest-v100.yaml b/.github/workflows/nv-torch-latest-v100.yaml index df801985..271ac42a 100644 --- a/.github/workflows/nv-torch-latest-v100.yaml +++ b/.github/workflows/nv-torch-latest-v100.yaml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - pip install git+https://github.com/ringohoffman/DeepSpeed.git@pydantic-compatibility-module + pip install git+https://github.com/DeepSpeed.git pip install git+https://github.com/huggingface/transformers.git pip install -U accelerate ds_report From 6090ffd30e2cf1381b20da5f57ace60ffc6a08f6 Mon Sep 17 00:00:00 2001 From: Michael Wyatt Date: Mon, 9 Oct 2023 12:10:17 -0700 Subject: [PATCH 4/4] Update .github/workflows/nv-torch-latest-v100.yaml --- .github/workflows/nv-torch-latest-v100.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nv-torch-latest-v100.yaml b/.github/workflows/nv-torch-latest-v100.yaml index 5e5df1da..ffb7384a 100644 --- a/.github/workflows/nv-torch-latest-v100.yaml +++ b/.github/workflows/nv-torch-latest-v100.yaml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - pip install git+https://github.com/DeepSpeed.git + pip install git+https://github.com/microsoft/DeepSpeed.git pip install git+https://github.com/huggingface/transformers.git pip install -U accelerate ds_report