vllm.compilation.caching
¶
Classes:
-
StandaloneCompiledArtifacts–Storage for standalone compiled artifacts with content-based deduplication.
-
VllmSerializableFunction–A wrapper around a compiled function by vllm. It will forward the tensor
Functions:
-
compute_env_and_config_hashes–Return the hashed environment factors, config hash, and raw factors.
-
get_code_factors–Per-file factors for the compile cache key, sorted by path.
-
read_code_files–Read traced source files. Files that can't be read map to None.
-
reconstruct_serializable_fn_from_mega_artifact–Construct a VllmSerializableFunction from cached inductor artifacts.
StandaloneCompiledArtifacts
¶
Storage for standalone compiled artifacts with content-based deduplication.
Deduplication works via a two-level indirection:
1. submodule_bytes maps "{submod_name}_{shape}" -> SHA256 hash
2. submodule_bytes_store maps SHA256 hash -> actual bytes
When inserting, we compute the SHA256 hash of the bytes. If the hash
already exists in submodule_bytes_store, we reuse the existing entry
rather than storing duplicate bytes. This is common because submodules
often compile to identical artifacts (e.g., identical transformer layers
split on attn)
VllmSerializableFunction
¶
Bases: SerializableCallable
A wrapper around a compiled function by vllm. It will forward the tensor inputs to the compiled function and return the result. It also implements a serialization interface to support PyTorch's precompile with custom backend, so that we can save and load the compiled function on disk. There's no need to wrap around the compiled function if we don't want to serialize them in particular cases. Right now serialization for the custom backend is done via serializing the Dynamo fx graph plus example inputs.
Methods:
-
finalize_loading–Eagerly initialize the compiled backend and perform all loading.
Attributes:
compute_env_and_config_hashes(vllm_config)
¶
Return the hashed environment factors, config hash, and raw factors. Both AOT and JIT cache paths rely on this helper to ensure their cache keys stay in sync.
get_code_factors(contents)
¶
Per-file factors for the compile cache key, sorted by path.
read_code_files(files)
¶
Read traced source files. Files that can't be read map to None.
reconstruct_serializable_fn_from_mega_artifact(state, standalone_compile_artifacts, vllm_config, sym_shape_indices_map, returns_tuple_map, fake_mode)
¶
Construct a VllmSerializableFunction from cached inductor artifacts.
This function reconstructs a callable model from pre-compiled inductor artifacts without re-running the compilation. It: 1. Loads all cached artifacts 2. Builds compiled callables for each submodule/shape 3. Creates PiecewiseBackend instances that dispatch to cached artifacts 4. Wraps with cudagraph if needed 5. Returns the final VllmSerializableFunction
Note: This function shares similar logic with PiecewiseCompileInterpreter in backends.py. Both create PiecewiseBackend instances and wrap them with cudagraph. The key difference is: - this function: PiecewiseBackend receives pre-compiled runnables (compiled_runnables is set, graph is None) - PiecewiseCompileInterpreter: PiecewiseBackend receives the FX graph to compile (graph is set, compiled_runnables is None)
If modifying the backend creation/wrapping logic, consider updating both.
Parameters:
-
(fake_mode¶FakeTensorMode) –FakeTensorMode used to unpickle the cached graph.
-
(state¶dict[str, Any]) –Deserialized state dict containing graph_module, example_inputs, prefix, is_encoder, etc.
-
(standalone_compile_artifacts¶StandaloneCompiledArtifacts) –The StandaloneCompiledArtifacts containing pre-compiled artifacts for each submodule/shape combination.
-
(vllm_config¶VllmConfig) –The vLLM configuration.
-
(sym_shape_indices_map¶dict[str, list[int]]) –Mapping from submod_name to sym_shape_indices.
-
(returns_tuple_map¶dict[str, bool]) –Mapping from submod_name to returns_tuple.
Returns:
-
VllmSerializableFunction–A VllmSerializableFunction that can be called directly.