Skip to content
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

feat(sagemaker): add support uncompressed model #30949

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

WinterYukky
Copy link
Contributor

@WinterYukky WinterYukky commented Jul 25, 2024

Issue # (if applicable)

None.

Reason for this change

Currently, sagemaker.Model only support ModelDataUrl. ModelDataUrl must be gzip the model artifact.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sagemaker-model-containerdefinition.html#cfn-sagemaker-model-containerdefinition-modeldataurl

LLM, which is popular these days, is large and takes longer to compress. For example, the 70B parameter model could take 2 hours or more to compress. SageMaker has a way to use the uncompressed model, and this PR is needed to support the uncompressed model.

The uncompressed model is also recommended in the official documentation.

When deploying ML models, one option is to archive and compress the model artifacts into a tar.gz format. Although this method works well for small models, compressing a large model artifact with hundreds of billions of parameters and then decompressing it on an endpoint can take a significant amount of time. For large model inference, we recommend that you deploy uncompressed ML model.
https://docs.aws.amazon.com/sagemaker/latest/dg/large-model-inference-uncompressed.html

Description of changes

Users can now specify the use of the uncompressed model by taking the model's compression type and S3 data type as options. When using an uncompressed model, use ModelDataSource instead of ModelDataUrl. Since ModelDataSource cannot be used in some workloads, the compression model uses ModelDataUrl as before.

Note

Currently you cannot use ModelDataSource in conjunction with SageMaker batch transform, SageMaker serverless endpoints, SageMaker multi-model endpoints, and SageMaker Marketplace.
https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ContainerDefinition.html#sagemaker-Type-ContainerDefinition-ModelDataSource

Also, asset bundling can now be used as a by-product of being able to use something other than tar.gz due to support for uncompressed models. Until now, no model artifacts with extensions other than tar.gz were permitted, but bundled assets are now allowed if they are not directories.

Since it is not possible to upload a directory or extract a zip with s3_asset.asset alone, the directory cannot continue to be used as an asset. (If there is a way to support directories, please let me know)

Description of how you validated changes

I've added an integ test with assertions that invoke the model endpoint and verify the response.

Checklist

Other

sagemaker-alpha module document is not aligned contributing guide recommendation, so also I fix the it.
https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md#recommendations


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Jul 25, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team July 25, 2024 15:43
@github-actions github-actions bot added the p2 label Jul 25, 2024
Comment on lines -73 to -75
if (!path.toLowerCase().endsWith(ARTIFACT_EXTENSION)) {
throw new Error(`Asset must be a gzipped tar file with extension ${ARTIFACT_EXTENSION} (${this.path})`);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asset's availability determination was moved after binding it as an asset.

Comment on lines +172 to +174
if (!this.asset.isFile) {
throw new Error(`Asset must be a file, if you want to use directory you can use 'ModelData.fromBucket()' with the 's3DataType' option to 'S3DataType.S3_PREFIX' and 'compressionType' option to 'CompressionType.NONE' (${this.path})`);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundled assets are now allowed if they are not directories.

Comment on lines +179 to +182
compressionType: this.asset.assetPath.toLowerCase().endsWith(COMPRESSED_ARTIFACT_EXTENSION)
? CompressionType.GZIP
: CompressionType.NONE,
s3DataType: S3DataType.S3_OBJECT,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncompressed single files are also supported

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: a4882a0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants