簡體   English   中英

抱臉聖人

[英]Huggingface sagemaker

我正在嘗試使用text2text (翻譯)model facebook/m2m100_418M在 sagemaker 上運行。

因此,如果您單擊部署,然后單擊 sagemaker,則有一些樣板代碼運行良好,但我似乎無法找到如何將它傳遞給 arguments src_lang="en", tgt_lang="fr"就像使用管道或變壓器時一樣. 所以現在它翻譯成隨機語言。

我猜我應該以某種方式將它添加到這里,但沒有記錄在案。

predictor.predict({
    'inputs': "The answer to the universe is"
})

有人知道如何將 arguments 傳遞給預測方法嗎?

編輯

這是您需要更改 HF_TASK 的錯誤代碼:

import sagemaker

role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
    'HF_MODEL_ID':'facebook/m2m100_418M',
    'HF_TASK':'text2text-generation'
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
    transformers_version='4.6.1',
    pytorch_version='1.7.1',
    py_version='py36',
    env=hub,
    role=role, 
)

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

一般來說,對於 Huggingface 模型,傳遞額外 arguments 的方式是使用parameters字典。 在這種情況下:

predictor.predict({'inputs': "The answer to the universe is",
                   'parameters': {'src_lang': 'en', 'tgt_lang' : 'de'}})

# output: [{'translation_text': 'Die Antwort auf das Universum ist'}]

呵呵,有意思。 您能否確認這是您用於部署的代碼?

from sagemaker.huggingface import HuggingFaceModel
import sagemaker

role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
    'HF_MODEL_ID':'facebook/m2m100_418M',
    'HF_TASK':'translation'
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
    transformers_version='4.6.1',
    pytorch_version='1.7.1',
    py_version='py36',
    env=hub,
    role=role, 
)

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

好的,我想通了。 任務錯誤,源語言和目標語言需要在任務中(HF_TASK)

例如: 'HF_TASK': 'translation_en_to_fr'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM