vllm.compilation.wrapper ¶
TorchCompileWithNoGuardsWrapper ¶
A wrapper class for torch.compile, it ensures that all guards are dropped when CompilationMode is not CompilationMode.STOCK_TORCH_COMPILE. When guards are dropped, the first time call is invoked, a single compilation is triggered. Dynamo should never be traced again after that since we drop all guards.
Source code in vllm/compilation/wrapper.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
_compiled_callable instance-attribute ¶
_compiled_callable = compile(
forward,
fullgraph=True,
dynamic=False,
backend=backend,
options=options,
)
__call__ ¶
Source code in vllm/compilation/wrapper.py
__init__ ¶
Source code in vllm/compilation/wrapper.py
_dispatch_to_compiled_code ¶
Context manager to dispatch to internally compiled code for torch<2.8. Why does this work? Because Dynamo guarantees that the compiled bytecode has exactly the same arguments, cell variables, and free variables as the original code. Therefore we can directly switch the code object in the function and call it.
See https://dev-discuss.pytorch.org/t/what-is-the-relationship-requirement-among-original-bytecode-transformed-bytecode-and-bytecode-returned-by-hooks-in-dynamo/1693/7 for more details.
Source code in vllm/compilation/wrapper.py
aot_compile ¶
Source code in vllm/compilation/wrapper.py
bytecode_hook ¶
Hook to save the compiled bytecode for direct execution.
Source code in vllm/compilation/wrapper.py
forward abstractmethod ¶
_compilation_context ¶
Context manager for compilation settings and patches.
This manager: 1. Sets higher dynamo cache limits for compilation. (Needed for qwen2_5_vl see test_qwen2_5_vl_evs_functionality). Generally a recompilation can happen whenever we use a new backend instance in torch.compile. 2. Patches out add_global_state_guard to skip GLOBAL_STATE guards 3. Patches out add_torch_function_mode_stack_guard to skip TORCH_FUNCTION_MODE_STACK guards. 4. Restores everything when compilation completes