kitty528 commited on
Commit
81f799f
·
verified ·
1 Parent(s): 8ec3f88

Create deploy.py

Browse files
Files changed (1) hide show
  1. deploy.py +31 -0
deploy.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sagemaker
2
+ import boto3
3
+ from sagemaker.huggingface import HuggingFaceModel
4
+
5
+ try:
6
+ role = sagemaker.get_execution_role()
7
+ except ValueError:
8
+ iam = boto3.client('iam')
9
+ role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn']
10
+
11
+ # Hub Model configuration. https://huggingface.co/models
12
+ hub = {
13
+ 'HF_MODEL_ID':'kitty528/article-to-song',
14
+ 'HF_TASK':'undefined'
15
+ }
16
+
17
+ # create Hugging Face Model Class
18
+ huggingface_model = HuggingFaceModel(
19
+ transformers_version='4.26.0',
20
+ pytorch_version='1.13.1',
21
+ py_version='py39',
22
+ env=hub,
23
+ role=role,
24
+ )
25
+
26
+ # deploy model to SageMaker Inference
27
+ predictor = huggingface_model.deploy(
28
+ initial_instance_count=1, # number of instances
29
+ instance_type='ml.m5.xlarge' # ec2 instance type
30
+ )
31
+