Shinhati2023 commited on
Commit
a54f869
1 Parent(s): 8959f89

Create Deploy.Py

Browse files
Files changed (1) hide show
  1. Deploy.Py +37 -0
Deploy.Py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sagemaker
3
+ import boto3
4
+ from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
5
+
6
+ try:
7
+ role = sagemaker.get_execution_role()
8
+ except ValueError:
9
+ iam = boto3.client('iam')
10
+ role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn']
11
+
12
+ # Hub Model configuration. https://huggingface.co/models
13
+ hub = {
14
+ 'HF_MODEL_ID':'stabilityai/StableBeluga2',
15
+ 'SM_NUM_GPUS': json.dumps(8)
16
+ }
17
+
18
+
19
+
20
+ # create Hugging Face Model Class
21
+ huggingface_model = HuggingFaceModel(
22
+ image_uri=get_huggingface_llm_image_uri("huggingface",version="1.4.2"),
23
+ env=hub,
24
+ role=role,
25
+ )
26
+
27
+ # deploy model to SageMaker Inference
28
+ predictor = huggingface_model.deploy(
29
+ initial_instance_count=1,
30
+ instance_type="ml.p4d.24xlarge",
31
+ container_startup_health_check_timeout=1500,
32
+ )
33
+
34
+ # send request
35
+ predictor.predict({
36
+ "inputs": "My name is Julien and I like to",
37
+ })