Optimum 文档

RyzenAI模型

您正在查看 main 版本,该版本需要从源码安装。如果您想要常规的 pip 安装,请查看最新的稳定版本 (v1.24.0)。
Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

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 InferenceSession。
  • 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/
  • 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://runtime.onnx.org.cn/docs/execution-providers/
  • session_options (Optional[onnxruntime.SessionOptions], 默认为 None), — 用于加载模型的 ONNX Runtime 会话选项。
  • provider_options (Optional[Dict[str, Any]], 默认为 None) — 与所用提供程序对应的提供程序选项字典。请参阅每个提供程序的可用选项: https://runtime.onnx.org.cn/docs/api/c/group___global.html
  • kwargs (Dict[str, Any]) — 将传递给底层模型加载方法。

解码器模型(RyzenAIForSpeechSeq2Seq)的参数

  • use_cache (Optional[bool], 默认为 True) — 是否应使用过去的键/值缓存。默认为 True

返回值

RyzenAI模型

加载的 RyzenAIModel 模型。

从预训练模型配置实例化预训练模型。

save_pretrained

< >

( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )

参数

  • save_directory (Union[str, os.PathLike]) — 要保存到的目录。如果目录不存在,则会创建。
  • push_to_hub (bool, optional, defaults to False) — 是否在保存模型后将其推送到 Hugging Face 模型中心。

    使用 push_to_hub=True 将同步您要推送到的仓库和 save_directory,如果 save_directory 是现有文件夹,则需要它是您要推送到的仓库的本地克隆。传递 temp_dir=True 以使用临时目录。

将模型及其配置文件保存到目录中,以便可以使用 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]

参数

  • model_path (Union[str, Path]) — 模型的路径。
  • input_shape_dict (Dict[str, Tuple[int]]) — 模型的输入形状。
  • output_shape_dict (Dict[str, Tuple[int]]) — 模型的输出形状。

返回值

Union[str, Path]

更新输入形状后模型的路径。

Raises

ValueError

  • ValueError — 如果提供的模型在输入/输出中具有动态轴,并且未提供输入/输出形状,则会引发此错误。

在模型的层上传播给定的输入形状,固定模型的输入形状。

计算机视觉

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 )

Custom Tasks

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 )

< > Update on GitHub