-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: include model channel for gated uncompressed models #5181
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
Merged
benieric
merged 5 commits into
aws:master
from
evakravi:fix/include-model-channel-for-gated-uncompressed-models
May 16, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7531524
fix: include model channel for gated uncompressed models
evakravi ade4453
chore: add unit tests
evakravi c9cc193
fix: flake8
evakravi ed67de5
chore: add __init__.py file
evakravi 51321c3
chore: always use model channel for private hub models, add unit tests
evakravi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
162 changes: 162 additions & 0 deletions
162
tests/unit/sagemaker/jumpstart/factory/test_estimator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
from __future__ import absolute_import | ||
import pytest | ||
from unittest.mock import patch | ||
from sagemaker.jumpstart.constants import JUMPSTART_MODEL_HUB_NAME | ||
from sagemaker.jumpstart.factory.estimator import ( | ||
_add_model_uri_to_kwargs, | ||
get_model_info_default_kwargs, | ||
) | ||
from sagemaker.jumpstart.types import JumpStartEstimatorInitKwargs | ||
from sagemaker.jumpstart.enums import JumpStartScriptScope | ||
|
||
|
||
class TestAddModelUriToKwargs: | ||
@pytest.fixture | ||
def mock_kwargs(self): | ||
return JumpStartEstimatorInitKwargs( | ||
model_id="test-model", | ||
model_version="1.0.0", | ||
instance_type="ml.m5.large", | ||
model_uri=None, | ||
) | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=True, | ||
) | ||
@patch("sagemaker.jumpstart.factory.estimator.model_uris.retrieve") | ||
def test_add_model_uri_to_kwargs_default_uri( | ||
self, mock_retrieve, mock_supports_training, mock_kwargs | ||
): | ||
"""Test adding default model URI when none is provided.""" | ||
default_uri = "s3://jumpstart-models/training/test-model/1.0.0" | ||
mock_retrieve.return_value = default_uri | ||
|
||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
mock_supports_training.assert_called_once() | ||
mock_retrieve.assert_called_once_with( | ||
model_scope=JumpStartScriptScope.TRAINING, | ||
instance_type=mock_kwargs.instance_type, | ||
**get_model_info_default_kwargs(mock_kwargs), | ||
) | ||
assert result.model_uri == default_uri | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=True, | ||
) | ||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_incremental_training", | ||
return_value=True, | ||
) | ||
@patch("sagemaker.jumpstart.factory.estimator.model_uris.retrieve") | ||
def test_add_model_uri_to_kwargs_custom_uri_with_incremental( | ||
self, mock_retrieve, mock_supports_incremental, mock_supports_training, mock_kwargs | ||
): | ||
"""Test using custom model URI with incremental training support.""" | ||
default_uri = "s3://jumpstart-models/training/test-model/1.0.0" | ||
custom_uri = "s3://custom-bucket/my-model" | ||
mock_retrieve.return_value = default_uri | ||
mock_kwargs.model_uri = custom_uri | ||
|
||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
mock_supports_training.assert_called_once() | ||
mock_supports_incremental.assert_called_once() | ||
assert result.model_uri == custom_uri | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=True, | ||
) | ||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_incremental_training", | ||
return_value=False, | ||
) | ||
@patch("sagemaker.jumpstart.factory.estimator.model_uris.retrieve") | ||
@patch("sagemaker.jumpstart.factory.estimator.JUMPSTART_LOGGER.warning") | ||
def test_add_model_uri_to_kwargs_custom_uri_without_incremental( | ||
self, | ||
mock_warning, | ||
mock_retrieve, | ||
mock_supports_incremental, | ||
mock_supports_training, | ||
mock_kwargs, | ||
): | ||
"""Test using custom model URI without incremental training support logs warning.""" | ||
default_uri = "s3://jumpstart-models/training/test-model/1.0.0" | ||
custom_uri = "s3://custom-bucket/my-model" | ||
mock_retrieve.return_value = default_uri | ||
mock_kwargs.model_uri = custom_uri | ||
|
||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
mock_supports_training.assert_called_once() | ||
mock_supports_incremental.assert_called_once() | ||
mock_warning.assert_called_once() | ||
assert "does not support incremental training" in mock_warning.call_args[0][0] | ||
assert result.model_uri == custom_uri | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=False, | ||
) | ||
def test_add_model_uri_to_kwargs_no_training_support(self, mock_supports_training, mock_kwargs): | ||
"""Test when model doesn't support training model URI.""" | ||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
mock_supports_training.assert_called_once() | ||
assert result.model_uri is None | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=False, | ||
) | ||
@patch("sagemaker.jumpstart.factory.estimator.model_uris.retrieve") | ||
def test_add_model_uri_to_kwargs_private_hub( | ||
self, mock_retrieve, mock_supports_training, mock_kwargs | ||
): | ||
"""Test when model is from a private hub.""" | ||
default_uri = "s3://jumpstart-models/training/test-model/1.0.0" | ||
mock_retrieve.return_value = default_uri | ||
mock_kwargs.hub_arn = "arn:aws:sagemaker:us-west-2:123456789012:hub/private-hub" | ||
|
||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
# Should not check if model supports training model URI for private hub | ||
mock_supports_training.assert_not_called() | ||
mock_retrieve.assert_called_once() | ||
assert result.model_uri == default_uri | ||
|
||
@patch( | ||
"sagemaker.jumpstart.factory.estimator._model_supports_training_model_uri", | ||
return_value=False, | ||
) | ||
@patch("sagemaker.jumpstart.factory.estimator.model_uris.retrieve") | ||
def test_add_model_uri_to_kwargs_public_hub( | ||
self, mock_retrieve, mock_supports_training, mock_kwargs | ||
): | ||
"""Test when model is from the public hub.""" | ||
mock_kwargs.hub_arn = ( | ||
f"arn:aws:sagemaker:us-west-2:123456789012:hub/{JUMPSTART_MODEL_HUB_NAME}" | ||
) | ||
|
||
result = _add_model_uri_to_kwargs(mock_kwargs) | ||
|
||
# Should check if model supports training model URI for public hub | ||
mock_supports_training.assert_called_once() | ||
mock_retrieve.assert_not_called() | ||
assert result.model_uri is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised we didn't have this before, thanks for adding it!