diff --git a/src/sagemaker/model.py b/src/sagemaker/model.py index 83efa57cb8..75e736ae96 100644 --- a/src/sagemaker/model.py +++ b/src/sagemaker/model.py @@ -603,6 +603,7 @@ def register( model_card=model_card, model_life_cycle=model_life_cycle, ) + print("Model package args are:", **model_pkg_args) model_package = self.sagemaker_session.create_model_package_from_containers( **model_pkg_args ) @@ -982,6 +983,9 @@ def _create_sagemaker_model( enable_network_isolation=self._enable_network_isolation, tags=format_tags(tags), ) + print("ruiliann test create_model_args:", create_model_args) # Print create_model_args + + self.sagemaker_session.create_model(**create_model_args) def _get_model_uri(self): diff --git a/src/sagemaker/serve/builder/model_builder.py b/src/sagemaker/serve/builder/model_builder.py index 6a3b093ac5..9d584edd01 100644 --- a/src/sagemaker/serve/builder/model_builder.py +++ b/src/sagemaker/serve/builder/model_builder.py @@ -20,9 +20,12 @@ import logging import os import re +import aws_cdk as cdk from pathlib import Path +from constructs import Construct +import sagemaker from sagemaker.enums import Tag from sagemaker.s3 import S3Downloader @@ -345,7 +348,7 @@ def _auto_detect_container(self): # Auto detect the container image uri if self.image_uri: logger.info( - "Skipping auto detection as the image uri is provided %s", + "Test Skipping auto detection as the image uri is provided %s", self.image_uri, ) return @@ -1485,28 +1488,6 @@ def _optimize_for_hf( return create_optimization_job_args return None + + - def _optimize_prepare_for_hf(self): - """Prepare huggingface model data for optimization.""" - custom_model_path: str = ( - self.model_metadata.get("CUSTOM_MODEL_PATH") if self.model_metadata else None - ) - if _is_s3_uri(custom_model_path): - # Remove slash by the end of s3 uri, as it may lead to / subfolder during upload. - custom_model_path = ( - custom_model_path[:-1] if custom_model_path.endswith("/") else custom_model_path - ) - else: - if not custom_model_path: - custom_model_path = f"/tmp/sagemaker/model-builder/{self.model}" - download_huggingface_model_metadata( - self.model, - os.path.join(custom_model_path, "code"), - self.env_vars.get("HUGGING_FACE_HUB_TOKEN"), - ) - - self.pysdk_model.model_data, env = self._prepare_for_mode( - model_path=custom_model_path, - should_upload_artifacts=True, - ) - self.pysdk_model.env.update(env) diff --git a/src/sagemaker/serve/builder/testCFN.py b/src/sagemaker/serve/builder/testCFN.py new file mode 100644 index 0000000000..7e93ce8c66 --- /dev/null +++ b/src/sagemaker/serve/builder/testCFN.py @@ -0,0 +1,44 @@ +from aws_cdk import ( + Stack, + aws_sagemaker as sagemaker, + CfnOutput, + App, +) +from constructs import Construct +from aws_cdk.cloudformation_include import CfnInclude +import json + +class SageMakerEndpointConfigStack(Stack): + + def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: + super().__init__(scope, construct_id, **kwargs) + + # Create SageMaker EndpointConfig + endpoint_config = sagemaker.CfnEndpointConfig( + self, "MyEndpointConfig", + production_variants=[ + sagemaker.CfnEndpointConfig.ProductionVariantProperty( + initial_instance_count=1, + instance_type="ml.t2.medium", + model_name="model-name-1348706a967911ef97190653ff4a3db9", + variant_name="AllTraffic", + initial_variant_weight=1.0 + ) + ], + endpoint_config_name="test-endpoint-config-11-20" + ) + + # Output the EndpointConfig name + CfnOutput(self, "EndpointConfigName", value=endpoint_config.endpoint_config_name) + +app = App() +stack = SageMakerEndpointConfigStack(app, "SageMakerEndpointConfigStack") + +# Synthesize the stack to a CloudFormation template +cfn_template = app.synth().get_stack_by_name(stack.stack_name).template + +# Save the CloudFormation template as a JSON file +with open("sagemaker_endpoint_config_template.json", "w") as f: + json.dump(cfn_template, f, indent=2) +print("cccccc") +app.synth() diff --git a/src/sagemaker/serve/builder/testCreateEndpoint.py b/src/sagemaker/serve/builder/testCreateEndpoint.py new file mode 100644 index 0000000000..a7646c17ff --- /dev/null +++ b/src/sagemaker/serve/builder/testCreateEndpoint.py @@ -0,0 +1,63 @@ +from aws_cdk import ( + Stack, + aws_sagemaker as sagemaker, + CfnOutput, + App, +) +from constructs import Construct +import json + +class SageMakerEndpointStack(Stack): + + def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: + super().__init__(scope, construct_id, **kwargs) + + # Create SageMaker EndpointConfig + endpoint_config = sagemaker.CfnEndpointConfig( + self, "MyEndpointConfig", + production_variants=[ + sagemaker.CfnEndpointConfig.ProductionVariantProperty( + initial_instance_count=1, + instance_type="ml.t2.medium", + model_name="model-name-1348706a967911ef97190653ff4a3db9", + variant_name="AllTraffic", + initial_variant_weight=1.0 + ) + ], + endpoint_config_name="test-endpoint-config-11-20-001" + ) + + # Create SageMaker Endpoint + endpoint = sagemaker.CfnEndpoint( + self, "MyEndpoint", + endpoint_config_name=endpoint_config.endpoint_config_name, + endpoint_name="test-endpoint-11-20" + ) + + # Ensure the Endpoint is created after the EndpointConfig + endpoint.add_dependency(endpoint_config) + + # Output the EndpointConfig name + CfnOutput(self, "EndpointConfigName", value=endpoint_config.endpoint_config_name) + + # Output the Endpoint name + CfnOutput(self, "EndpointName", value=endpoint.endpoint_name) + +def generate_cfn_template(): + app = App() + stack = SageMakerEndpointStack(app, "SageMakerEndpointStack") + + # Synthesize the stack to a CloudFormation template + cfn_template = app.synth().get_stack_by_name(stack.stack_name).template + + # Save the CloudFormation template as a JSON file + with open("sagemaker_endpoint_template.json", "w") as f: + json.dump(cfn_template, f, indent=2) + + print("CloudFormation template saved as sagemaker_endpoint_template.json") + + return cfn_template + +if __name__ == "__main__": + generate_cfn_template() + print("CDK synthesis complete")