Repository navigation
[PERF] Eliminate varlen prefill GDN D2H synchronization with reusable metadata - #4532
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces reusable, typed prefill-batch metadata for variable-length Gated Delta Rule (GDR) and causal-conv prefill so chunk schedules (grids/offsets/rebased cu_seqlens) can be computed once and reused across layers/backends, eliminating repeated device→host synchronization in the forward path.
Changes:
- Adds
CausalConvPrefillMetadata/GatedDeltaRulePrefillMetadataand builders in a new sharedaiter/ops/prefill_batch_metadata.py. - Threads
prefill_metadata(or hostseq_lens_cpu) through GDR K1–K6 prologues and updates Triton kernels to consume separate(sequence_ids, chunk_ids)(+ stride) instead of interleaved chunk indices. - Enables causal-conv prefill backends (HIP/Triton/FlyDSL) to reuse prebuilt chunk grids via
CausalConvPrefillMetadata.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| aiter/ops/triton/gated_delta_net/gated_delta_rule.py | Adds optional seq_lens_cpu / prefill_metadata plumbing to the public Triton GDR entrypoint. |
| aiter/ops/triton/gated_delta_net/causal_conv1d_prefill.py | Accepts typed causal-conv metadata and validates/reuses its chunk grid. |
| aiter/ops/triton/gated_delta_net/init.py | Exposes GDR prefill metadata symbols/builders as part of the Triton gated-delta-net namespace. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/utils/solve_tril.py | Refactors varlen indexing inputs to (sequence_ids, chunk_ids, INDEX_STRIDE) and updates the solve wrapper accordingly. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/utils/prefill_metadata.py | Adds compatibility re-exports to the new shared metadata module. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/utils/init.py | Re-exports GDR metadata/builder from utils. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/prefill/fused_solve_tril_recompute.py | Adds prefill_metadata support and switches kernels to the new ID-pointer scheme. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/prefill/fused_cumsum_kkt.py | Adds prefill_metadata support and switches kernels to the new ID-pointer scheme. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/prefill/chunk.py | Builds/validates reusable metadata and threads it through GDR prefill stages and backend selection. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/prefill/chunk_o.py | Adds prefill_metadata support and switches kernels to the new ID-pointer scheme. |
| aiter/ops/triton/_triton_kernels/gated_delta_rule/prefill/chunk_delta_h.py | Adds prefill_metadata support for hidden-state prefill scheduling. |
| aiter/ops/prefill_batch_metadata.py | Introduces shared metadata primitives and eager builders for causal-conv and GDR schedules. |
| aiter/ops/flydsl/linear_attention_prefill_kernels.py | Allows FlyDSL GDR prefill wrapper to consume validated reusable metadata. |
| aiter/ops/flydsl/causal_conv1d_flydsl.py | Enables FlyDSL causal-conv prefill to reuse typed chunk-grid metadata. |
| aiter/ops/chunk_gated_delta_rule_fwd_h.py | Extends HIP GDR hidden-state wrapper to accept/build reusable metadata to avoid GPU readback. |
| aiter/ops/causal_conv1d_fwd_split_qkv.py | Enables HIP causal-conv prefill to reuse typed chunk-grid metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
valarLip
approved these changes
Aug 4, 2026
5 tasks done
huizzhan
added a commit
that referenced
this pull request
Aug 12, 2026
The K5 BV selector needs total_chunks and max_seq_chunks and took them from chunk_offsets.tolist() on every forward. That blocking D2H sits between the K1..K4 launches and K5's, so the host waited for the whole front end to retire and the GPU then idled through the remaining host work for K5 and K6 rather than the host running ahead. The copy itself is 4us; the bubble it opened was 66us of a 738us block. Prefer the host-side counts prebuilt metadata already carries (GatedDeltaRuleChunkSchedule.total_chunks / .max_seq_chunks, derived from seq_lens_cpu). The old call sat outside the prefill_metadata branch, so passing metadata did not avoid the transfer -- the case #4532 missed here. Without metadata, cache the counts on chunk_offsets itself, the same tensor-attribute pattern as _as_int32 and _resolve_prologue: it comes from the tensor_cache'd prologue, so its identity is stable across forwards and the counts cannot change underneath the cache. varlen-64k-qwen-ptpc-ali T=8192 (Hg=2, H=8, packed varlen with state I/O, one 80-CU gfx942): the block goes 738.1us -> 667.5us, its launch gap 66.1 -> 0.7us, and Memcpy DtoH disappears from the profile. The 79 non-perf cases in test_flydsl_linear_attention_prefill.py are unchanged. Co-authored-by: Cursor <[email protected]>
huizzhan
added a commit
that referenced
this pull request
Aug 12, 2026
The K5 BV selector needs total_chunks and max_seq_chunks and took them from chunk_offsets.tolist() on every forward. That blocking D2H sits between the K1..K4 launches and K5's, so the host waited for the whole front end to retire and the GPU then idled through the remaining host work for K5 and K6 rather than the host running ahead. The copy itself is 4us; the bubble it opened was 66us of a 738us block. Prefer the host-side counts prebuilt metadata already carries (GatedDeltaRuleChunkSchedule.total_chunks / .max_seq_chunks, derived from seq_lens_cpu). The old call sat outside the prefill_metadata branch, so passing metadata did not avoid the transfer -- the case #4532 missed here. Without metadata, cache the counts on chunk_offsets itself, the same tensor-attribute pattern as _as_int32 and _resolve_prologue: it comes from the tensor_cache'd prologue, so its identity is stable across forwards and the counts cannot change underneath the cache. varlen-64k-qwen-ptpc-ali T=8192 (Hg=2, H=8, packed varlen with state I/O, one 80-CU gfx942): the block goes 738.1us -> 667.5us, its launch gap 66.1 -> 0.7us, and Memcpy DtoH disappears from the profile. The 79 non-perf cases in test_flydsl_linear_attention_prefill.py are unchanged. Co-authored-by: Cursor <[email protected]> (cherry picked from commit 24b6f80)
3 of 4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Variable-length GDR and causal-conv prefill currently derive chunk counts, launch grids, and sequence offsets from device-side sequence metadata during execution. This introduces blocking device-to-host synchronization in the forward path, and the overhead is repeated across layers processing the same batch.
This change moves the required sequence information outside the latency-sensitive forward path so it can be reused across operators and layers. The goal is to eliminate repeated D2H synchronization while preserving existing outputs, legacy call paths, and mixed decode-prefill behavior.
Technical Details
solve_trilcompatibility.Test Result
HIP and Triton cold D2H events decreased from 1 to 0.
Submission Checklist