onnx_diagnostic.helpers.model_builder_helper

onnx_diagnostic.helpers.model_builder_helper.create_model_builder(config: Any, model: torch.nn.Module, cache_dir: str, precision: str = 'fp32', execution_provider: str = 'cpu', verbose: int = 0, **extra_options) Model[source][source]

Creates a model based on a configuration. The onnx model is returned by function save_model_builder().

Parameters:
  • config – configuration

  • cache_dir – cache directory

  • precision – precision

  • execution_provider – execution provider

  • verbose – verbosity

  • extra_options – extra options

Returns:

model

onnx_diagnostic.helpers.model_builder_helper.download_model_builder_to_cache(url: str = 'https://raw.githubusercontent.com/microsoft/onnxruntime-genai/refs/heads/main/src/python/py/models/builder.py')[source][source]

Downloads builder.py from the https://github.com/microsoft/onnxruntime-genai/blob/main/src/python/py/models/builder.py.

onnx_diagnostic.helpers.model_builder_helper.find_names_pattern(names: List[str]) str[source][source]

Finds a repeatable patterns in a list of names. It tries to locate the figures.

<<<

from onnx_diagnostic.helpers.model_builder_helper import find_names_pattern

pattern = find_names_pattern(["past_key_values_key_0", "past_key_values_key_1"])
print(pattern)

>>>

    past_key_values_key_%d
onnx_diagnostic.helpers.model_builder_helper.import_model_builder(module_name: str = 'builder') object[source][source]

Imports the downloaded model.by.

onnx_diagnostic.helpers.model_builder_helper.make_genai_config(config, onnx_filename: str) Dict[source][source]

Creates genai config file for a model.

Parameters:
  • config – configuration from transformers

  • onnx_filename – onnx configuration

Returns:

configuration

onnx_diagnostic.helpers.model_builder_helper.save_model_builder(self, out_dir: str | None = '', verbose: int = 0) str | ModelProto[source][source]

Saves a model created by function create_model_builder(). If out_dir is empty or not specified, the function still returns the generated model.