.torch_interpreter.diagnose

class experimental_experiment.torch_interpreter.diagnose.ModelDiagnoseOutput(name: str, model: Module, level: int = 0)[source]

Contains inputs and outputs, diagnose results when tracing intermediate results. An instance of this class is produced by infer_shape_type_from_execution(). Example to_onnx, failures Phi-3.5-mini-instruct tells you more about how to use this class.

add_child(diag: ModelDiagnoseOutput)[source]

Adds a submodule.

add_inputs(args: Tuple[Any, ...], kwargs: Dict[str, Any])[source]

Stores used inputs. Makes a copy.

add_outputs(args: Tuple[Any, ...])[source]

Stores returned outputs. Makes a copy.

property dot_name

Returns a kind of indented name.

property full_name

Returns a name and class name.

guess_dynamic_dimensions(*tensors) Any[source]

Infers the dynamic dimension from multiple shapes.

guess_dynamic_shape_object(*objs: Any, msg: Callable | None = None) Any[source]

Guesses the dynamic shapes for one argument.

guess_dynamic_shapes() Any[source]

Guesses the dynamic shapes for that module from two execution. If there is only one execution, then that would be static dimensions.

property module_name_type

Returns name and module type.

pretty_text(with_dynamic_shape: bool = False, with_shape: bool = True, with_min_max: bool = True, with_device: bool = True, with_inputs: bool = True) str[source]

Renders the outputs.

Parameters:
Returns:

text

try_export(exporter: str = 'fx', exporter_kwargs: Dict[str, Any] | None = None, bypass_kwargs: Dict[str, Any] | None = None, verbose: int = 0, quiet: bool = True, discrepancies: bool = True, use_dynamic_shapes: bool | None = None, atol: float = 0.01, rtol: float = 0.1) Any[source]

Tries to export a model. If not possible, tries every child until it is possible. The fucntion stores the export and other results in the class itself.

Parameters:
Returns:

result of the export function

See to_onnx, failures Phi-3.5-mini-instruct for an example.

experimental_experiment.torch_interpreter.diagnose.infer_shape_type_from_execution(model: Module, inputs: List[Tuple[Tuple[Any, ...], Dict[str, Any]]], verbose: int = 0) ModelDiagnoseOutput[source]

Runs a model, traces the intermediate output and infers dynamic shapes based on it.

Parameters:
  • model – model

  • inputs – list of input sets [(args, kwargs), (args, kwargs), ...] with different shapes (at least for the dynamic dimensions)

  • verbose – verbosity

Returns:

see ModelDiagnoseOutput

See to_onnx, failures Phi-3.5-mini-instruct for an example.

experimental_experiment.torch_interpreter.diagnose.make_copy(obj: Any) Any[source]

Makes a copy of the objects.

experimental_experiment.torch_interpreter.diagnose.trace_forward_execution(model: Module, verbose: int = 0) ModelDiagnoseOutput[source]

Replaces all forward to store the inputs and outputs of the module and every submodules. See to_onnx, failures Phi-3.5-mini-instruct for an example.