Views
No views yet
code/inference.py and code/requirements.txt to provide customize inference script and environment for SageMaker deployment.deploy_llava.ipynb (full tutorial here) , bundle llava model weights and code into a model.tar.gz and upload to S3:1from sagemaker.s3 import S3Uploader
2
3# upload model.tar.gz to s3
4s3_model_uri = S3Uploader.upload(local_path="./model.tar.gz", desired_s3_uri=f"s3://{sess.default_bucket()}/llava-v1.5-13b")
5
6print(f"model uploaded to: {s3_model_uri}")HuggingfaceModel to deploy our real-time inference endpoint on SageMaker:1from sagemaker.huggingface.model import HuggingFaceModel
2
3# create Hugging Face Model Class
4huggingface_model = HuggingFaceModel(
5 model_data=s3_model_uri, # path to your model and script
6 role=role, # iam role with permissions to create an Endpoint
7 transformers_version="4.28.1", # transformers version used
8 pytorch_version="2.0.0", # pytorch version used
9 py_version='py310', # python version used
10 model_server_workers=1
11)
12
13# deploy the endpoint endpoint
14predictor = huggingface_model.deploy(
15 initial_instance_count=1,
16 instance_type="ml.g5.xlarge",
17)conv_mode for llava-1.5 is setup as llava_v1 to process raw_prompt into meaningful prompt. You can also setup conv_mode as raw to directly use raw_prompt.1data = {
2 "image" : 'https://raw.githubusercontent.com/haotian-liu/LLaVA/main/images/llava_logo.png',
3 "question" : "Describe the image and color details.",
4 # "max_new_tokens" : 1024,
5 # "temperature" : 0.2,
6 # "conv_mode" : "llava_v1"
7}
8output = predictor.predict(data)
9print(output)