vllm.compilation.fix_functionalization
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.
Source code in vllm/compilation/fix_functionalization.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
__call__
¶
__call__(graph: Graph)
Source code in vllm/compilation/fix_functionalization.py
_remove
¶
Stage a node (or nodes) for removal at the end of the pass.
Source code in vllm/compilation/fix_functionalization.py
defunctionalize
¶
defunctionalize(
graph: Graph,
node: Node,
mutated_args: dict[int, Union[Node, str]],
args: Optional[tuple[Union[Node, str], ...]] = 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.
Source code in vllm/compilation/fix_functionalization.py
getitem_users
¶
Returns the operator.getitem users of the auto-functionalized node, indexed by the index they are getting.
Source code in vllm/compilation/fix_functionalization.py
insert_defunctionalized
¶
insert_defunctionalized(
graph: Graph,
node: Node,
args: Optional[tuple[Union[Node, str], ...]] = 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
:param graph: Graph to insert the defunctionalized node into
:param node: The auto-functionalized node to defunctionalize
:param args: If we cannot use kwargs, specify args directly.
If an arg is a string, node.kwargs[arg]
is used.
Source code in vllm/compilation/fix_functionalization.py
replace_users_with_mutated_args
¶
Replace all getitem users of the auto-functionalized node with the
mutated arguments.
:param node: The auto-functionalized node
:param mutated_args: The mutated arguments, indexed by getitem index.
If the value of an arg is a string, node.kwargs[arg]
is used.