Repository navigation
[CI]Main2Main 0807 #13477
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
[CI]Main2Main 0807 #13477
Changes from 4 commits
1f5d818
576f8ae
927f691
c4e772f
78a10d9
8186009
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0351e9aa1fdf1a51329d1906881528dfe61fc88e | ||
| 58d3918e3ea0a544ffedadad2ba84559e9c51d8f |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,29 @@ def postprocess_mamba_fused_kernel( | |
| state_inner_sizes_ptr, # number of elements in inner dimensions | ||
| state_conv_widths_ptr, # conv width for conv states (0 for temporal) | ||
| state_group_indices_ptr, # maps state_idx to group index in block table | ||
| # DS conv row metadata. Zero keeps the single-region copy path. | ||
| state_dim_row_count_ptr, # int32: per-block dim row count for DS conv | ||
| state_dim_row_stride_ptr, # int64: bytes between rows for DS conv | ||
| # Output: num_accepted_tokens update (for src==dst case) | ||
| num_accepted_tokens_out_ptr, | ||
| # Optional: batch_idx -> req_idx mapping (V2 model runner / PP). The | ||
| # per-request decision arrays are in req-state-slot order; the block table | ||
| # is in batch order, so HAS_IDX_MAPPING splits the two indexings. | ||
| idx_mapping_ptr, | ||
| # Runtime parameter (varies per batch - NOT constexpr to avoid recompilation) | ||
| num_reqs, | ||
| # Compile-time constants (fixed after model initialization) | ||
| # block_size: determined by model config, constant for all invocations | ||
| block_size: tl.constexpr, | ||
| # COPY_BLOCK_SIZE: fixed tuning parameter for memory copy loop | ||
| COPY_BLOCK_SIZE: tl.constexpr, | ||
| CONV_STATE_DIM_FIRST: tl.constexpr, | ||
| # HAS_IDX_MAPPING: when True, program_id(0) is a batch index resolved to a | ||
| # req-state slot via idx_mapping_ptr (V2). When False, it is the req index. | ||
| HAS_IDX_MAPPING: tl.constexpr = False, | ||
|
Contributor
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. [P1] Preserve the vLLM v0.26.0 output-buffer contract. This Ascend kernel is installed for both main and v0.26.0, but their MRv2 callers have different output contracts. Main (after vLLM #50432) passes an accepted-token snapshot as input and a non-null output buffer. v0.26.0 passes Please either backport the #50432 host-side snapshot/output-buffer flow to the v0.26.0 compatibility patch, or select the write contract explicitly at host/version specialization time. Using one unconditional output-pointer store for both lanes is not compatible.
Collaborator
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. ok |
||
| # PRECOMPUTED_NEW_COMPUTED: when True, num_computed_tokens_ptr already holds | ||
| # the post-step new_num_computed value (V2 supplies the advanced count). | ||
| PRECOMPUTED_NEW_COMPUTED: tl.constexpr = False, | ||
| ): | ||
| """ | ||
| Fused GPU kernel for postprocess_mamba that computes decisions AND performs | ||
|
|
@@ -48,9 +62,14 @@ def postprocess_mamba_fused_kernel( | |
| because the kernel indexes directly into pre-flattened metadata arrays | ||
| using program_id(1). The grid dimensions encode the total state count. | ||
| """ | ||
| req_idx = tl.program_id(0) | ||
| batch_idx = tl.program_id(0) | ||
| state_idx = tl.program_id(1) | ||
|
|
||
| if HAS_IDX_MAPPING: | ||
| req_idx = tl.load(idx_mapping_ptr + batch_idx).to(tl.int32) | ||
|
Contributor
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. [P1] Validate the batch index, not the mapped request slot, against
if batch_idx >= num_reqs:
return
if HAS_IDX_MAPPING:
req_idx = tl.load(idx_mapping_ptr + batch_idx)
if req_idx < 0:
return
else:
req_idx = batch_idxA positive request-slot bound would require the actual buffer capacity, not
Collaborator
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. ok |
||
| else: | ||
| req_idx = batch_idx | ||
|
|
||
| # Bounds check | ||
| if req_idx >= num_reqs: | ||
| return | ||
|
|
@@ -59,13 +78,21 @@ def postprocess_mamba_fused_kernel( | |
| num_accepted = tl.load(num_accepted_tokens_ptr + req_idx) | ||
| src_block_idx = tl.load(mamba_state_idx_ptr + req_idx) | ||
| num_scheduled = tl.load(num_scheduled_tokens_ptr + req_idx) | ||
| num_computed = tl.load(num_computed_tokens_ptr + req_idx) | ||
| num_draft = tl.load(num_draft_tokens_ptr + req_idx) | ||
| if PRECOMPUTED_NEW_COMPUTED: | ||
|
Contributor
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. [P1] Do not load
Collaborator
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. ok |
||
| new_num_computed = tl.load(num_computed_tokens_ptr + req_idx) | ||
| else: | ||
| num_computed = tl.load(num_computed_tokens_ptr + req_idx) | ||
| num_draft = tl.load(num_draft_tokens_ptr + req_idx) | ||
| num_tokens_running_state = num_computed + num_scheduled - num_draft | ||
| new_num_computed = num_tokens_running_state + num_accepted - 1 | ||
|
|
||
| num_tokens_running_state = num_computed + num_scheduled - num_draft | ||
| new_num_computed = num_tokens_running_state + num_accepted - 1 | ||
| aligned_new_computed = (new_num_computed // block_size) * block_size | ||
|
|
||
| if not PRECOMPUTED_NEW_COMPUTED: | ||
| num_tokens_running_state = num_computed + num_scheduled - num_draft | ||
| else: | ||
| num_tokens_running_state = (new_num_computed // block_size) * block_size | ||
|
Contributor
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. [P1] Restore the MRv2 running-state formula. Under new_num_computed = tl.load(num_computed_tokens_ptr + req_idx)
num_tokens_running_state = new_num_computed - num_accepted + 1Please use that formula; otherwise MRv2 align can skip required state shifts or copy at the wrong boundary.
Collaborator
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. ok |
||
|
|
||
| needs_copy = aligned_new_computed >= num_tokens_running_state | ||
|
|
||
| if not needs_copy: | ||
|
|
@@ -91,7 +118,9 @@ def postprocess_mamba_fused_kernel( | |
| # block table). Reinterpret as int32* since block ids are int32. | ||
| group_base_addr = tl.load(block_table_ptrs_ptr + group_idx) | ||
| block_table_typed = group_base_addr.to(tl.pointer_type(tl.int32)) | ||
| block_table_base = block_table_typed + req_idx * block_table_stride_req | ||
|
|
||
| bt_row_idx = batch_idx if HAS_IDX_MAPPING else req_idx | ||
| block_table_base = block_table_typed + bt_row_idx * block_table_stride_req | ||
|
|
||
| # Widen block ids to int64 before they reach `block_id * state_block_stride` | ||
| # below: state_block_stride can exceed 2**31 bytes for large mamba caches, | ||
|
|
@@ -114,8 +143,16 @@ def postprocess_mamba_fused_kernel( | |
| dst_addr = state_base_addr + dest_block_id * state_block_stride | ||
| # Number of elements to copy: | ||
| # (conv_width - accept_token_bias) * inner_size | ||
| num_elems_to_copy = (conv_width - accept_token_bias).to(tl.int64) * state_inner_size | ||
| copy_size = num_elems_to_copy * state_elem_size | ||
| if CONV_STATE_DIM_FIRST: | ||
| dim_row_count = tl.load(state_dim_row_count_ptr + state_idx) | ||
| dim_row_stride = tl.load(state_dim_row_stride_ptr + state_idx) | ||
| num_rows_to_copy = (conv_width - accept_token_bias).to(tl.int64) | ||
| copy_size = dim_row_count * dim_row_stride | ||
|
Contributor
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. [P1] Fix the DS convolution row copy dimensions and advance the row address. For DS layout ( For
Collaborator
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. ok |
||
| num_loops = num_rows_to_copy | ||
| else: | ||
| num_elems_to_copy = (conv_width - accept_token_bias).to(tl.int64) * state_inner_size | ||
| copy_size = num_elems_to_copy * state_elem_size | ||
| num_loops = 1 | ||
| else: | ||
| # Temporal state: copy | ||
| # state[block_table[req_idx, src_block_idx + accept_token_bias]] | ||
|
|
@@ -129,6 +166,7 @@ def postprocess_mamba_fused_kernel( | |
| # state_block_stride which is the page stride and can exceed the | ||
| # actual data when the state tensor uses as_strided page padding. | ||
| copy_size = state_inner_size * state_elem_size | ||
| num_loops = 1 | ||
|
|
||
| # Mirror postprocess_mamba's trailing | ||
| # if src_block_idx == dest_block_idx: num_accepted_tokens_cpu[i] = 1 | ||
|
|
@@ -151,7 +189,8 @@ def postprocess_mamba_fused_kernel( | |
| src_ptr = src_addr.to(tl.pointer_type(tl.uint8)) | ||
| dst_ptr = dst_addr.to(tl.pointer_type(tl.uint8)) | ||
| offsets = tl.arange(0, COPY_BLOCK_SIZE) | ||
| for i in range(0, copy_size, COPY_BLOCK_SIZE): | ||
| mask = (i + offsets) < copy_size | ||
| data = tl.load(src_ptr + i + offsets, mask=mask) | ||
| tl.store(dst_ptr + i + offsets, data, mask=mask) | ||
| for _ in range(num_loops): | ||
| for i in range(0, copy_size, COPY_BLOCK_SIZE): | ||
| mask = (i + offsets) < copy_size | ||
| data = tl.load(src_ptr + i + offsets, mask=mask) | ||
| tl.store(dst_ptr + i + offsets, data, mask=mask) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have the model owner confirm that the modifications are correct and there is no performance degradation.