Created
March 28, 2024 16:03
-
-
Save ensean/663c19ffa2bdb645eb1b309f9bef1c32 to your computer and use it in GitHub Desktop.
sd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sagemaker | |
import boto3 | |
from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri | |
try: | |
role = sagemaker.get_execution_role() | |
except ValueError: | |
iam = boto3.client('iam') | |
role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn'] | |
# Hub Model configuration. https://huggingface.co/models | |
hub = { | |
'HF_MODEL_ID':'TheBloke/Airoboros-L2-70B-3.1.2-GPTQ', | |
'SM_NUM_GPUS': json.dumps(4), | |
'QUANTIZE': 'gptq' | |
} | |
# create Hugging Face Model Class | |
huggingface_model = HuggingFaceModel( | |
image_uri=get_huggingface_llm_image_uri("huggingface",version="1.4.2"), | |
env=hub, | |
role=role, | |
) | |
# deploy model to SageMaker Inference | |
predictor = huggingface_model.deploy( | |
initial_instance_count=1, | |
instance_type="ml.g5.24xlarge", | |
container_startup_health_check_timeout=300, | |
) | |
# send request | |
predictor.predict({ | |
"inputs": "Hey my name is Julien! How are you?", | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment