vllm.model_executor.hw_agnostic.custom_op
¶
Classes:
-
CustomOp–Base class for custom ops.
-
PluggableLayer–Base class for pluggable layers.
CustomOp
¶
Bases: Module
Base class for custom ops. Dispatches the forward method to the appropriate backend.
Methods:
-
default_on–Behavior controlled by
CompilationConfig.custom_ops: On by default if -
forward_native–PyTorch-native implementation; OOT plugins override via
-
maybe_compile–Compile fn if compilation enabled.
Source code in vllm/model_executor/hw_agnostic/custom_op.py
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
default_on()
staticmethod
¶
Behavior controlled by CompilationConfig.custom_ops: On by default if
'all', off by default if 'none'.
When PyTorch Inductor is used, 'none' is the default value,
otherwise 'all'.
Source code in vllm/model_executor/hw_agnostic/custom_op.py
forward_native(*args, **kwargs)
¶
PyTorch-native implementation; OOT plugins override via
:meth:forward_oot.
maybe_compile(fn, *, enable=True)
¶
Compile fn if compilation enabled. Useful for CustomOp instances called from within a torch custom op, meaning the forward call is hidden from the model-level torch.compile.
NOTE: this does not enable fusion across ops, so opaque custom ops should still be unwrapped wherever possible.
Source code in vllm/model_executor/hw_agnostic/custom_op.py
PluggableLayer
¶
Bases: Module
Base class for pluggable layers.
A PluggableLayer is a module-composing abstraction: it may instantiate other
torch.nn.Module objects as sub-layers, and its functionality depends on
these sub-layers following a generalized invocation sequence. Also, it is stateful
and may hold parameters or buffers.
Unlike :class:CustomOp, PluggableLayer does NOT provide per-platform
forward_* dispatch. Instead, it supports out-of-tree (OOT) replacement
of the entire layer class at instantiation time, allowing customized
initialization and submodule composition.
Source code in vllm/model_executor/hw_agnostic/custom_op.py
_class_to_instantiate(cls, name)
¶
The out-of-tree override registered for cls as name, else cls.
The in-tree and the hw-agnostic path keep separate registries, both keyed on the bare class name, so a class can be registered in the hw-agnostic path but not in the in-tree one, and vice versa. This catches the two cases where an override written against the in-tree class would go unnoticed:
- Registered in the hw-agnostic path, but not derived from
cls: Python would skip its__init__, so this raises. - Registered in the in-tree path, but not in the hw-agnostic one: it would never be used, so this warns.