[PR #1457] [CLOSED] prefill: reuse shared scratch for the HC read #3470

Closed
opened 2026-11-07 14:41:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1457
Author: @W1nge
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: codex/prefill-hc-gate-reuse


📝 Commits (2)

  • efbbb26 prefill: reuse shared scratch for the HC gate
  • 819881c prefill: extend scratch reuse to the complete HC read

📊 Changes

1 file changed (+34 additions, -16 deletions)

View changed files

📝 src/prefill/prefill.cpp (+34 -16)

📄 Description

The HC read's normalized rows, low-rank projections and gate currently retain separate allocations throughout prefill. Reuse the existing attention/MoE scratch region for the complete HC read. A shared take_hc helper supplies both the allocation layout and byte estimate, including the unfused FP32 copy, optional padding and BF16 low parts.

HC reads finish before attention/MoE uses the region on the compute stream. The fused next-half normalization follows those consumers; the existing fusion guard disables it before PLE, which also borrows the region. Persistent residuals, row scales, injection and mixed outputs stay separate. The legacy ring-byte estimate remains conservative.

At T=32768, with default BF16 HC mode and no padding, the removed separate payloads total 1980 MiB (640 MiB normalized rows, 60 MiB low-rank buffers, 1280 MiB gate). Actual savings include allocator rounding and depend on the largest scratch set. No new hardware-specific switch or chunk default.

Validation on RTX 2080 Ti / Windows:

  • Both ordinary and native/MMQ/fused prefill translation units compile.
  • Complete engine builds on current main plus this PR and #1451/#1454/#1455/#1465.
  • Four real-model baseline/integrated pairs pass: default, STRATA_GR_UNFUSED=1, STRATA_PREFILL_BF16X2=1, STRATA_RING_BYTES=0. Each uses IQ3_XXS, INT8 KV, 194 input tokens, chunk 128 (two prompt chunks), and 8 output tokens. All exit successfully with matching output IDs per pair.

These are short combined-regression checks, not isolated speed measurements or exhaustive state/logit equality. Long prompts, control vectors, padding, multi-device and non-CUDA runtime coverage remain outstanding; keep as draft.

Based directly on d5ea713. Independent of the other PRs; integration with #1454 needs the adjacent allocation/count edits combined (already tested locally).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1457 **Author:** [@W1nge](https://github.com/W1nge) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/prefill-hc-gate-reuse` --- ### 📝 Commits (2) - [`efbbb26`](https://github.com/Niko1221/Strata/commit/efbbb26e78fcf0aaa7911206c2fcafe60a1bf343) prefill: reuse shared scratch for the HC gate - [`819881c`](https://github.com/Niko1221/Strata/commit/819881c2093c8c34113294d159f80e574f0a9f4a) prefill: extend scratch reuse to the complete HC read ### 📊 Changes **1 file changed** (+34 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+34 -16) </details> ### 📄 Description The HC read's normalized rows, low-rank projections and gate currently retain separate allocations throughout prefill. Reuse the existing attention/MoE scratch region for the complete HC read. A shared take_hc helper supplies both the allocation layout and byte estimate, including the unfused FP32 copy, optional padding and BF16 low parts. HC reads finish before attention/MoE uses the region on the compute stream. The fused next-half normalization follows those consumers; the existing fusion guard disables it before PLE, which also borrows the region. Persistent residuals, row scales, injection and mixed outputs stay separate. The legacy ring-byte estimate remains conservative. At T=32768, with default BF16 HC mode and no padding, the removed separate payloads total 1980 MiB (640 MiB normalized rows, 60 MiB low-rank buffers, 1280 MiB gate). Actual savings include allocator rounding and depend on the largest scratch set. No new hardware-specific switch or chunk default. Validation on RTX 2080 Ti / Windows: - Both ordinary and native/MMQ/fused prefill translation units compile. - Complete engine builds on current main plus this PR and #1451/#1454/#1455/#1465. - Four real-model baseline/integrated pairs pass: default, STRATA_GR_UNFUSED=1, STRATA_PREFILL_BF16X2=1, STRATA_RING_BYTES=0. Each uses IQ3_XXS, INT8 KV, 194 input tokens, chunk 128 (two prompt chunks), and 8 output tokens. All exit successfully with matching output IDs per pair. These are short combined-regression checks, not isolated speed measurements or exhaustive state/logit equality. Long prompts, control vectors, padding, multi-device and non-CUDA runtime coverage remain outstanding; keep as draft. Based directly on d5ea713. Independent of the other PRs; integration with #1454 needs the adjacent allocation/count edits combined (already tested locally). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:41:42 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3470
No description provided.