Optimum 文档

RyzenAI模型

您正在查看的是需要从源码安装. 如果您想进行常规的 pip 安装,请查看最新的稳定版本 (v1.27.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 推理会话。
  • 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, 可选, 默认为 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]

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

引发

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 )

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 )

< > 在 GitHub 上更新