Repository navigation
fix(vulkan): reject small HOST_VISIBLE aperture for moe-cache on discrete AMD - #401
Conversation
|
The detection reads right. Taking the largest DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT heap and comparing it to the budget is the correct test for a small BAR aperture, and the force override is a good escape hatch. One blocker. The diff also deletes the queue lock in Smaller:
|
|
Sorry about the noise — the queue-lock drop was accidental (full-file web edit against a local tree missing the newer lock), not intentional. Restored in the follow-up; aperture logic unchanged. Thanks — answering the smaller questions from what we can test here: 1. Slow discrete path / default off 2. True UMA / ReBAR host-mapped log 3. Follow-up commit on this PR: |
|
Follow-up pushed: budget claim + refuse staging for on/auto + thrash guard; queue lock unchanged. Agreed — these are validation axes, not bugs shown by the diff. Short answers from the Polaris farm + current code:
off: ~3.9 tok/s gen (prod ref) on after T6: pools=0, refuse staging, gen ~3.8 (≈ off) 512 opt-in: still not a prod win; thrash guard cuts staging from ~88 GiB to ~2.5 GiB and recovers gen ~3.6 once it trips This follow-up is safety / correctness of defaults, not a tok/s win claim for staging-on-Polaris. Prod remains --moe-cache off. Happy to tighten (1) or (2) in-tree if you prefer before merge; (3) needs hardware we don’t have; (4) already logged above. |
| // Resolve free-minus-reserve (or explicit MiB cap) before GPU setup / | ||
| // pool create. Previously budget_mb==0 bailed here, so --moe-cache on/auto | ||
| // never activated on Vulkan. | ||
| if (!vk_moe_prepare_budget(*session, dev)) { |
There was a problem hiding this comment.
This changes the default. --moe-cache defaults to auto, and vk_moe_query_config returns enabled with budget_mb=0. Before, this function returned here for that case, so auto never did anything on Vulkan. Now vk_moe_prepare_budget turns the cache on for any device whose host-visible heap fits free minus reserve, which covers iGPUs and ReBAR cards. Nobody has run that path. Please keep auto inert on Vulkan in this PR (return when budget_mb == 0 unless ALLOW_STAGING is set) and enable auto in a separate PR with a UMA or ReBAR run.
|
|
||
| vk_moe_revalidate_host_mapped(dev, budget_bytes); | ||
|
|
||
| size_t slots = budget_bytes / expert_size; |
There was a problem hiding this comment.
Every pool is sized from the full budget_bytes (dev.budget_limit). Before, that was the explicit MiB cap. With auto it is free minus reserve, so a second pool (another expert size or wtype) claims the same memory again. Size from dev.budget_limit - dev.allocated_bytes like the CUDA path does (remaining = slab_limit - allocated_bytes in moe-cache.cu), and stop when it drops below moe_cache_pool_slots_min slots.
| return nullptr; | ||
| } | ||
|
|
||
| vk_moe_revalidate_host_mapped(dev, budget_bytes); |
There was a problem hiding this comment.
This call can't change anything today because budget_bytes is dev.budget_limit, which vk_moe_prepare_budget already checked. If it ever did flip host_mapped to false after a host-mapped pool exists, vk_moe_plan would take the staging branch and vkCmdCopyBuffer into a slab created without TRANSFER_DST. Please drop it and decide host_mapped once, in vk_moe_prepare_budget.
| // than they save. Serve hits only for the rest of the session. | ||
| if (!dev.host_mapped && !dev.staging_thrash_stopped && | ||
| pool.free_slots.empty() && | ||
| dev.fills >= 256 && |
There was a problem hiding this comment.
The thrash guard and the staging counters are new cache policy, not part of the aperture fix. dev.fills and dev.evictions are device-wide while pool.free_slots is only the current pool, and once it trips it stays off for the life of the process. Please move this to its own PR with the Polaris numbers so it can be reviewed by itself.
|
Thanks @gaigher for the aperture check. The later commits grew past it, so my comments are about splitting those out. |
Discrete AMD exposes a tiny DEVICE_LOCAL|HOST_VISIBLE heap that was misdetected as UMA, so expert slab alloc failed despite free VRAM. Prefer device-local + staging when UMA heap < budget; allow FORCE_DEVICE_LOCAL.
Restore vk_backend + ggml_backend_vk_lock_queue/unlock accidentally dropped in a73fd8a. Aperture/UMA heap check unchanged. Log notes that device-local+staging is slow on discrete; prefer --moe-cache off.
|
Sorry for the delay getting back to this, and thanks for the clear split guidance — you’re right that the later commits grew past the aperture check. Plan
Re-validated on 6× Polaris before the force-push: Force-pushed the slimmed branch ( |
…heTom#417, TheTom#371, TheTom#401, TheTom#419) # Conflicts: # AGENTS.md # docs/KV-cache-quantization.md # tests/CMakeLists.txt
Summary
failed to allocate ~508 MiBeven with free VRAM.GGML_VK_MOE_CACHE_FORCE_DEVICE_LOCAL=1.Evidence (6× RX 580 8GB, GPT-OSS 120B Q4_K_M, profile S-23)
Before: host-mapped → fail_alloc, pools=0
After:
UMA heap=256 MiB < need=512 MiB; using device-local + staging→ pool 508 MiB, fail_alloc=0, hits≈49%Performance note (correctness-only PR)
Local A/B
@8192×3 on Polaris 8GB:--moe-cache offgen ~3352 tok/s vs--moe-cache 512gen ~369 tok/s (~9× slower; pool thrashing). This PR fixes allocation correctness; it does not claim a production perf win on discrete Polaris — keep--moe-cache offuntil a better cache strategy (VRAM headroom, budget, HOT_USES).Test plan
-DGGML_VULKAN=ON--moe-cache 512on discrete AMD: log shows device-local + staging,session ready,pool[...], no fail_alloc(non testable ici — 6× Polaris discrets seulement ; à valider par un reviewer iGPU/ReBAR)
GGML_VK_MOE_CACHE_FORCE_DEVICE_LOCAL=1forces device-local--moe-cache offvs512on same-ot(regression documented above)Version Française
Résumé
failed to allocate ~508 MiBmalgré de la VRAM libre.GGML_VK_MOE_CACHE_FORCE_DEVICE_LOCAL=1.Preuves (6× RX 580 8 Go, GPT-OSS 120B Q4_K_M, profil S-23)
Avant : host-mapped → fail_alloc, pools=0
Après :
UMA heap=256 MiB < need=512 MiB; using device-local + staging→ pool 508 MiB, fail_alloc=0, hits≈49 %Note perf (PR correctness only)
A/B local
@8192×3 sur Polaris 8 Go :--moe-cache offgen ~3352 tok/s vs--moe-cache 512gen ~369 tok/s (~9× plus lent ; thrashing de pool). Cette PR corrige l’allocation ; elle ne revendique pas un gain perf en prod sur Polaris discret — garder--moe-cache offjusqu’à une meilleure stratégie (marge VRAM, budget, HOT_USES).Plan de test
-DGGML_VULKAN=ON--moe-cache 512sur AMD discret : log device-local + staging,session ready,pool[...], pas de fail_alloc(non testable ici — 6× Polaris discrets seulement ; à valider par un reviewer iGPU/ReBAR)
GGML_VK_MOE_CACHE_FORCE_DEVICE_LOCAL=1force device-local--moe-cache offvs512sur le même-ot(régression documentée ci-dessus)