Skip to content

Instantly share code, notes, and snippets.

@ensean
Created March 28, 2024 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ensean/663c19ffa2bdb645eb1b309f9bef1c32 to your computer and use it in GitHub Desktop.
Save ensean/663c19ffa2bdb645eb1b309f9bef1c32 to your computer and use it in GitHub Desktop.
sd
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