graphsanitizer

Graph sanitization and optimization for ONNX models.

Classes

GraphSanitizer

A class for sanitizing ONNX model graphs, a part of the AutoCast tool.

class GraphSanitizer

Bases: object

A class for sanitizing ONNX model graphs, a part of the AutoCast tool.

__init__(model, min_opset=13)

Initialize GraphSanitizer.

Parameters:
  • model (ModelProto) – ONNX model to sanitize

  • min_opset (int) – minimum opset version to use

Return type:

None

convert_opset(min_opset)

Convert the model to the given opset version.

Parameters:

min_opset (int) – minimum opset version to use

Return type:

None

The method checks all opset imports and converts the model if any are below the minimum version.

find_custom_nodes()

Find custom nodes in the model.

Scans through all nodes in the graph and logs any nodes that use custom operators that are not part of the standard ONNX operator set.

Return type:

None

remove_disconnected_outputs()

Remove disconnected outputs from the model.

Return type:

None

replace_layernorm_pattern()

Detects and replaces LayerNorm operation patterns.

This method scans through the graph looking for sequences of operations that implement LayerNorm functionality and replaces them with the more efficient LayerNormalization operator.

Return type:

None

sanitize()

Sanitize the model graph.

Currently, this finds decomposed LayerNorm patterns and replaces them with a single LayerNormalization operator. Additional functionality may be added in the future.

Return type:

None