Optimum 文档
RyzenAI模型
并获得增强的文档体验
开始使用
RyzenAIModel
class optimum.amd.ryzenai.RyzenAIModel
< source >( 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
< source >( 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://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)的参数
返回值
RyzenAI模型
加载的 RyzenAIModel 模型。
从预训练模型配置实例化预训练模型。
save_pretrained
< source >( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )
将模型及其配置文件保存到目录中,以便可以使用 from_pretrained
类方法重新加载。
reshape
< source >( 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
< source >( 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
< source >( 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
< source >( 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
< source >( 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 )