##
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 )

Base class for implementing models using ONNX Runtime.

The RyzenAIModel implements generic methods for interacting with the Hugging Face Hub as well as exporting vanilla transformers models to ONNX using `optimum.exporters.onnx` toolchain.

Class attributes:

- model_type (`str`, defaults to `"onnx_model"`) — The name of the model type to use when registering the RyzenAIModel classes.
- auto_model_class (`Type`, defaults to `AutoModel`) — The “AutoModel” class to represented by the current RyzenAIModel class.

Common attributes:

- model (`ort.InferenceSession`) — The ONNX Runtime InferenceSession that is running the model.
- config (`PretrainedConfig` — The configuration of the model.
- model_save_dir (`Path`) — The directory where the model exported to ONNX is saved. By defaults, if the loaded model is local, the directory where the original model will be used. Otherwise, the cache directory is used.
- providers (`List[str]) — The list of execution providers available to 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`

Parameters

- model_id (`Union[str, Path]`) — Can be either:
  - A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a user or organization name, like `dbmdz/bert-base-german-cased`.
  - A path to a directory containing a model saved using `~OptimizedModel.save_pretrained`, e.g., `./my_model_directory/`.
- export (`bool`, defaults to `False`) — Defines whether the provided `model_id` needs to be exported to the targeted format.
- force_download (`bool`, defaults to `True`) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
- use_auth_token (`Optional[Union[bool,str]]`, defaults to `None`) — Deprecated. Please use the `token` argument instead.
- token (`Optional[Union[bool,str]]`, defaults to `None`) — The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated when running `huggingface-cli login` (stored in `huggingface_hub.constants.HF_TOKEN_PATH`).
- cache_dir (`Optional[str]`, defaults to `None`) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
- subfolder (`str`, defaults to `""`) — In case the relevant files are located inside a subfolder of the model repo either locally or on huggingface.co, you can specify the folder name here.
- config (`Optional[transformers.PretrainedConfig]`, defaults to `None`) — The model configuration.
- local_files_only (`Optional[bool]`, defaults to `False`) — Whether or not to only look at local files (i.e., do not try to download the model).
- trust_remote_code (`bool`, defaults to `False`) — Whether or not to allow for custom code defined on the Hub in their own modeling. This option should only be set to `True` for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine.
- revision (`Optional[str]`, defaults to `None`) — The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git.
- provider (`str`, defaults to `"VitisAIExecutionProvider"`) — ONNX Runtime provider to use for loading the model. See https://onnxruntime.ai/docs/execution-providers/ for possible providers.
- session_options (`Optional[onnxruntime.SessionOptions]`, defaults to `None`), — ONNX Runtime session options to use for loading the model.
- provider_options (`Optional[Dict[str, Any]]`, defaults to `None`) — Provider option dictionaries corresponding to the provider used. See available options for each provider: https://onnxruntime.ai/docs/api/c/group___global.html .
- kwargs (`Dict[str, Any]`) — Will be passed to the underlying model loading methods.

Parameters for decoder models (RyzenAIForSpeechSeq2Seq)

- use_cache (`Optional[bool]`, defaults to `True`) — Whether or not past key/values cache should be used. Defaults to `True`.

Returns

`RyzenAIModel`

The loaded RyzenAIModel model.

Instantiate a pretrained model from a pre-trained model configuration.

####
save_pretrained

< source >

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

Parameters

- save_directory (`Union[str, os.PathLike]`) — Directory to which to save. Will be created if it doesn’t exist.
- push_to_hub (`bool`, optional, defaults to `False`) — Whether or not to push your model to the Hugging Face model hub after saving it.

  Using `push_to_hub=True` will synchronize the repository you are pushing to with `save_directory`, which requires `save_directory` to be a local clone of the repo you are pushing to if it’s an existing folder. Pass along `temp_dir=True` to use a temporary directory instead.

Saves a model and its configuration file to a directory, so that it can be re-loaded using the `from_pretrained` class method.

####
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]

Parameters

- model_path (Union[str, Path]) — Path to the model.
- input_shape_dict (Dict[str, Tuple[int]]) — Input shapes for the model.
- output_shape_dict (Dict[str, Tuple[int]]) — Output shapes for the model.

Returns

Union[str, Path]

Path to the model after updating the input shapes.

Raises

`ValueError`

- `ValueError` — If the model provided has dynamic axes in input/output and no input/output shape is provided.

Propagates the given input shapes on the model’s layers, fixing the input shapes of the model.

###
Computer vision

###
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 )

###
class optimum.amd.ryzenai.RyzenAIModelForSemanticSegmentation

< 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 )

Update on GitHub