Repository navigation
[JIT][ROCm] Fully warmup GLM-5.3-Flash #60919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dllehr-amd
merged 22 commits into
vllm-project:main
from
simondanielsson:feature/warmup-glm5next
Nov 4, 2026
+310
−47
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2618f68
fix: warmup kernels
simondanielsson 8eb76c8
Merge branch 'main' into feature/warmup-glm5next
simondanielsson 270a0e9
Merge remote-tracking branch 'upstream/main' into feature/warmup-glm5…
simondanielsson 2c68082
Merge branch 'feature/warmup-glm5next' of github.com:simondanielsson/…
simondanielsson 20b4515
fix: fix speccialization on 2gb+ buffers
simondanielsson 5f772df
fix: add util
simondanielsson 6839d61
fix: improve docstring
simondanielsson 14b373e
chore: simplify another docstring
simondanielsson 67cb695
feat: add regression test
simondanielsson bc08282
fix: set storage_bytes also onthe compressed k and sclae ptrs
simondanielsson 4bd95b5
Merge remote-tracking branch 'upstream/main' into feature/warmup-glm5…
simondanielsson 3af196d
Merge remote-tracking branch 'upstream/main' into feature/warmup-glm5…
simondanielsson 4855236
test: add test that ensures the compile call propagates the ptr range…
simondanielsson 29b1816
fix: only warmup l2norm on triton backend
simondanielsson 51d7cd8
fix: remove change to mla_attention
simondanielsson b187873
Merge branch 'main' into feature/warmup-glm5next
simondanielsson f695581
Merge branch 'main' into feature/warmup-glm5next
simondanielsson 51ecec1
Merge remote-tracking branch 'upstream/main' into feature/warmup-glm5…
simondanielsson 00c873f
fix: make sure tests works even if no modelconfig is none
simondanielsson ec18e93
fix: don't specialize redundantly on alignment for sccalar load pointers
simondanielsson 097a8ef
Merge remote-tracking branch 'upstream/main' into feature/warmup-glm5…
simondanielsson 3beb493
Merge branch 'main' into feature/warmup-glm5next
simondanielsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,16 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| import torch | ||
|
|
||
| from vllm.model_executor.warmup.jit_warmup_triton_helper import ( | ||
| DispatchSpec, | ||
| TritonWarmupTensor, | ||
| triton_kernel_dispatcher_with_warmup, | ||
| triton_ptr_range, | ||
| ) | ||
| from vllm.platforms import current_platform | ||
| from vllm.triton_utils import tl, triton | ||
|
|
||
|
|
@@ -68,7 +76,7 @@ def _hadamard128(x): | |
| # Fused pool compression and cache write. | ||
|
|
||
|
|
||
| @triton.jit | ||
| @triton.jit(do_not_specialize_on_alignment=["loc_ptr"]) | ||
| def _kpool_softmax_rotate_write_cache_kernel( | ||
| buf_fp8_ptr, | ||
| buf_fp32_ptr, | ||
|
|
@@ -191,6 +199,81 @@ def _kpool_softmax_rotate_write_cache_kernel( | |
| tl.store(compressed_scale_ptr + row, scale) | ||
|
|
||
|
|
||
| def _kpool_compress_warmup_inputs( | ||
| *, k_cache, pool_size: int, head_dim: int, round_scale: bool | ||
| ) -> dict[str, Any]: | ||
| kv_cache = k_cache.kv_cache | ||
| page_size = kv_cache.shape[1] | ||
| buf_numel_per_page = kv_cache.stride(0) | ||
| buf_ptr_range_bytes = triton_ptr_range(kv_cache) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This is where the specialization otherwise broke. If not specifying that the buffer it would warmup assuming <2GiB, and at runtime re-compile for >2GiB |
||
| # With return_compressed=False the compressed outputs alias the cache views. | ||
| buf_fp8 = TritonWarmupTensor(FP8_DTYPE, ptr_range_bytes=buf_ptr_range_bytes) | ||
| buf_fp32 = TritonWarmupTensor(torch.float32, ptr_range_bytes=buf_ptr_range_bytes) | ||
| return dict( | ||
| buf_fp8_ptr=buf_fp8, | ||
| buf_fp32_ptr=buf_fp32, | ||
| slot_k_ptr=TritonWarmupTensor(torch.bfloat16, shape=(1, pool_size, head_dim)), | ||
| slot_score_ptr=TritonWarmupTensor( | ||
| torch.bfloat16, shape=(1, pool_size, head_dim) | ||
| ), | ||
| ape_ptr=TritonWarmupTensor(torch.float32, shape=(pool_size, head_dim)), | ||
| loc_ptr=TritonWarmupTensor(torch.int64), | ||
| write_mask_ptr=TritonWarmupTensor(torch.bool), | ||
| compressed_k_ptr=buf_fp8, | ||
| compressed_scale_ptr=buf_fp32, | ||
| page_size=page_size, | ||
| buf_numel_per_page=buf_numel_per_page, | ||
| head_dim=head_dim, | ||
| round_scale=round_scale, | ||
| has_write_mask=True, | ||
| return_compressed=False, | ||
| write_cache=True, | ||
| ) | ||
|
|
||
|
|
||
| @triton_kernel_dispatcher_with_warmup( | ||
| kernel=_kpool_softmax_rotate_write_cache_kernel, | ||
| warmup_inputs=_kpool_compress_warmup_inputs, | ||
| ) | ||
| def kpool_compress_dispatch( | ||
| buf_fp8_ptr, | ||
| buf_fp32_ptr, | ||
| slot_k_ptr, | ||
| slot_score_ptr, | ||
| ape_ptr, | ||
| loc_ptr, | ||
| write_mask_ptr, | ||
| compressed_k_ptr, | ||
| compressed_scale_ptr, | ||
| page_size: int, | ||
| buf_numel_per_page: int, | ||
| head_dim: int, | ||
| round_scale: bool, | ||
| has_write_mask: bool, | ||
| return_compressed: bool, | ||
| write_cache: bool, | ||
| ) -> DispatchSpec: | ||
| return (slot_k_ptr.shape[0],), dict( | ||
| slot_k_stride_0=slot_k_ptr.stride(0), | ||
| slot_k_stride_1=slot_k_ptr.stride(1), | ||
| slot_score_stride_0=slot_score_ptr.stride(0), | ||
| slot_score_stride_1=slot_score_ptr.stride(1), | ||
| ape_stride_0=ape_ptr.stride(0), | ||
| PAGE_SIZE=page_size, | ||
| BUF_NUMEL_PER_PAGE=buf_numel_per_page, | ||
| POOL_SIZE=slot_k_ptr.shape[1], | ||
| HEAD_DIM=head_dim, | ||
| S_OFFSET_NBYTES_IN_PAGE=page_size * head_dim, | ||
| FP8_MAX=FP8_MAX, | ||
| PRESHUFFLE=page_size > 1, | ||
| ROUND_SCALE=round_scale, | ||
| HAS_WRITE_MASK=has_write_mask, | ||
| RETURN_COMPRESSED=return_compressed, | ||
| WRITE_CACHE=write_cache, | ||
| BLOCK_D=triton.next_power_of_2(head_dim), | ||
| ) | ||
|
|
||
|
|
||
| def kpool_compress_and_write_cache( | ||
| kv_cache: torch.Tensor, | ||
| slot_k: torch.Tensor, | ||
|
|
@@ -261,7 +344,6 @@ def kpool_compress_and_write_cache( | |
| buf_fp32 = buf.view(torch.float32) | ||
| # bytes per page (last dim of kv_cache) viewed as uint8 | ||
| buf_numel_per_page = buf.stride(0) | ||
| s_offset_nbytes_in_page = page_size * head_dim | ||
|
|
||
| if return_compressed: | ||
| compressed_k = torch.empty( | ||
|
|
@@ -279,7 +361,7 @@ def kpool_compress_and_write_cache( | |
| if page_size > 1: | ||
| assert page_size % 16 == 0, "ROCm preshuffle requires 16-token tiles" | ||
|
|
||
| _kpool_softmax_rotate_write_cache_kernel[(slot_k.shape[0],)]( | ||
| kpool_compress_dispatch( | ||
| buf_fp8, | ||
| buf_fp32, | ||
| slot_k, | ||
|
|
@@ -289,23 +371,13 @@ def kpool_compress_and_write_cache( | |
| write_mask, | ||
| compressed_k, | ||
| compressed_scale, | ||
| slot_k.stride(0), | ||
| slot_k.stride(1), | ||
| slot_score.stride(0), | ||
| slot_score.stride(1), | ||
| ape.stride(0), | ||
| PAGE_SIZE=page_size, | ||
| BUF_NUMEL_PER_PAGE=buf_numel_per_page, | ||
| POOL_SIZE=slot_k.shape[1], | ||
| HEAD_DIM=head_dim, | ||
| S_OFFSET_NBYTES_IN_PAGE=s_offset_nbytes_in_page, | ||
| FP8_MAX=FP8_MAX, | ||
| PRESHUFFLE=page_size > 1, | ||
| ROUND_SCALE=round_scale, | ||
| HAS_WRITE_MASK=has_write_mask, | ||
| RETURN_COMPRESSED=return_compressed, | ||
| WRITE_CACHE=write_cache, | ||
| BLOCK_D=triton.next_power_of_2(head_dim), | ||
| page_size, | ||
| buf_numel_per_page, | ||
| head_dim, | ||
| round_scale, | ||
| has_write_mask, | ||
| return_compressed, | ||
| write_cache, | ||
| ) | ||
|
|
||
| if return_compressed: | ||
|
|
@@ -316,7 +388,9 @@ def kpool_compress_and_write_cache( | |
| # Seed each request's incomplete pool into its paged tail during prefill. | ||
|
|
||
|
|
||
| @triton.jit | ||
| @triton.jit( | ||
| do_not_specialize=["n_tokens"], do_not_specialize_on_alignment=["tslot_ptr"] | ||
| ) | ||
| def _kpool_tail_seed_kernel( | ||
| key_ptr, | ||
| score_ptr, | ||
|
|
@@ -362,6 +436,56 @@ def _kpool_tail_seed_kernel( | |
| ) | ||
|
|
||
|
|
||
| def _kpool_tail_seed_warmup_inputs( | ||
| *, tail_cache, kpool: int, head_dim: int | ||
| ) -> dict[str, Any]: | ||
| tail_kv_cache = tail_cache.kv_cache | ||
| tail_block_elems = tail_kv_cache.stride(0) | ||
| kpool_head = tail_kv_cache.stride(1) | ||
| ring = tail_kv_cache.shape[2] | ||
| tail_ptr_range_bytes = triton_ptr_range(tail_kv_cache) | ||
| return dict( | ||
| key_ptr=TritonWarmupTensor(torch.bfloat16), | ||
| score_ptr=TritonWarmupTensor(torch.bfloat16), | ||
| tslot_ptr=TritonWarmupTensor(torch.int64), | ||
| tail_ptr=TritonWarmupTensor( | ||
| torch.bfloat16, ptr_range_bytes=tail_ptr_range_bytes | ||
| ), | ||
| n_tokens=1, | ||
| tail_block_elems=tail_block_elems, | ||
| kpool_head=kpool_head, | ||
| head_dim=head_dim, | ||
| kpool=kpool, | ||
| ring=ring, | ||
| ) | ||
|
|
||
|
|
||
| @triton_kernel_dispatcher_with_warmup( | ||
| kernel=_kpool_tail_seed_kernel, | ||
| warmup_inputs=_kpool_tail_seed_warmup_inputs, | ||
| ) | ||
| def kpool_tail_seed_dispatch( | ||
| key_ptr, | ||
| score_ptr, | ||
| tslot_ptr, | ||
| tail_ptr, | ||
| n_tokens: int, | ||
| tail_block_elems: int, | ||
| kpool_head: int, | ||
| head_dim: int, | ||
| kpool: int, | ||
| ring: int, | ||
| ) -> DispatchSpec: | ||
| return (n_tokens,), dict( | ||
| TAIL_BLOCK_ELEMS=tail_block_elems, | ||
| KPOOL_HEAD=kpool_head, | ||
| HEAD_DIM=head_dim, | ||
| KPOOL=kpool, | ||
| RING=ring, | ||
| BLOCK_D=triton.next_power_of_2(head_dim), | ||
| ) | ||
|
|
||
|
|
||
| def kpool_seed_tail_cache( | ||
| tail_kv_cache: torch.Tensor, | ||
| key: torch.Tensor, | ||
|
|
@@ -376,18 +500,17 @@ def kpool_seed_tail_cache( | |
| n = tslot.shape[0] | ||
| if n == 0: | ||
| return | ||
| _kpool_tail_seed_kernel[(n,)]( | ||
| kpool_tail_seed_dispatch( | ||
| key, | ||
| gate_score, | ||
| tslot, | ||
| tail_kv_cache, | ||
| n, | ||
| TAIL_BLOCK_ELEMS=tail_kv_cache.stride(0), | ||
| KPOOL_HEAD=tail_kv_cache.stride(1), | ||
| HEAD_DIM=head_dim, | ||
| KPOOL=kpool, | ||
| RING=tail_kv_cache.shape[2], | ||
| BLOCK_D=triton.next_power_of_2(head_dim), | ||
| tail_kv_cache.stride(0), | ||
| tail_kv_cache.stride(1), | ||
| head_dim, | ||
| kpool, | ||
| tail_kv_cache.shape[2], | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.