Pandago commited on
Commit
b2960bf
·
verified ·
1 Parent(s): 04d3dec

Create inference.py

Browse files
Files changed (1) hide show
  1. inference.py +30 -0
inference.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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':'Pandago/llama_3.1_infer_pdf',
14
+ 'HF_TASK':'undefined'
15
+ }
16
+
17
+ # create Hugging Face Model Class
18
+ huggingface_model = HuggingFaceModel(
19
+ transformers_version='4.37.0',
20
+ pytorch_version='2.1.0',
21
+ py_version='py310',
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
+ )