Вывод с помощью модели LLava v1.6 Mistral на Amazon SageMakerPython

Программы на Python
Anonymous
Вывод с помощью модели LLava v1.6 Mistral на Amazon SageMaker

Сообщение Anonymous »

Я развернул следующую модель llava-hf/llava-v1.6-mistral-7b-hf в Amazon SageMaker, просто вставив код развертывания с карточки модели (https://huggingface.co/llava-hf/llava- v1.6-mistral-7b-hf). Развертывание, похоже, прошло хорошо, и в том же блокноте в Amazon SageMaker я попытался проверить вывод, используя клиент boto3 и функцию вызова_endpoint (я хочу отправить изображение и попросить модель описать, что находится на изображении). Полный код развертывания и вывода из блокнота Amazon SageMaker выглядит следующим образом:

Код: Выделить всё

# DEPLOYMENT PART:

import sagemaker
import boto3
from sagemaker.huggingface import HuggingFaceModel

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':'llava-hf/llava-v1.6-mistral-7b-hf',
'HF_TASK':'image-text-to-text'
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
transformers_version='4.37.0',
pytorch_version='2.1.0',
py_version='py310',
env=hub,
role=role,
)

# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
initial_instance_count=1, # number of instances
instance_type='ml.p3.2xlarge' # ec2 instance type
)

Код: Выделить всё

# INFERENCE PART:

import json
from PIL import Image
import requests

client = boto3.client('sagemaker-runtime')
endpoint_name = 'huggingface-pytorch-inference-2024-06-22-21-48-42-168'

url = "https://www.ikea.com/pl/pl/images/products/silvtjaern-pojemnik__1150132_pe884373_s5.jpg?f=xl"
image = Image.open(requests.get(url, stream=True).raw)
prompt = "[INST] \nWhat is shown in this image? [/INST]"

payload = json.dumps(prompt)

response = client.invoke_endpoint(
EndpointName=endpoint_name,
ContentType='application/json',
Body=payload
)

result = json.loads(response['Body'].read().decode())
print(result)
Моя цель — вызвать конечную точку для вывода с использованием функции Lambda и API GW за пределами AWS, поэтому я сначала попытался протестировать вывод локально из блокнота SageMaker, но после запуска этого кода вывода У меня в блокноте следующая ошибка:

Код: Выделить всё

ModelError                                Traceback (most recent call last)
Cell In[6], line 3
1 payload = json.dumps(prompt)
----> 3 response = client.invoke_endpoint(
4     EndpointName=endpoint_name,
5     ContentType='application/json',
6     Body=payload
7 )
9 result = json.loads(response['Body'].read().decode())
10 print(result)

File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/botocore/client.py:565, in ClientCreator._create_api_method.._api_call(self, *args, **kwargs)
561     raise TypeError(
562         f"{py_operation_name}() only accepts keyword arguments."
563     )
564 # The "self" in this scope is referring to the BaseClient.
--> 565 return self._make_api_call(operation_name, kwargs)

File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/botocore/client.py:1021, in BaseClient._make_api_call(self, operation_name, api_params)
1017     error_code = error_info.get("QueryErrorCode") or error_info.get(
1018         "Code"
1019     )
1020     error_class = self.exceptions.from_code(error_code)
-> 1021     raise error_class(parsed_response, operation_name)
1022 else:
1023     return parsed_response

ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "{
"code": 400,
"type": "InternalServerException",
"message": "The checkpoint you are trying to load has model type `llava_next` but Transformers does not recognize this architecture.  This could be because of an issue with the checkpoint, or because your version of Transformers is out of date."
Может ли кто-нибудь помочь мне понять, что здесь не так и как на самом деле вызвать эту модель с помощью клиента Lambda и Python boto3?
Я проверил следующую документациюhttps://huggingface.co/llava-hf/llava-v1.6-mistral-7b-hf
https://medium.com/@liltom.eth/deploy-llava-1-5 -on-amazon-sagemaker-168b2efd2489
https://medium.com/@vishaaly/how-to-dep ... a94a58f98c
Как выполнить вывод с помощью Модель Llava Llama развернута в SageMaker из Huggingface?
но подобной проблемы не обнаружено.

Подробнее здесь: https://stackoverflow.com/questions/786 ... -sagemaker

Вернуться в «Python»