Optimum 文件
RyzenAI模型
並獲得增強的文件體驗
開始使用
RyzenAIModel
class optimum.amd.ryzenai.RyzenAIModel
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )
使用 ONNX Runtime 實現模型的基礎類。
RyzenAIModel 實現了與 Hugging Face Hub 互動的通用方法,以及使用 `optimum.exporters.onnx` 工具鏈將普通 transformers 模型匯出到 ONNX。
類屬性
- model_type (
str, 預設為"onnx_model") — 註冊 RyzenAIModel 類時要使用的模型型別名稱。 - auto_model_class (
Type, 預設為AutoModel) — 當前 RyzenAIModel 類所代表的“AutoModel”類。
通用屬性
- model (
ort.InferenceSession) — 執行模型的 ONNX Runtime 推理會話。 - config (PretrainedConfig — 模型的配置。
- model_save_dir (
Path) — 匯出到 ONNX 的模型儲存的目錄。預設情況下,如果載入的模型是本地的,則使用原始模型所在的目錄。否則,使用快取目錄。 - providers (`List[str]) — ONNX Runtime 可用的執行提供程式列表。
from_pretrained
< 來源 >( model_id: typing.Union[str, pathlib.Path] vaip_config: str = None export: bool = False force_download: bool = False use_auth_token: typing.Optional[str] = None cache_dir: typing.Optional[str] = None subfolder: str = '' config: typing.Optional[transformers.configuration_utils.PretrainedConfig] = None local_files_only: bool = False provider: str = 'VitisAIExecutionProvider' session_options: typing.Optional[onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions] = None provider_options: typing.Optional[typing.Dict[str, typing.Any]] = None trust_remote_code: bool = False revision: typing.Optional[str] = None library_name: typing.Optional[typing.Dict[str, typing.Any]] = None **kwargs ) → RyzenAIModel
引數
- model_id (
Union[str, Path]) — 可以是:- 一個字串,即託管在 huggingface.co 上模型倉庫中的預訓練模型的模型 ID。有效的模型 ID 可以是根級別的,如
bert-base-uncased,也可以是使用者或組織名稱下的名稱空間,如dbmdz/bert-base-german-cased。 - 一個目錄的路徑,包含使用
~OptimizedModel.save_pretrained儲存的模型,例如./my_model_directory/。
- 一個字串,即託管在 huggingface.co 上模型倉庫中的預訓練模型的模型 ID。有效的模型 ID 可以是根級別的,如
- export (
bool, 預設為False) — 定義提供的model_id是否需要匯出到目標格式。 - force_download (
bool, 預設為True) — 是否強制(重新)下載模型權重和配置檔案,如果快取版本存在則覆蓋。 - use_auth_token (
Optional[Union[bool,str]], 預設為None) — 已棄用。請改用token引數。 - token (
Optional[Union[bool,str]], 預設為None) — 用作遠端檔案 HTTP bearer 授權的令牌。如果為True,將使用執行huggingface-cli login時生成的令牌(儲存在huggingface_hub.constants.HF_TOKEN_PATH中)。 - cache_dir (
Optional[str], 預設為None) — 如果不應使用標準快取,則下載的預訓練模型配置應快取到的目錄路徑。 - subfolder (
str, 預設為"") — 如果相關檔案位於模型倉庫的子資料夾中(本地或 huggingface.co 上),您可以在此處指定資料夾名稱。 - config (
Optional[transformers.PretrainedConfig], 預設為None) — 模型配置。 - local_files_only (
Optional[bool], 預設為False) — 是否只檢視本地檔案(即不嘗試下載模型)。 - trust_remote_code (
bool, 預設為False) — 是否允許 Hub 上自定義模型程式碼。只有對於您信任且已閱讀程式碼的倉庫才應將此選項設定為True,因為它將在您的本地機器上執行 Hub 上存在的程式碼。 - revision (
Optional[str], 預設為None) — 要使用的特定模型版本。它可以是分支名稱、標籤名稱或提交 ID,因為我們使用基於 git 的系統來儲存 huggingface.co 上的模型和其他工件,因此revision可以是 git 允許的任何識別符號。 - provider (
str, 預設為"VitisAIExecutionProvider") — 用於載入模型的 ONNX Runtime 提供程式。有關可能的提供程式,請參閱 https://onnxruntime.llms.tw/docs/execution-providers/。 - session_options (
Optional[onnxruntime.SessionOptions], 預設為None) — 用於載入模型的 ONNX Runtime 會話選項。 - provider_options (
Optional[Dict[str, Any]], 預設為None) — 與所使用的提供程式對應的提供程式選項字典。有關每個提供程式的可用選項,請參閱:https://onnxruntime.llms.tw/docs/api/c/group___global.html。 - kwargs (
Dict[str, Any]) — 將傳遞給底層模型載入方法。
解碼器模型引數 (RyzenAIForSpeechSeq2Seq)
返回
RyzenAI模型
載入的 RyzenAIModel 模型。
從預訓練模型配置例項化預訓練模型。
save_pretrained
< 來源 >( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )
將模型及其配置檔案儲存到目錄中,以便可以使用 from_pretrained 類方法重新載入。
reshape
< 來源 >( model_path: typing.Union[str, pathlib.Path] input_shape_dict: typing.Dict[str, typing.Tuple[int]] output_shape_dict: typing.Dict[str, typing.Tuple[int]] ) → Union[str, Path]
傳播給定輸入形狀到模型的層,固定模型的輸入形狀。
計算機視覺
class optimum.amd.ryzenai.RyzenAIModelForImageClassification
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )
class optimum.amd.ryzenai.RyzenAIModelForImageToImage
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )
class optimum.amd.ryzenai.RyzenAIModelForObjectDetection
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )
class optimum.amd.ryzenai.RyzenAIModelForSemanticSegmentation
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )
自定義任務
class optimum.amd.ryzenai.RyzenAIModelForCustomTasks
< 來源 >( model: InferenceSession config: PretrainedConfig vaip_config: typing.Union[str, pathlib.Path] = None model_save_dir: typing.Union[str, pathlib.Path, tempfile.TemporaryDirectory, NoneType] = None preprocessors: typing.Optional[typing.List] = None **kwargs )