• Docs >
  • torch.onnx diagnostics
Shortcuts

torch.onnx diagnostics

Overview

NOTE: This feature is underdevelopment and is subject to change.

The goal is to improve the diagnostics to help users debug and improve their model export to ONNX.

  • The diagnostics are emitted in machine parsable Static Analysis Results Interchange Format (SARIF).

  • A new clearer, structured way to add new and keep track of diagnostic rules.

  • Serve as foundation for more future improvements consuming the diagnostics.

Diagnostic Rules

API Reference

class torch.onnx._internal.diagnostics.ExportDiagnostic(*args, frames_to_skip=1, cpp_stack=False, **kwargs)[source]

Base class for all export diagnostics.

This class is used to represent all export diagnostics. It is a subclass of infra.Diagnostic, and adds additional methods to add more information to the diagnostic.

record_cpp_call_stack(frames_to_skip)[source]

Records the current C++ call stack in the diagnostic.

Return type:

Stack

class torch.onnx._internal.diagnostics.infra.DiagnosticEngine[source]

A generic diagnostic engine based on SARIF.

This class is the main interface for diagnostics. It manages the creation of diagnostic contexts. A DiagnosticContext provides the entry point for recording Diagnostics. See infra.DiagnosticContext for more details.

Examples

Step 1: Create a set of rules. >>> rules = infra.RuleCollection.custom_collection_from_list( … “CustomRuleCollection”, … [ … infra.Rule( … id=”r1”, … name=”rule-1”, … message_default_template=”Mising xxx”, … ), … ], … )

Step 2: Create a diagnostic engine. >>> engine = DiagnosticEngine()

Step 3: Start a new diagnostic context. >>> with engine.create_diagnostic_context(“torch.onnx.export”, version=”1.0”) as context: … …

Step 4: Add diagnostics in your code. … context.diagnose(rules.rule1, infra.Level.ERROR)

Step 5: Afterwards, get the SARIF log. >>> sarif_log = engine.sarif_log()

clear()[source]

Clears all diagnostic contexts.

create_diagnostic_context(name, version, options=None, diagnostic_type=<class 'torch.onnx._internal.diagnostics.infra.engine.Diagnostic'>)[source]

Creates a new diagnostic context.

Parameters:
  • name (str) – The subject name for the diagnostic context.

  • version (str) – The subject version for the diagnostic context.

  • options (Optional[DiagnosticOptions]) – The options for the diagnostic context.

Returns:

A new diagnostic context.

Return type:

DiagnosticContext

dump(file_path, compress=False)[source]

Dumps the SARIF log to a file.

pretty_print(verbose=False, level=Level.ERROR)[source]

Pretty prints all diagnostics in the diagnostic contexts.

Parameters:
  • verbose (bool) – Whether to print the diagnostics in verbose mode. See Diagnostic.pretty_print.

  • level (Level) – The minimum level of diagnostics to print.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources