Skip to content

Commit d664b18

Browse files
committed
Fix
1 parent d959a9d commit d664b18

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

sagemaker-serve/src/sagemaker/serve/model_builder.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,13 @@ def _resolve_model_artifact_uri(self) -> Optional[str]:
514514
fine-tuned model.
515515
516516
Returns:
517-
Optional[str]: S3 URI to model artifacts, or None for LORA adapters
517+
Optional[str]: S3 URI to model artifacts, or None when not needed
518518
519519
Logic:
520520
- For LORA adapters: Returns None (adapter weights are separate)
521+
- For fine-tuned models: Returns None (model data is handled by the recipe/container)
521522
- For base models: Uses HostingArtifactUri from JumpStart hub metadata
522-
- For full fine-tuned models: Uses ModelPackage artifact location
523+
- For non-model-customization: Returns None
523524
524525
Raises:
525526
ValueError: If model package or hub metadata is unavailable when needed
@@ -534,22 +535,23 @@ def _resolve_model_artifact_uri(self) -> Optional[str]:
534535
if self._is_model_customization():
535536
model_package = self._fetch_model_package()
536537
if model_package:
537-
# Check if this is a full fine-tuned model (has its own artifacts)
538538
if (hasattr(model_package, 'inference_specification') and
539539
model_package.inference_specification and
540540
hasattr(model_package.inference_specification, 'containers') and
541541
model_package.inference_specification.containers):
542542

543543
container = model_package.inference_specification.containers[0]
544544

545-
# If container has model_data_source, use it (full fine-tuned model)
545+
# For fine-tuned models (have model_data_source), return None.
546+
# The model data is handled by the recipe/container configuration,
547+
# not via artifact_url in CreateInferenceComponent.
546548
if (hasattr(container, 'model_data_source') and
547549
container.model_data_source and
548550
hasattr(container.model_data_source, 's3_data_source') and
549551
container.model_data_source.s3_data_source):
550-
return container.model_data_source.s3_data_source.s3_uri
552+
return None
551553

552-
# Otherwise, this is a base model - get HostingArtifactUri from JumpStart
554+
# For base models, get HostingArtifactUri from JumpStart
553555
if hasattr(container, 'base_model') and container.base_model:
554556
try:
555557
hub_document = self._fetch_hub_document_for_custom_model()
@@ -570,7 +572,6 @@ def _resolve_model_artifact_uri(self) -> Optional[str]:
570572
return None
571573

572574
# For non-model-customization deployments, return None
573-
# (artifact handling is done differently for those cases)
574575
return None
575576

576577
def _infer_instance_type_from_jumpstart(self) -> str:

sagemaker-serve/tests/unit/test_artifact_path_propagation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ def test_fine_tuned_model_artifact_uri_propagated_to_inference_component(
150150
mock_is_model_customization.return_value = True
151151
mock_fetch_peft.return_value = "FULL"
152152

153-
# Setup: Artifact URI resolution returns model package S3 URI
154-
expected_artifact_uri = 's3://my-bucket/fine-tuned-model/model.tar.gz'
155-
mock_resolve_artifact.return_value = expected_artifact_uri
153+
# Setup: Artifact URI resolution returns None for fine-tuned models
154+
mock_resolve_artifact.return_value = None
156155

157156
# Setup: Model package
158157
mock_package = Mock()
@@ -209,8 +208,8 @@ def test_fine_tuned_model_artifact_uri_propagated_to_inference_component(
209208
# Extract the specification
210209
ic_spec = call_kwargs['specification']
211210

212-
# Verify artifact_url matches the resolved URI
213-
assert ic_spec.container.artifact_url == expected_artifact_uri
211+
# Verify artifact_url is None for fine-tuned models (model data handled by recipe)
212+
assert ic_spec.container.artifact_url is None
214213

215214
@patch('sagemaker.core.resources.InferenceComponent.create')
216215
@patch('sagemaker.core.resources.InferenceComponent.get_all')

sagemaker-serve/tests/unit/test_artifact_path_resolution.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_fine_tuned_adapter_artifact_location(
9595
mock_fetch_peft,
9696
mock_fetch_package
9797
):
98-
"""Test fine-tuned adapter artifact location from ModelPackage."""
98+
"""Test fine-tuned model returns None (model data handled by recipe/container)."""
9999
# Setup: Full fine-tuned model (not LORA)
100100
mock_is_model_customization.return_value = True
101101
mock_fetch_peft.return_value = "FULL"
@@ -127,8 +127,8 @@ def test_fine_tuned_adapter_artifact_location(
127127
# Execute
128128
artifact_uri = builder._resolve_model_artifact_uri()
129129

130-
# Verify: Should return model_data_source S3 URI
131-
assert artifact_uri == 's3://my-bucket/fine-tuned-model/model.tar.gz'
130+
# Verify: Fine-tuned models return None - model data is handled by recipe/container
131+
assert artifact_uri is None
132132

133133
@patch('sagemaker.serve.model_builder.ModelBuilder._fetch_peft')
134134
@patch('sagemaker.serve.model_builder.ModelBuilder._is_model_customization')
@@ -434,7 +434,7 @@ def test_fine_tuned_model_with_nested_s3_data_source(
434434
mock_fetch_peft,
435435
mock_fetch_package
436436
):
437-
"""Test fine-tuned model with properly nested s3_data_source structure."""
437+
"""Test fine-tuned model with nested s3_data_source returns None."""
438438
# Setup: Full fine-tuned model with nested structure
439439
mock_is_model_customization.return_value = True
440440
mock_fetch_peft.return_value = "FULL"
@@ -443,7 +443,6 @@ def test_fine_tuned_model_with_nested_s3_data_source(
443443
mock_package = Mock()
444444
mock_container = Mock()
445445

446-
# Create nested structure: container -> model_data_source -> s3_data_source -> s3_uri
447446
mock_s3_data_source = Mock()
448447
mock_s3_data_source.s3_uri = 's3://custom-bucket/my-fine-tuned-model/artifacts.tar.gz'
449448

@@ -470,8 +469,8 @@ def test_fine_tuned_model_with_nested_s3_data_source(
470469
# Execute
471470
artifact_uri = builder._resolve_model_artifact_uri()
472471

473-
# Verify: Should return the nested S3 URI
474-
assert artifact_uri == 's3://custom-bucket/my-fine-tuned-model/artifacts.tar.gz'
472+
# Verify: Fine-tuned models return None - model data handled by recipe/container
473+
assert artifact_uri is None
475474

476475
@patch('sagemaker.serve.model_builder.ModelBuilder._fetch_hub_document_for_custom_model')
477476
@patch('sagemaker.serve.model_builder.ModelBuilder._fetch_model_package')

0 commit comments

Comments
 (0)