Skip to content

Dev ruiliann #4936

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

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/sagemaker/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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):
Expand Down
31 changes: 6 additions & 25 deletions src/sagemaker/serve/builder/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
44 changes: 44 additions & 0 deletions src/sagemaker/serve/builder/testCFN.py
Original file line number Diff line number Diff line change
@@ -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()
63 changes: 63 additions & 0 deletions src/sagemaker/serve/builder/testCreateEndpoint.py
Original file line number Diff line number Diff line change
@@ -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")
Loading