-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathsagemaker_huggingface_model_svd-stack.ts
More file actions
94 lines (85 loc) · 3.29 KB
/
sagemaker_huggingface_model_svd-stack.ts
File metadata and controls
94 lines (85 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
import { NagSuppressions } from "cdk-nag";
import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import { Construct } from 'constructs';
import * as genai from '@cdklabs/generative-ai-cdk-constructs';
export class SagemakerHuggingfaceModelSvdStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Define some constants
const BUCKET_NAME = 'sagemaker-us-east-1-XXXXXXXX';
const BUCKET_KEY = 'svd-hf-1';
const BUCKET_PATH = `s3://${BUCKET_NAME}/${BUCKET_KEY}`
const BUCKET_ARN = `arn:aws:s3:::${BUCKET_NAME}`
const SG_ENDPOINT_NAME = 'svdendpoint';
const HUGGING_FACE_MODEL_ID = 'stabilityai/stable-video-diffusion-img2vid-xt-1-1';
// Custom Sagemaker Endpoint construct
const CustomHuggingFaceEndpoint = new genai.CustomSageMakerEndpoint(this, 'testsvdendpoint', {
modelId: HUGGING_FACE_MODEL_ID,
instanceType: genai.SageMakerInstanceType.ML_G5_8XLARGE,
container: genai.DeepLearningContainerImage.HUGGINGFACE_PYTORCH_INFERENCE_2_1_0_TRANSFORMERS4_37_0_GPU_PY310_CU118_UBUNTU20_04,
modelDataUrl: BUCKET_PATH+'/model.tar.gz',
environment: {
HF_MODEL_ID: HUGGING_FACE_MODEL_ID,
SAGEMAKER_CONTAINER_LOG_LEVEL: "20",
SAGEMAKER_REGION: "us-east-1",
SAGEMAKER_MODEL_SERVER_TIMEOUT: "3600",
TS_MAX_RESPONSE_SIZE: "1000000000",
TS_MAX_REQUEST_SIZE: "1000000000",
MMS_MAX_RESPONSE_SIZE: "1000000000",
MMS_MAX_REQUEST_SIZE: "1000000000",
HF_API_TOKEN: 'XXXXX'
},
endpointName: SG_ENDPOINT_NAME,
startupHealthCheckTimeoutInSeconds: 900,
modelDataDownloadTimeoutInSeconds: 900,
asyncInference: {
maxConcurrentInvocationsPerInstance: 15,
outputPath: BUCKET_PATH+'/output/',
failurePath: BUCKET_PATH+'/failure/'
}
});
this.templateOptions.description= 'Description: (uksb-1tupboc43) (tag:custom-async-endpoint-layer-stack)',
CustomHuggingFaceEndpoint.addToRolePolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
's3:GetObject',
's3:GetObject*',
's3:GetBucket*',
's3:List*',
],
resources: [
`${BUCKET_ARN}`,
`${BUCKET_ARN}/*`,
],
}),
);
NagSuppressions.addResourceSuppressions(
CustomHuggingFaceEndpoint,
[
{
id: 'AwsSolutions-IAM4',
reason: 'Sample SageMaker default endpoint role uses AWS Managed Policy.',
},
{
id: 'AwsSolutions-IAM5',
reason: 'Sample SageMaker default endpoint role uses wildcards for bucket access.',
},
],
true,
);
}
}