Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enables piecewise
torch.compile
support for PLaMo2. The compilation is only enabled for attention layers, because enablingtorch.compile
for mamba layers requires a redesign of the mamba cache in upstream vLLM.TODO: add benchmark
Illustration
The compilation result is exemplified using the QK-norm in the Attention layer:
vllm/vllm/model_executor/models/plamo2.py
Lines 422 to 427 in 7bc2e28
This is the timeline of the RMSNorm(Q) and RMSNorm(K) ops:
This is the timeline of the same ops with compilation enabled:
The entries for the QK-norm are between
cutlass::Kernel2
(/triton_tem_fused_mm
) and the one prior toflash::flash_fwd_splitkv_kernel
. Without compilation, an individual kernel is launched for every torch op inside the QK-norm. The launch and memory transaction overhead for these kernels is significantly higher than the actual computation.With compilation, these kernels are fused into a single Triton kernel, which drastically reduces the runtime of the QK-norm.
Example
Example inference script with compilation configuration: https://github.com/pfn-attic/vllm-plamo2-plugin/blob/piecewise-compile/example.py
Output:
By setting
compilation_config=0
in the above script, the compilation can be disabled. I have confirmed that the model outputs are identical with compilation enabled and disabled.Note: This PR depends on/includes the fix in vllm-project#14913.