无法在HuggingFace推理端点上运行模型。

huangapple go评论71阅读模式
英文:

Unable to run a model using HuggingFace Inference Endpoints

问题

我可以使用免费端点成功发出请求,但在使用推理端点时,我收到404响应。以下是相关的代码部分:

mode = 'paid'                                              # 如果是'free'则工作正常
model_id = "sentence-transformers/all-MiniLM-L6-v2"
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}

if mode == 'free':
    # 这个工作正常
    api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
else:
    api_url = f"https://xxxxxxxxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud/{model_id}"

def get_embeddings(texts):
    response = requests.post(api_url, headers=headers, json={"inputs": texts, "options":{"wait_for_model":True}})

在Web界面中,端点显示为正在运行,我可以在那里进行测试,没有问题。

我漏掉了什么?

英文:

I am able to make successful requests using the free endpoint, but when using Inference Endpoints, I get 404 response. Here is the relevant piece of code:

mode = 'paid'                                              # works if 'free'
model_id = "sentence-transformers/all-MiniLM-L6-v2"
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}

if mode == 'free':
    # This works
    api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
else:
    api_url = f"https://xxxxxxxxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud/{model_id}"

def get_embeddings(texts):
    response = requests.post(api_url, headers=headers, json={"inputs": texts, "options":{"wait_for_model":True}})

In the web UI, the endpoint is shown as running and I can test it there no problem.

What am I missing?

答案1

得分: 2

如在评论中提到的:

  1. URL 没有 /{model_id} 终点。
  2. task 部分应根据您的需求正确填写。

在移除 /{model_id} 后,我们遇到了一个 400, list indices must be integers or slices, not str 错误消息。这是由于错误的任务引起的。它不是在获取嵌入向量,而是试图在列表中的字符串之间获取相似性。将任务更改为嵌入向量后,模型成功地从单个字符串生成了嵌入向量。有关涵盖部署过程的详细教程,请参阅 Getting Started with Hugging Face Inference Endpoints

英文:

As mentioned in the comments;

  1. The URL doesn't have a /{model_id} endpoint.
  2. The task section should be filled correctly according to your needs.

After removing the /{model_id}, we faced a 400, list indices must be integers or slices, not str message. Which was caused by the faulty task. Instead of getting the embeddings, it was trying to get the similarities between strings in a list. After changing the task to embeddings, the model successfully generated embeddings from a single string. For a detailed tutorial that covers the deployment process, please see Getting Started with Hugging Face Inference Endpoints .

huangapple
  • 本文由 发表于 2023年8月10日 20:28:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定