Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sagemaker core is unimportable in warnings as error mode due to SyntaxError: invalid escape sequence: '\|' #244

Open
jmahlik opened this issue Feb 12, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@jmahlik
Copy link

jmahlik commented Feb 12, 2025

Describe the bug
A clear and concise description of what the bug is.

Sagemaker core cannot be imported when running python in warnings as error mode. This comes up a lot in test suites when running pytest in warnings as error mode.

I believe most of this is codegen, so likely will need a fix to the generator to remove invalid escape sequences. Potentially a CI check could be added down the road to ensure the files are importable. There shouldn't be warnings on import either.

To reproduce
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.

# In case the venv creation matters
python -m pip install uv
uv venv venv
. venv/Scripts/active

python --version
Python 3.13.1

 python ./src/sagemaker_core/main/shapes.py
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:5799: SyntaxWarning: invalid escape sequence '\|'
  """
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:6604: SyntaxWarning: invalid escape sequence '\*'
  """
C:\sagemaker-core\src\sagemaker_core\main\shapes.py:8812: SyntaxWarning: invalid escape sequence '\*'
  """
C:\sagemaker-core\venv\Lib\site-packages\pydantic\_internal\_fields.py:192: UserWarning: Field name "json" in "MonitoringDatasetFormat" shadows an attribute in parent "Base"
  warnings.warn(


python -W error ./src/sagemaker_core/main/shapes.py
  File "C:\sagemaker-core\src\sagemaker_core\main\shapes.py", line 5799
    """
    ^^^
SyntaxError: invalid escape sequence '\|'

There's multiple files with this issue. I'm not sure how these are passing tests.

git grep -e '\\|'
src/sagemaker_core/main/resources.py:            task: The machine learning task your model package accomplishes. Common machine learning tasks include object detection and image classification. The following tasks are supported by Inference Recommender: "IMAGE_CLASSIFICATION" \| "OBJECT_DETECTION" \| "TEXT_GENERATION" \|"IMAGE_SEGMENTATION" \| "FILL_MASK" \| "CLASSIFICATION" \| "REGRESSION" \| "OTHER". Specify "OTHER" if none of the tasks listed fit your use case.
src/sagemaker_core/main/shapes.py:    domain: The machine learning domain of the model and its components. Valid Values: COMPUTER_VISION \| NATURAL_LANGUAGE_PROCESSING \| MACHINE_LEARNING
src/sagemaker_core/main/shapes.py:    task: The machine learning task that the model accomplishes. Valid Values: IMAGE_CLASSIFICATION \| OBJECT_DETECTION \| TEXT_GENERATION \| IMAGE_SEGMENTATION \| FILL_MASK \| CLASSIFICATION \| REGRESSION \| OTHER
src/sagemaker_core/main/shapes.py:    framework: The machine learning framework of the container image. Valid Values: TENSORFLOW \| PYTORCH \| XGBOOST \| SAGEMAKER-SCIKIT-LEARN
src/sagemaker_core/main/shapes.py:    nearest_model_name: The name of a pre-trained machine learning model benchmarked by Amazon SageMaker Inference Recommender that matches your model. Valid Values: efficientnetb7 \| unet \| xgboost \| faster-rcnn-resnet101 \| nasnetlarge \| vgg16 \| inception-v3 \| mask-rcnn \| sagemaker-scikit-learn \| densenet201-gluon \| resnet18v2-gluon \| xception \| densenet201 \| yolov4 \| resnet152 \| bert-base-cased \| xceptionV1-keras \| resnet50 \| retinanet

Expected behavior
A clear and concise description of what you expected to happen.
No errors nor warnings on import.

Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.

Bug information
A description of your system. Please provide:

  • SageMaker Core version: main
  • Python version: 3.13, 3.12, 3.11
  • Is the issue with autogen code or with generate code ?: yes

Additional context
Add any other context about the problem here.

@jmahlik jmahlik added the bug Something isn't working label Feb 12, 2025
@jmahlik
Copy link
Author

jmahlik commented Feb 13, 2025

One idea to stop codegen generating python files with warnings or invalid code all together.

Somewhere after reformat with black runs and the files are about to be written:

def reformat_file_with_black(filename):
. Simulate a run of the import to make sure no warnings happen on import.

Something like this.

with warnings.filterwarnings("error"):
    runpy.run_path(file)

@jmahlik jmahlik changed the title Sagemaker core is inimportable due to SyntaxError: invalid escape sequence: '\|' Sagemaker core is unimportable due to SyntaxError: invalid escape sequence: '\|' Feb 13, 2025
@benieric benieric changed the title Sagemaker core is unimportable due to SyntaxError: invalid escape sequence: '\|' Sagemaker core is unimportable in warnings as error mode due to SyntaxError: invalid escape sequence: '\|' Feb 14, 2025
@jmahlik
Copy link
Author

jmahlik commented Feb 24, 2025

Related issue in sm_debug_rulesconfig awslabs/sagemaker-debugger-rulesconfig#45 that also prevents the sagemaker python sdk from being imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant