Skip to main content

hetorch.passes.builtin.utils

Utility transformation passes

Classes

DeadCodeEliminationPass(args, kwargs)

Remove unused nodes from the computation graph

This pass identifies nodes that don't contribute to the output and removes them to simplify the graph.

Methods:

analyze_cost(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> hetorch.backend.cost_model.CostAnalysis

Analyze cost impact of this pass

Args: graph_module: Graph module to analyze context: Compilation context

Returns: Cost analysis result

transform(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> torch.fx.graph_module.GraphModule

Apply dead code elimination

Args: graph_module: Input graph module context: Compilation context

Returns: Transformed graph module with dead code removed

validate(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> bool

Validate preconditions for this pass

Args: graph_module: Graph module to validate context: Compilation context

Returns: True if validation passes, False otherwise

Raises: PassValidationError: If validation fails with detailed message

PrintGraphPass(verbose: <class 'bool'>)

Print graph structure for debugging

This pass doesn't modify the graph, it just prints it for inspection.

Methods:

__init__(self, verbose: bool = False)

Initialize PrintGraphPass

Args: verbose: If True, print detailed node information

analyze_cost(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> hetorch.backend.cost_model.CostAnalysis

Analyze cost impact of this pass

Args: graph_module: Graph module to analyze context: Compilation context

Returns: Cost analysis result

transform(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> torch.fx.graph_module.GraphModule

Print graph and return unchanged

Args: graph_module: Input graph module context: Compilation context

Returns: Unchanged graph module

validate(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> bool

Validate preconditions for this pass

Args: graph_module: Graph module to validate context: Compilation context

Returns: True if validation passes, False otherwise

Raises: PassValidationError: If validation fails with detailed message