mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1439] [CLOSED] perf(prefill): cache immutable BF16-to-FP16 weight conversions #3457
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3457
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1439
Author: @agorevski
Created: 10/7/2026
Status: ❌ Closed
Base:
main← Head:perf/immutable-bf16-conversion-cache📝 Commits (3)
8a9ef1fAdd opt-in persistent immutable BF16 conversion cache819b33dPreserve strided FP16 inputs alongside rebased conversion cachea9274aaSeparate persistent writeback reserve for independent peer composition📊 Changes
8 files changed (+506 additions, -30 deletions)
View changed files
📝
CMakeLists.txt(+10 -0)📝
docs/DETAILS.md(+33 -0)📝
include/strata/prefill/gemm.hpp(+34 -0)📝
include/strata/prefill/prefill.hpp(+3 -0)📝
src/prefill/gemm.cu(+163 -11)📝
src/prefill/gemm_bf16_parity.cu(+226 -4)📝
src/prefill/prefill.cpp(+9 -3)📝
src/program/generate.cpp(+28 -12)📄 Description
Title
Issue: Related context: #1349 and #1910; no issue resolution is claimed.
Opt-in persistent cache for immutable BF16-to-FP16 prompt weights
Summary
Avoid repeated conversion of explicitly immutable BF16 weights on the active CUDA FP16 BF16_TC path.
Rebased onto
origin/mainpinned ata0116b2782a5b82622358c04a06496485d12b2d6.Current head:
a9274aaaa2423de9c94b61d8d171041fcf7c1b16.This is independent of other optimization PRs. The existing default is unchanged.
What changed
include/strata/prefill/gemm.hpp,src/prefill/gemm.cu: explicitbf16_immutableAPI,invalidation, statistics and a bounded persistent per-owner conversion arena. Entries use source pointer
and weight shape on the owner's device; first-admitted entries remain until invalidation/destruction.
Full/oversize misses convert per call without evicting retained weights.
low-memory tiling rather than restoring the old implementation. Cached and uncached FP16 activation
conversion respects padded input rows; add a focused packed-versus-strided regression case.
include/strata/prefill/prefill.hpp,src/prefill/prefill.cpp: expose persistent reserve pricing andopt resident immutable model weights into caching. Mutable dequantization scratch, activations and
drafter weights are not cached. Preserve newer source-dependent prefill sizing.
src/program/generate.cpp: reserve the persistent arena independently of loans in skip-if-fits,stage room, automatic/adaptive reserves, explicit/native cache caps, post-writeback and owned-fit checks.
owned_prefill_mib()includes the cache even when buffers are borrowed, alongside estimated/exactowned buffers otherwise. Callers inherit the price without adding it again, including a separately
merged peer-capacity PR. No peer planner or peer-specific header/API is added.
The post-writeback reserve is initialized before the allocation loop via
cache_writeback_reserve;the independent peer PR shares that baseline extraction and replaces the reserve with its full
pending-allocation holdback. Non-peer persistence is preserved, while peer persistence is counted
once through
owned_prefill_mib()rather than added again.src/prefill/gemm_bf16_parity.cu,CMakeLists.txt: configuration parsing, reuse, mutable bypass,shape keys, budget fallback/retention, invalidate/pointer reuse, separate streams, prompt-shape parity,
inactive reservations and strided input checks. Keep default cuBLAS parity.
docs/DETAILS.md: configuration, lifetime, pricing and explicitly historical throughput-neutral evidence.Only exact
STRATA_BF16_TC_CACHE=1enables the cache.STRATA_BF16_TC_CACHE_MIBdefaults to 256 MiB perGemm, accepts 1..65536 MiB, and disables caching with a diagnostic for invalid values. The arena existsonly on the active FP16 BF16_TC path: CUDA Volta by default and Turing with
STRATA_BF16_TC=1;not an RTX 8000 name gate. Native BF16, Pascal FP32 and HIP reserve no arena.
STRATA_BF16_TC=2is only the tests' forced FP16 mode.Each owner has one model lifetime, device and fixed stream, with host-serialized calls. The immutable
source stays allocated and unchanged until invalidation/destruction. Invalidate before mutation, unload
or pointer reuse; invalidation waits for the stream and reuses the arena. Cross-stream uploads require
explicit ordering. The arena is never a loan and competes with expert VRAM. BF16_TC rounding remains
unchanged, not a guarantee of native-BF16 bit identity or cross-library determinism.
Extra Notes
Historical integrated measurements — not rebased benchmarks
2026-10-07, physical GPU 3, RTX 8000 at 260 W, IQ3_S, speculation 4, fixed 19,000 expert slots,
8,192-token prefill. The engine was built from v0.1.40.3 with other local changes integrated.
Three requests per size, 128 output tokens each; median prompt throughput:
321 retained conversions, 5,778 hits. Whole-model throughput was neutral; no speedup is claimed.
Historical evidence:
bench-tc1-result.json,bench-cache1024-result.json,bench-cache1024-engine.login session files. Neither the original isolated branch nor this rebaseproduced these whole-model numbers. Older 5/5 GPU-suite results apply to the older branch, not this head.
Rebase validation (2026-10-12)
Working directory:
/home/algore/.copilot/session-state/a7c2bcbb-4264-4eb2-879d-c71a90285b0b/files/pr-worktrees/bf16-cache.Configure — passed with CUDA 12.4.131, system GCC/G++ 13, tests ON, architecture 75, shared vendor:
Build — passed, both targets; repeated after removal of an unused diagnostic argument:
CPU-only strict configuration parsing — passed, 1/1, repeated after final cleanup:
Single targeted CUDA attempt — passed, 1/1, 0.86 seconds, including the new strided regression,
before the final unused-argument/documentation cleanup; this specific test was not rerun:
The whole GPU command held the exclusive session lock and selected only physical GPU 3.
The host's reported NVML 580.178 driver/library mismatch did not prevent this CUDA runtime test.
No driver/library/environment repair, reboot, model server or power change was attempted.
The remaining tests were subsequently run once (see below); no benchmarks were rerun.
Whitespace — passed:
Logs: session files
rebase-1439-configure.log,rebase-1439-build.log,rebase-1439-final-build.log,rebase-1439-cpu.log,rebase-1439-gpu.log.Old head preserved as
backup/rebase-1439-6a6062f5-20261012T1852.Independent peer composition followup
Followup commit
a9274aaaa2423de9c94b61d8d171041fcf7c1b16changes only three added lines andone replaced line in
src/program/generate.cpp, without importing peer symbols.With peer head
b19c396f84641fe3ee7d30c4e8aa1f234ee2667d, the merged code initializes the baseline,adds persistent cache bytes for non-peer operation, then replaces that result when the peer planner is
active with
peer_primary_reserve. That complete reserve already includes persistence viaowned_prefill_mib(), so it is a replacement, not an additive/double-booked holdback.Only the peer agent modified the separate peer worktree.
Rebuild after the reserve followup — passed, both targets, CUDA 12.4/GCC13/arch75:
Remaining targeted GPU tests — passed, 3/3, 11.88 seconds. Executed once under the exclusive
whole-command GPU3 lock; the GEMM executable was unchanged by the reserve-only followup:
gemm_bf16_parity: passed, default cuBLAS parity, 5.36 seconds.gemm_bf16_cache_shapes: passed, cached-versus-uncached prompt shapes, 5.34 seconds.gemm_bf16_cache_inactive_reserve: passed, inactive path reserves no arena, 1.18 seconds.Across the rebase attempts all five targeted tests passed, not as one combined suite run.
CUDA worked despite the reported NVML mismatch; no driver/library repair was attempted.
Logs:
rebase-1439-compose-build.log,rebase-1439-remaining-gpu.log.Composition — passed, no checkout or actual merge performed:
Merged tree:
e13f01de931eac8550b7ab4d0f800401fe5bbf5f; the merged reserve ordering was inspecteddirectly with
git show. This is a clean composition/code-inspection result, not a combined runtime benchmark.git diff --checkandgit diff a0116b2782a5b82622358c04a06496485d12b2d6 HEAD --check— passed.git status --short— passed, clean. Local scratch directory removed.Related issues
gh issue list --repo Niko1221/Strata --state all --search 'BF16' --limit 30 --json number,title,url,and equivalent searches for
'RTX 8000'and'Turing', were followed by reading #1349 and #1910.#1349 reports Turing BF16_TC and owned/borrowed prefill trade-offs, relevant to cache reserve/lifetime
context. #1910 reports dual-Turing prefill regression and mentions BF16/borrowed-buffer trade-offs;
this throughput-neutral opt-in cache has not been shown to fix it. Neither is a speculative
Resolves.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.