Skip to content

Serving/issue 2 chunked prefill - #6

Merged
bhargavchintam merged 3 commits into
bhargavchintam:mainfrom
Aaqibhafeezkhan:serving/issue-2-chunked-prefill
Nov 9, 2026
Merged

bhargavchintam merged 3 commits into
bhargavchintam:mainfrom
Aaqibhafeezkhan:serving/issue-2-chunked-prefill

Conversation

@Aaqibhafeezkhan

@Aaqibhafeezkhan Aaqibhafeezkhan commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a NumPy-based chunked prefill check using multiple chunk sizes.
  • Verify that chunked prefill preserves KV-cache contents and next-token logits compared with full prefill.
  • Interleave decode steps for another request between prefill chunks and report the maximum decode wait in token slots.
  • Document the new check in the README.

Validation

The check compares chunk sizes 1, 2, 4 and 8 against full prefill, asserting numerical equivalence with a tolerance of 1e-10. It reports the maximum error and decode waiting slots for each chunk size.

Closes #2

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified KV-cache and next-token-logit equivalence across four chunk sizes, with decode steps interleaved between chunks and the resulting maximum wait reported.

@Aaqibhafeezkhan

Copy link
Copy Markdown
Contributor Author

Hi @bhargavchintam

Please review/merge

@bhargavchintam bhargavchintam left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, @Aaqibhafeezkhan, and sorry the review took a while. I approved the CI run, and all three jobs (Python 3.10, 3.12 and 3.13) printed 30/30 checks passed (run 40671325140). The new check's line from the 3.10 job:

PASS  serving/chunked_prefill.py           0.12s  max_err=5.55e-17 (chunked KV and next-token logits == full pr…

3.12 and 3.13 printed the same max_err=5.55e-17. The equivalence part is what #2 asked for: K, V, every prefill logit and the logits of the next decode step match a full prefill for chunk sizes 1, 2, 4 and 8.

One change before I merge: the decode wait is printed from min(chunk_size, len(PROMPT)), so the script states the wait instead of measuring it. Could prefill_chunked record how many prompt tokens ran before each interleaved decode step (the end - start of the chunk just before it) and return the largest? Then the script can assert it is at most chunk_size and print it next to the unchunked wait of len(PROMPT) tokens, so the README's "wait falls from 16 to at most 8 token slots" comes from the run like the other rows.

Two small ones, your call:

  • other_logits is computed but never read. Comparing it with the same request decoded on its own would show the interleaving leaves that request unchanged; otherwise it can go.
  • assert len(PROMPT) > max((1, 2, 4, 8)) checks the setup, so it reads better above the loop.

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I've pushed the requested updates in commit 619dd1b.

  • Decode wait is now measured during execution rather than calculated from a formula.
  • Added a comparison against an independently decoded reference to verify interleaving doesn't change the other request's logits.
  • Moved the prompt-length assertion before the loop.

I also updated the README with the measured results. The numerical validation passes locally across all tested chunk sizes.

@bhargavchintam
bhargavchintam merged commit 1daab30 into bhargavchintam:main Nov 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a chunked prefill check

2 participants