onnx_ir.passes.common¶

Built-in passes provided by the ONNX IR

class onnx_ir.passes.common.AddInitializersToInputsPass[source]¶

Bases: InPlacePass

Add initializers to inputs.

This pass finds all initializers and adds them to the graph.inputs list if they are not already present.

class onnx_ir.passes.common.CheckerPass(full_check: bool = False, skip_opset_compatibility_check: bool = False, check_custom_domain: bool = False)[source]¶

Bases: PassBase

Run onnx checker on the model.

property changes_input: Literal[False]¶

This pass does not change the input model.

property in_place: Literal[True]¶

This pass does not create a new model.

class onnx_ir.passes.common.ClearMetadataAndDocStringPass[source]¶

Bases: InPlacePass

Clear all metadata and docstring from the model, graphs, nodes, and functions.

class onnx_ir.passes.common.InlinePass[source]¶

Bases: InPlacePass

Inline model local functions to the main graph and clear function definitions.

class onnx_ir.passes.common.LiftConstantsToInitializersPass(lift_all_constants: bool = False, size_limit: int = 16)[source]¶

Bases: InPlacePass

Lift constants to initializers.

lift_all_constants¶

Whether to lift all Constant nodes, including those that does not contain a tensor attribute (e.g. with value_ints etc.) Default to False, where only Constants with the value attribute are lifted.

size_limit¶

The minimum size of the tensor to be lifted. If the tensor contains number of elements less than size_limit, it will not be lifted. Default is 16.

class onnx_ir.passes.common.LiftSubgraphInitializersToMainGraphPass[source]¶

Bases: InPlacePass

Lift subgraph initializers to main graph.

This pass lifts the initializers of a subgraph to the main graph. It is used to ensure that the initializers are available in the main graph for further processing or optimization.

Initializers that are also graph inputs will not be lifted.

class onnx_ir.passes.common.RemoveInitializersFromInputsPass[source]¶

Bases: InPlacePass

Remove initializers from inputs.

This pass finds all graph inputs that have a const_value and removes them from the graph.inputs list.

class onnx_ir.passes.common.RemoveUnusedFunctionsPass[source]¶

Bases: InPlacePass

class onnx_ir.passes.common.RemoveUnusedNodesPass[source]¶

Bases: InPlacePass

Pass for removing unused nodes and initializers (dead code elimination).

This pass does not modify the model signature (inputs and outputs). It ensures that unused nodes and initializers are removed while preserving the original contract of the model.

class onnx_ir.passes.common.RemoveUnusedOpsetsPass(process_functions: bool = True)[source]¶

Bases: InPlacePass

Remove unused opset imports from the model and functions.

process_functions¶

Whether to process functions in the model. If True, the pass will remove unused opset imports from functions as well. If False, only the main graph will be processed.

class onnx_ir.passes.common.ShapeInferencePass(check_type: bool = True, strict_mode: bool = True, data_prop: bool = True)[source]¶

Bases: InPlacePass

This pass performs shape inference on the graph.

class onnx_ir.passes.common.TopologicalSortPass[source]¶

Bases: InPlacePass

Topologically sort graphs and functions in a model.