Skip to content

vllm.compilation.passes.vllm_inductor_pass

Classes:

Functions:

VllmFusionPatternMatcherPass

Bases: VllmPatternMatcherPass

A VllmPatternMatcherPass for passes that use VllmPatternReplacement objects. Subclasses register patterns via self.register() in their own init.

VllmInductorPass

Bases: InductorPass

An inductor pass with access to vLLM PassConfig. It provides timing, logging, and dumping utilities.

Attributes:

  • dump_prefix (int | None) –

    Keep track of pass index for debug dump ordering.

dump_prefix = None class-attribute

Keep track of pass index for debug dump ordering.

VllmPatternMatcherPass

Bases: VllmInductorPass

A VllmInductorPass that uses the Inductor pattern matcher. Provides pattern registration with match counting, debug dumping, and logging.

Methods:

  • dump_patterns –

    If debug dumping is enabled, dump the Inductor pattern-matcher patterns

Attributes:

match_table = defaultdict(int) class-attribute

Global table mapping pass name to its total match count.

matched_count = 0 class-attribute instance-attribute

The number of matched patterns in the pass.

_replace_op_overloads(string)

Replace with nicer formulations.

dump_patterns(config, pm_pass)

If debug dumping is enabled, dump the Inductor pattern-matcher patterns into the debug_dump_path folder next to the dumped fx graphs.

This method does its best to print something that looks like Python code for easier debugging and potentially navigation. If any errors appear in the output, please add to this method.

TODO(luka): use pattern object to manually produce pattern graph

VllmPatternReplacement

Bases: ABC, Generic[P, R]

A pattern/replacement pair for FX graph fusion.

Implement the three abstract members below, then pass instances to VllmFusionPatternMatcherPass.register(). The pass will find every occurrence of pattern in the graph and substitute it with replacement.

Methods:

  • get_inputs –

    Example tensors used to trace pattern and replacement.

Attributes:

pattern abstractmethod property

Returns a closure defining the FX subgraph to search for.

replacement abstractmethod property

Returns a closure defining the FX subgraph to substitute in place of each match.

get_inputs() abstractmethod

Example tensors used to trace pattern and replacement.

fold_consecutive_reshapes(gm)

Fold consecutive reshape ops into a single reshape.

make_fx faithfully records every view/reshape the Python code performs, so patterns like x.reshape(a, b).reshape(c, d) produce two reshape nodes. Inductor's own optimisation would fold these, but pm.register_replacement's trace_fn runs before Inductor, so we must fold them ourselves for the pattern to match the compiled graph.

When reshape(A, shape1) feeds only into reshape(result, shape2), the first reshape is redundant -- replace with reshape(A, shape2).

get_match_table()

Return a snapshot of the match table.

remove_noop_reshapes(gm)

Drop reshape ops whose output shape equals their input shape.

Companion to fold_consecutive_reshapes. make_fx records a reshape to the shape the input already has; the compiled graph has already dropped it, so the pattern only matches once we drop it too.