Skip to content

vllm.compilation.passes.utility.fix_functionalization

Classes:

FixFunctionalizationPass

Bases: VllmInductorPass

This pass defunctionalizes certain nodes to avoid redundant tensor copies. After this pass, DCE (dead-code elimination) should never be run, as de-functionalized nodes may appear as dead code.

To add new nodes to defunctionalize, add to the if-elif chain in call.

Methods:

_remove(node_or_nodes)

Stage a node (or nodes) for removal at the end of the pass.

defunctionalize(graph, node, mutated_args, args=None)

De-functionalize a node by replacing it with a call to the original. It also replaces the getitem users with the mutated arguments. See replace_users_with_mutated_args and insert_defunctionalized.

getitem_users(node)

Returns the operator.getitem users of the auto-functionalized node, indexed by the index they are getting.

insert_defunctionalized(graph, node, args=None)

Insert a new defunctionalized node into the graph before node. If one of the kwargs is 'out', provide args directly, as node.kwargs cannot be used. See https://github.com/pytorch/pytorch/blob/a00faf440888ffb724bad413f329a49e2b6388e7/torch/_inductor/lowering.py#L351

Parameters:

  • graph

    (Graph) –

    Graph to insert the defunctionalized node into

  • node

    (Node) –

    The auto-functionalized node to defunctionalize

  • args

    (tuple[Node | str, ...] | None, default: None ) –

    If we cannot use kwargs, specify args directly. If an arg is a string, node.kwargs[arg] is used.

replace_users_with_mutated_args(node, mutated_args)

Replace mutated getitem users of the auto-functionalized node with the mutated arguments.

Parameters:

  • node

    (Node) –

    The auto-functionalized node

  • mutated_args

    (dict[int, Node | str]) –

    The mutated arguments, indexed by getitem index. If the value of an arg is a string, node.kwargs[arg] is used.