aws / sagemaker-python-sdk

A library for training and deploying machine learning models on Amazon SageMaker
https://sagemaker.readthedocs.io/
Apache License 2.0
2.11k stars 1.14k forks source link

[bug] NameError when importing Transformer #4933

Open epassaroRKD opened 5 days ago

epassaroRKD commented 5 days ago

Describe the bug In latest version, after importing Transformers from sagemaker.transformer I get the error NameError: Field name "json" shadows a BaseModel attribute; use a different field name with "alias='json'".

EDIT: Fixed by updating pydantic.

To reproduce

from sagemarker.transformer import Transformer

Result:

in <module>:3                                                                                    │
│                                                                                                  │
│    1 import json                                                                                 │
│    2                                                                                             │
│ ❱  3 from sagemaker.transformer import Transformer                                               │
│    4                                                                                             │
│    5 from sagemaker.workflow.steps import CacheConfig                                            │
│    6 from sagemaker.workflow.functions import Join                                               │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker/__init__.py:18 in <module>                     │
│                                                                                                  │
│   15                                                                                             │
│   16 import importlib_metadata                                                                   │
│   17                                                                                             │
│ ❱ 18 from sagemaker import estimator, parameter, tuner  # noqa: F401                             │
│   19 from sagemaker.amazon.kmeans import KMeans, KMeansModel, KMeansPredictor  # noqa: F401      │
│   20 from sagemaker.amazon.pca import PCA, PCAModel, PCAPredictor  # noqa: F401                  │
│   21 from sagemaker.amazon.lda import LDA, LDAModel, LDAPredictor  # noqa: F401                  │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker/estimator.py:30 in <module>                    │
│                                                                                                  │
│     27 from six.moves.urllib.parse import urlparse                                               │
│     28                                                                                           │
│     29 import sagemaker                                                                          │
│ ❱   30 from sagemaker import git_utils, image_uris, vpc_utils, s3                                │
│     31 from sagemaker.analytics import TrainingJobAnalytics                                      │
│     32 from sagemaker.config import (                                                            │
│     33 │   ESTIMATOR_DEBUG_HOOK_CONFIG_PATH,                                                     │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker/image_uris.py:24 in <module>                   │
│                                                                                                  │
│    21 from packaging.version import Version                                                      │
│    22                                                                                            │
│    23 from sagemaker import utils                                                                │
│ ❱  24 from sagemaker.jumpstart.constants import DEFAULT_JUMPSTART_SAGEMAKER_SESSION              │
│    25 from sagemaker.jumpstart.enums import JumpStartModelType                                   │
│    26 from sagemaker.jumpstart.utils import is_jumpstart_model_input                             │
│    27 from sagemaker.spark import defaults                                                       │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker/jumpstart/constants.py:27 in <module>          │
│                                                                                                  │
│    24 │   MIMEType,                                                                              │
│    25 │   JumpStartModelType,                                                                    │
│    26 )                                                                                          │
│ ❱  27 from sagemaker.jumpstart.types import JumpStartLaunchedRegionInfo, JumpStartS3FileType     │
│    28 from sagemaker.base_serializers import (                                                   │
│    29 │   BaseSerializer,                                                                        │
│    30 │   CSVSerializer,                                                                         │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker/jumpstart/types.py:20 in <module>              │
│                                                                                                  │
│     17 from copy import deepcopy                                                                 │
│     18 from enum import Enum                                                                     │
│     19 from typing import Any, Dict, List, Optional, Set, Union                                  │
│ ❱   20 from sagemaker_core.shapes import ModelAccessConfig as CoreModelAccessConfig              │
│     21 from sagemaker.model_card.model_card import ModelCard, ModelPackageModelCard              │
│     22 from sagemaker.utils import (                                                             │
│     23 │   S3_PREFIX,                                                                            │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker_core/shapes/__init__.py:1 in <module>          │
│                                                                                                  │
│ ❱ 1 from ..main.shapes import *                                                                  │
│   2                                                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.10/site-packages/sagemaker_core/main/shapes.py:2509 in <module>           │
│                                                                                                  │
│    2506 │   """                                                                                  │
│    2507                                                                                          │
│    2508                                                                                          │
│ ❱  2509 class MonitoringDatasetFormat(Base):                                                     │
│    2510 │   """                                                                                  │
│    2511 │   MonitoringDatasetFormat                                                              │
│    2512 │     Represents the dataset format used when running a monitoring job.                  │
│                                                                                                  │
│ in pydantic.main.ModelMetaclass.__new__:186                                                      │
│                                                                                                  │
│ in pydantic.utils.validate_field_name:167                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
NameError: Field name "json" shadows a BaseModel attribute; use a different field name with "alias='json'".

Expected behavior

Screenshots or logs

System information A description of your system. Please provide:

Additional context Add any other context about the problem here.

dzornek commented 2 days ago

I am getting the same error when doing from sagemaker.jumpstart.model import JumpStartModel.

Edit: Resolved for me by upgrading the sagemaker sdk to 2.235.2