fix offline batch chunked prefill - #96
Conversation
📝 WalkthroughWalkthroughPrefill execution now derives an effective token budget from runtime settings, uses chunked dispatch when prompts exceed that budget, and adds a configurable long-prefill threshold. Qwen warmup and batching tests apply and validate the same budgeting behavior. The ChangesPrefill Budgeting
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a chunked prefill mechanism to handle offline batches within an effective token budget, adding a long_prefill_token_threshold configuration parameter and updating the NPU runner warmup logic and unit tests accordingly. Feedback on the changes suggests optimizing the chunked prefill implementation to co-schedule chunks from multiple requests for better NPU utilization, avoiding redundant greedy sampling on intermediate chunks, and simplifying the tensor stacking logic.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
2ffea2a to
580027c
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/test_batching.py (1)
59-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the prompt slices too. The batching checks only track positions, so a chunk from the wrong request can still pass. Add
token_idsassertions for the recordedPrefillBatchrows in both batching tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_batching.py` around lines 59 - 61, Update both batching tests to assert the token_ids values on each recorded PrefillBatch row, not just positional fields. Use the expected encoded prompt slices from _CharacterTokenizer so chunks from an incorrect request cannot pass, while preserving the existing position assertions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/model/qwen3_14b/runner/npu_runner.py`:
- Around line 397-405: The token-budget calculation around effective_budget,
step_tokens, and per_req must not dispatch more than the configured budget when
0 < effective_budget < batch. Reject this configuration or reduce the active
rows during warmup so total_tokens never exceeds effective_budget, and add a
regression test covering batch=4 with a threshold of 2.
In `@pypto-lib`:
- Line 1: Update the pypto-lib submodule pointer from the unreachable revision
4ee8cf44e4af815ba8cc15c0486ad8edfe73b1af to a commit that is published and
fetchable from the submodule’s remote repository.
In `@python/core/engine.py`:
- Around line 231-245: Update the prefill flow around _run_prefill_in_chunks so
an in-budget batch continues through batched prefill when try_generate_batch
returns None, rather than being reduced to one row. Use chunking only when the
total prompt token count exceeds prefill_token_budget, and apply the same
behavior at the corresponding later flow.
---
Nitpick comments:
In `@tests/test_batching.py`:
- Around line 59-61: Update both batching tests to assert the token_ids values
on each recorded PrefillBatch row, not just positional fields. Use the expected
encoded prompt slices from _CharacterTokenizer so chunks from an incorrect
request cannot pass, while preserving the existing position assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bb45bfb6-ca4f-4e79-bc88-de3ad6e2c904
📒 Files selected for processing (5)
examples/model/qwen3_14b/runner/npu_runner.pypypto-libpython/core/engine.pypython/core/types.pytests/test_batching.py
580027c to
3868c7b
Compare
|
Review follow-up completed locally:
Validation:
The one deselected test reads the unavailable local checkout of the |
Apply the effective prefill token budget to offline batch generation instead of dispatching the entire prompt batch at once. Preserve normal batched prefill when the full input fits the budget, and process over-budget long prefills one request at a time in round-robin order while retaining absolute positions, cumulative sequence lengths, and KV allocations. Keep Qwen warmup within the same safety threshold, avoid device sampling on intermediate chunks, and cover host- and device-embedding chunk paths with batching tests. The issue hw-native-sys#91 workload completes prefill and 20-token decode without the AICPU 507018 failure.
3868c7b to
2bca273
Compare
|
Correction to my previous validation note: both |
Summary
LLMEngine.generate_batchprefillinput_embeddingsisNoneRoot cause
The offline batch path built one
PrefillBatchfor all prompts and submitted it through a singlerun_prefillcall.max_num_batched_tokensconstrained warmup but did not constrain the real offline prefill dispatch.With 16 prompts of 3,338 tokens, the old path submitted 53,408 packed tokens at once and failed with AICPU error 507018.
Validation
pre-commit run --all-filescompileallandgit diff --checkpassed2bca273,pypto-lib@306519dc) still reproduces 507018 before decode:Refs #91