Skip to content

[fix]: Pass sagemaker session to downstream s3 calls #3775

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
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/sagemaker/djl_inference/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ def _read_existing_serving_properties(directory: str):
return properties


def _get_model_config_properties_from_s3(model_s3_uri: str):
def _get_model_config_properties_from_s3(model_s3_uri: str, sagemaker_session: Session):
"""Placeholder docstring"""

s3_files = s3.S3Downloader.list(model_s3_uri)
s3_files = s3.S3Downloader.list(model_s3_uri, sagemaker_session=sagemaker_session)
model_config = None
for config in defaults.VALID_MODEL_CONFIG_FILES:
config_file = os.path.join(model_s3_uri, config)
if config_file in s3_files:
model_config = json.loads(s3.S3Downloader.read_file(config_file))
model_config = json.loads(
s3.S3Downloader.read_file(config_file, sagemaker_session=sagemaker_session)
)
break
if not model_config:
raise ValueError(
Expand Down Expand Up @@ -198,7 +200,8 @@ def __new__(
"containing folder"
)
if model_id.startswith("s3://"):
model_config = _get_model_config_properties_from_s3(model_id)
sagemaker_session = kwargs.get("sagemaker_session")
model_config = _get_model_config_properties_from_s3(model_id, sagemaker_session)
else:
model_config = _get_model_config_properties_from_hf(model_id)
if model_config.get("_class_name") == "StableDiffusionPipeline":
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_djl_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def test_create_model_automatic_engine_selection(mock_s3_list, mock_read_file, s
sagemaker_session=sagemaker_session,
number_of_partitions=2,
)
mock_s3_list.assert_any_call(
VALID_UNCOMPRESSED_MODEL_DATA, sagemaker_session=sagemaker_session
)
if model_type == defaults.STABLE_DIFFUSION_MODEL_TYPE:
assert ds_model.engine == DJLServingEngineEntryPointDefaults.STABLE_DIFFUSION
else:
Expand Down