[PR #2399] [Engine] allow elastic expert cache and growing K/V on Linux HIP #4026

Open
opened 2026-11-07 15:32:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2399
Author: @i-Vladimir-i
Created: 10/14/2026
Status: 🔄 Open

Base: main ← Head: kvgrow-elastic-v2


📝 Commits (1)

  • ef7aca7 [Codex]: allow elastic expert cache and growing K/V on Linux HIP

📊 Changes

7 files changed (+502 additions, -212 deletions)

View changed files

📝 docs/DETAILS.md (+10 -6)
📝 docs/VRAM_ELASTIC.md (+46 -8)
📝 include/strata/core/vmm.hpp (+12 -1)
📝 src/core/expert_cache.cpp (+25 -158)
📝 src/core/vmm.cpp (+260 -9)
📝 src/program/generate.cpp (+117 -28)
📝 tests/core/vmm_test.cpp (+32 -2)

📄 Description

Problem and result

On Linux HIP, elastic expert-cache resizing is disabled, and --vram-elastic cannot
share the address range used by --kv-grow. This change enables the opt-in HIP path
after a per-device runtime safety probe and lets reserve/return coexist with growing K/V.
The feature remains off by default. Windows HIP remains disabled.

This updates the existing #2399 scope. It does not add the layer-split/per-device API
from #2522. The two proposals still have three textual conflicts and different cache
admission requirements; their combination has not been built or executed.

Approach

Reuse the VMM implementation for segmented and shared-arena caches. On Linux HIP,
check recommended allocation granularity, actual release behavior and the file limit
needed by physical allocations. Fail the probe with a reason and retain the existing
single-allocation path. With both opt-ins, reserve/return takes and refills chunks in
the existing K/V arena without moving the prompt loan. Refilling may select different
experts, so matching capacity alone does not establish matching expert membership.

Validation

Tested on Linux, AMD Radeon AI PRO R9700/gfx1201, official GGML
3cf03257f219afbe7334045ff7c6a06ac68c627d.
Engine base: 9f7d977d220e9fdf2ec53cf2620cdadac1cfb24e; tested candidate tree:
dfa2d887cf852d9c039808287374386399da263e.
The published refresh on 54828c7e differs only in eight upstream sponsor README files;
its feature patch is byte-identical, SHA256
6d2e751f205f598e93c4313cd9ab85b5c8d440f18aceb8b0550f3d06a515935c.
The separate evidence package records command arrays, individual failures/skips and input hashes.

Passed:

  • CPU/HIP/CUDA/SYCL builds for main and candidate. Server suite on each:
    python -B -m unittest discover -s serve -p 'test_*.py' -v, 1450 tests, 17 skips, exit 0.
  • Qualified CPU CTest: 88 passed/5 skipped on each. Full HIP CTest:
    main 211 passed/13 skipped; candidate 212/12, exit 0. The candidate's segmented-cache
    test ran. Numeric PLE and stock upstream MMQ passed; unsupported trellis host types
    are recorded as skipped, not numeric passes.
  • ctest --test-dir "$QUALIFIED_DIR" --output-on-failure --timeout 180 -j1 --output-junit "$XML". Seven disclosed test supports: separate ISA checker,
    private copy-stream warmup binary, explicit PLE arguments and four scratch
    CWD/output/consumer redirects. Inventory, dependencies, timeouts and skip codes
    otherwise preserved; none of these supports enters this PR.
  • UD-IQ4_XS synthetic workload: K/V growth to 24576 cells and trim to 8192;
    native SAVE/RESTORE/checksum and byte-identical round-trip sessions. Main/candidate
    cold, warm and full-restore token IDs/text match; same-regime repeat/restore checks pass.
  • Three reserve8192/return0 cycles: HIP free 8193 MiB, reserved 7705 slots, returned
    10948/10948/10857 slots. Six independent VMM/malloc consumers physically held
    8 GiB; DRM residency and zero model-VRAM shortfall checked. Consumers released
    before generation.
  • Default and forced-off: 12 cross-arm comparisons match. This is the explicit
    deterministic diagnostic profile, not production tuning.
  • Vision: six GPU_PASS cases across static/on-demand placement, image sizes 1024/1536,
    and candidate budgets 4096/2048/1536 MiB. A separate 1024 MiB case recovered text
    service after a resource limit; it is not counted as GPU_PASS.
  • All owned windows restored services. Final health ok/loaded; source/ELF and production
    config/engine/catalog/sampling/service invariants unchanged. Independent readers exit 0.

Failed:

  • Stock CPU ISA checker fails on both main and candidate; separate checker-only
    qualification passes. Original failures are retained.
  • The first native harness attempted three fixture writes in read-only build dirs.
    A new scratch-only revision passed without changing native sources/binaries.
  • Initial evidence export rejected CRLF/LF-only peaks.py bytes. A separate reader,
    qualified by five CPU regressions, verified that conversion and existing mappings
    without overwrite. The original failed postflight remains recorded; GPU was not rerun.
  • Cross-capacity comparisons after shrink/return differ from cold at token offset 80.
    Same-regime restore repeats pass. This does not establish arbitrary-resize parity
    or prove a restore defect; expert membership was not instrumented.

Not run:

Local Metal build/runtime; NVIDIA, Intel Arc and Windows hardware execution;
combined #2522 multi-GPU; restore with an external 8 GiB allocation still held;
fresh uncached image after idle; increased image-token counts; general quality parity.

Limits

Keep this PR in Draft pending missing backend/hardware checks. CUDA/SYCL compilation
is not hardware execution. Synthetic generations are capped at 96 tokens and end by
length; fixture success is not unrestricted answer-quality acceptance. The diagnostic
profile fixes pcie-frac0, IQ_MT_MIN1, PREFILL_CPU_SHARE0 and adaptation off; a previous
performance-profile baseline failure remains outside this result. Both image sizes
normalize to 1024 image tokens; the idle case reuses cached embeddings. Sampled 250 ms
VRAM peaks are lower bounds, not absolute maxima or separate verify peaks.

Published candidate and evidence

Head ef7aca7cf474e16c4bf49e1cff8c1e4eeb378d83, parent 54828c7efbcdf9474697e70922d851f6707f4b32.

Reconstruct the SHA256-verified evidence ZIP.
ZIP SHA256: 4f795ed12c1091b6d9394c6e4e0935a1e19684d389fb8fa120abee8d9a7b8756. All three public raw files and decoded ZIP were read back exactly.

CI on the updated head

Head ef7aca7cf474e16c4bf49e1cff8c1e4eeb378d83.

Metal CI compiled and linked the engine. It did not execute Metal inference or establish runtime GPU-kernel compilation/correctness. Local Metal hardware and the other Not run items above remain unavailable/unverified.
This PR remains Draft as requested.


🔄 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/2399 **Author:** [@i-Vladimir-i](https://github.com/i-Vladimir-i) **Created:** 10/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `kvgrow-elastic-v2` --- ### 📝 Commits (1) - [`ef7aca7`](https://github.com/Niko1221/Strata/commit/ef7aca7cf474e16c4bf49e1cff8c1e4eeb378d83) [Codex]: allow elastic expert cache and growing K/V on Linux HIP ### 📊 Changes **7 files changed** (+502 additions, -212 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -6) 📝 `docs/VRAM_ELASTIC.md` (+46 -8) 📝 `include/strata/core/vmm.hpp` (+12 -1) 📝 `src/core/expert_cache.cpp` (+25 -158) 📝 `src/core/vmm.cpp` (+260 -9) 📝 `src/program/generate.cpp` (+117 -28) 📝 `tests/core/vmm_test.cpp` (+32 -2) </details> ### 📄 Description ## Problem and result On Linux HIP, elastic expert-cache resizing is disabled, and `--vram-elastic` cannot share the address range used by `--kv-grow`. This change enables the opt-in HIP path after a per-device runtime safety probe and lets reserve/return coexist with growing K/V. The feature remains off by default. Windows HIP remains disabled. ## Related discussion This updates the existing #2399 scope. It does not add the layer-split/per-device API from #2522. The two proposals still have three textual conflicts and different cache admission requirements; their combination has not been built or executed. ## Approach Reuse the VMM implementation for segmented and shared-arena caches. On Linux HIP, check recommended allocation granularity, actual release behavior and the file limit needed by physical allocations. Fail the probe with a reason and retain the existing single-allocation path. With both opt-ins, reserve/return takes and refills chunks in the existing K/V arena without moving the prompt loan. Refilling may select different experts, so matching capacity alone does not establish matching expert membership. ## Validation Tested on Linux, AMD Radeon AI PRO R9700/gfx1201, official GGML `3cf03257f219afbe7334045ff7c6a06ac68c627d`. Engine base: `9f7d977d220e9fdf2ec53cf2620cdadac1cfb24e`; tested candidate tree: `dfa2d887cf852d9c039808287374386399da263e`. The published refresh on `54828c7e` differs only in eight upstream sponsor README files; its feature patch is byte-identical, SHA256 `6d2e751f205f598e93c4313cd9ab85b5c8d440f18aceb8b0550f3d06a515935c`. The separate evidence package records command arrays, individual failures/skips and input hashes. **Passed:** - CPU/HIP/CUDA/SYCL builds for main and candidate. Server suite on each: `python -B -m unittest discover -s serve -p 'test_*.py' -v`, 1450 tests, 17 skips, exit 0. - Qualified CPU CTest: 88 passed/5 skipped on each. Full HIP CTest: main 211 passed/13 skipped; candidate 212/12, exit 0. The candidate's segmented-cache test ran. Numeric PLE and stock upstream MMQ passed; unsupported trellis host types are recorded as skipped, not numeric passes. - `ctest --test-dir "$QUALIFIED_DIR" --output-on-failure --timeout 180 -j1 --output-junit "$XML"`. Seven disclosed test supports: separate ISA checker, private copy-stream warmup binary, explicit PLE arguments and four scratch CWD/output/consumer redirects. Inventory, dependencies, timeouts and skip codes otherwise preserved; none of these supports enters this PR. - UD-IQ4_XS synthetic workload: K/V growth to 24576 cells and trim to 8192; native SAVE/RESTORE/checksum and byte-identical round-trip sessions. Main/candidate cold, warm and full-restore token IDs/text match; same-regime repeat/restore checks pass. - Three reserve8192/return0 cycles: HIP free 8193 MiB, reserved 7705 slots, returned 10948/10948/10857 slots. Six independent VMM/malloc consumers physically held 8 GiB; DRM residency and zero model-VRAM shortfall checked. Consumers released before generation. - Default and forced-off: 12 cross-arm comparisons match. This is the explicit deterministic diagnostic profile, not production tuning. - Vision: six GPU_PASS cases across static/on-demand placement, image sizes 1024/1536, and candidate budgets 4096/2048/1536 MiB. A separate 1024 MiB case recovered text service after a resource limit; it is not counted as GPU_PASS. - All owned windows restored services. Final health ok/loaded; source/ELF and production config/engine/catalog/sampling/service invariants unchanged. Independent readers exit 0. **Failed:** - Stock CPU ISA checker fails on both main and candidate; separate checker-only qualification passes. Original failures are retained. - The first native harness attempted three fixture writes in read-only build dirs. A new scratch-only revision passed without changing native sources/binaries. - Initial evidence export rejected CRLF/LF-only `peaks.py` bytes. A separate reader, qualified by five CPU regressions, verified that conversion and existing mappings without overwrite. The original failed postflight remains recorded; GPU was not rerun. - Cross-capacity comparisons after shrink/return differ from cold at token offset 80. Same-regime restore repeats pass. This does not establish arbitrary-resize parity or prove a restore defect; expert membership was not instrumented. **Not run:** Local Metal build/runtime; NVIDIA, Intel Arc and Windows hardware execution; combined #2522 multi-GPU; restore with an external 8 GiB allocation still held; fresh uncached image after idle; increased image-token counts; general quality parity. ## Limits Keep this PR in Draft pending missing backend/hardware checks. CUDA/SYCL compilation is not hardware execution. Synthetic generations are capped at 96 tokens and end by length; fixture success is not unrestricted answer-quality acceptance. The diagnostic profile fixes pcie-frac0, IQ_MT_MIN1, PREFILL_CPU_SHARE0 and adaptation off; a previous performance-profile baseline failure remains outside this result. Both image sizes normalize to 1024 image tokens; the idle case reuses cached embeddings. Sampled 250 ms VRAM peaks are lower bounds, not absolute maxima or separate verify peaks. ## Published candidate and evidence Head `ef7aca7cf474e16c4bf49e1cff8c1e4eeb378d83`, parent `54828c7efbcdf9474697e70922d851f6707f4b32`. [Reconstruct the SHA256-verified evidence ZIP](https://gist.github.com/i-Vladimir-i/2dfdbaf7e63c94a01020062fe3f5ed2a). ZIP SHA256: `4f795ed12c1091b6d9394c6e4e0935a1e19684d389fb8fa120abee8d9a7b8756`. All three public raw files and decoded ZIP were read back exactly. ## CI on the updated head Head `ef7aca7cf474e16c4bf49e1cff8c1e4eeb378d83`. - [Metal build/link](https://github.com/Niko1221/Strata/actions/runs/42300267325/job/128175911652): passed; the log contains the final engine link. - [Title area](https://github.com/Niko1221/Strata/actions/runs/42300395657/job/128176348570): passed. - [Intake check](https://github.com/Niko1221/Strata/actions/runs/42300396103/job/128176355261): passed. - Intake sweep: skipped by the workflow; no sweep result is claimed. Metal CI compiled and linked the engine. It did not execute Metal inference or establish runtime GPU-kernel compilation/correctness. Local Metal hardware and the other Not run items above remain unavailable/unverified. This PR remains Draft as requested. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4026
No description provided.