Retrieved article excerpt
Open article · Retrieved 2026-11-10T02:21:33.875894+00:00
## Repository navigation
# GLM: opt-in CUDA+HIP expert helper for mixed-vendor GPUs - #879
#879
Open
[RenWuJun](https://github.com/RenWuJun) wants to merge 6 commits into
[mw00:main](https://github.com/mw00/project-maya/tree/main)mw00/project-maya:mainfrom
[RenWuJun:hengha/glm-hip-helper](https://github.com/RenWuJun/project-maya/tree/hengha/glm-hip-helper)RenWuJun/project-maya:hengha/glm-hip-helperCopy head branch name to clipboard
Open
## [GLM: opt-in CUDA+HIP expert helper for mixed-vendor GPUs](https://github.com/mw00/project-maya/pull/879#top)#879 [RenWuJun](https://github.com/RenWuJun) wants to merge 6 commits into [mw00:main](https://github.com/mw00/project-maya/tree/main)mw00/project-maya:mainfrom [RenWuJun:hengha/glm-hip-helper](https://github.com/RenWuJun/project-maya/tree/hengha/glm-hip-helper)RenWuJun/project-maya:hengha/glm-hip-helperCopy head branch name to clipboard
## Conversation
[@RenWuJun](https://github.com/RenWuJun)
### @RenWuJun **[RenWuJun](https://github.com/RenWuJun)** commented [Nov 6, 2026](https://github.com/mw00/project-maya/pull/879#issue-6234010420) • edited Loading Uh oh! There was an error while loading. [Please reload this page](https://github.com/mw00/project-maya/pull/879).
Copy link
Copy Markdown
I’m adding an opt-in HIP expert helper to Maya’s CUDA engine. I wanted to use the RTX 5090 and the Radeon 8060S in my Strix Halo machine together: CUDA keeps attention, dense/shared layers and its expert cache, while a separately compiled HIP module stores and computes complementary GLM experts.
I’ve kept this contribution focused on the existing GLM engine and its expert-helper path. I haven’t added DeepSeek support or a new inference engine.
### Current upstream integration: v1.1.56
I merged upstream main `7bf15ac68f9bb5026bd5298849608c83be4ff6c2` into this branch with a normal merge, preserving the published history. The three conflicts were in `remote_experts.hpp`, `remote_experts.cpp` and `glm_fast_path.cu`: upstream's native EXL3 helper and asynchronous enqueue/wait changes intersected the external helper interface.
I retained native EXL3/overlap behavior and the plugin's synchronous GGUF dispatch. External EXL3 or native `MAYA_GLM_HELPER_OVERLAP=1` requests now fail explicitly before entering native helper CUDA state. Plugin grouped prefill overlap still works. I added a Release dispatch/setup regression to CI and documented this boundary; there is no new plugin ABI, kernel, SDK or default-policy change.
Fresh CUDA engine and separate CUDA/HIP 7.1 modules build on the rig. Ubuntu server tests pass (793, 33 skipped), as do installer/tools tests (783, 39 skipped), HIP mapping, Release dispatch/reader/cost and upstream CPU fixtures. All 108 real-weight Maya-M expert arrays match the previous HIP 7.1 fixture bitwise. At 1025 tokens with FP16 KV and fixed placement, all three static full-model endpoints match exactly. Adaptive sequential logits also match; adaptive batch/repeat KL is 6.01e-7 / 5.17e-7, with unchanged top token but non-identical values (maximum absolute differences 5.62 / 2.44). Real-engine startup correctly rejects plugin + native-helper overlap before plugin allocation. Native multi-CUDA EXL3/overlap hardware execution remains unqualified here.
I reran the unchanged native `maya.py --bench` twice per mode on Maya-M, 96 GiB UMA, context 9216, upstream INT8 KV and automatic CUDA sizing. Same initial expert profile; static max64/share0.25, adaptive max128/share0.25. MTP2 and DFlash use static prefill. All eight runs pass:
| CUDA+HIP configuration | Mean decode tok/s | Mean 2K prefill tok/s | Mean 8K prefill tok/s |
| --- | --- | --- | --- |
| No speculation, static prefill | 45.00 | 330 | 963 |
| No speculation, adaptive prefill | 45.40 | 380.5 | 977.5 |
| Built-in MTP, 2 fixed drafts | 64.35 | 317.5 | 928 |
| DFlash2, up to 4 drafts | 68.90 | 324 | 949.5 |
Individual repeats (decode / 2K / 8K): no-spec 44.6/330/962 and 45.4/330/964; adaptive 45.4/378/979 and 45.4/383/976; MTP2 64.3/320/930 and 64.4/315/926; DFlash 68.8/324/949 and 69.0/324/950. Sampled device-wide CUDA peaks were 31573–31591 MiB (about 30.84–30.85 GiB). CUDA cache slots were stable within each pair: 2773 no-spec/adaptive, 2696 MTP2, 2658 DFlash. Source/static-library/module/loaded-runtime identities were checked; original builds are preserved.
These are small-sample hybrid baseline refreshes, not a new stock CUDA+CPU comparison. I retained the existing pack to isolate runtime changes; upstream's new F32 router-bias packing fix is included in code but repacking was not exercised. Throughput is not broad quality qualification. The v1.1.55 stock comparisons and earlier validation below remain historical.
### Implementation
- Reuse `GlmExpertHelper`, existing CUDA/HIP expert kernels, prefill staging and result combination. A small versioned C ABI passes host data and opaque contexts; allocations, device ordinals and runtime handles stay within their owning runtime.
- Add bounded persistent expert storage, generation-checked uploads/replacement, serialized completion and error propagation. Optional mapped input/result buffers use the helper runtime's own allocation.
- Optional weight readback feeds CUDA prefill. Optional grouped helper execution overlaps a bounded share of expert rows with CUDA work; the tested 25% setting is an admission cap, not a fixed compute-time split. Selected experts and routing weights are preserved.
- Add optional cost-based prefill admission using existing completion events and observed helper/staging costs; keep static admission as the default.
- Include prefill reader lifetime/error-handling fixes, standalone executor fixtures, a Release reader regression in CI, and build/settings documentation. Primary CUDA VRAM sizing remains Maya's native automatic policy.
The plugin, readback and grouped prefill are opt-in. Current scope is Linux, one primary GPU, native GGUF GLM experts with width 4096, intermediate width 2048 and at most eight routes. Unsupported plugin configurations fail explicitly. Windows, EXL3, other model shapes, primary/helper hot-expert exchange are outside this PR. Cost-based prefill admission is an additional opt-in policy described below.
### Setup and launch
I also added `setup-cuda-hip.sh` because ordinary setup selects one engine backend at a time. Maya already keeps ordinary CUDA and HIP builds in separate directories; this script prepares a matched CUDA engine and external HIP executor for one configuration.
On Ubuntu 26.04 x86\_64, the guided entry point is:
```
./setup-cuda-hip.sh
```
It offers missing Ubuntu build dependencies through apt/sudo, installs Python/CMake/Ninja into Maya's private environment, and prompts for the GLM config, HIP device and budget. If no CUDA GLM config exists, it calls normal Maya model setup first. Existing configs can use `--install-deps --yes --config ... --hip-device ... --helper-mib ...` to install dependencies and build sequentially in one command. `--deps-plan` previews missing system packages. Working drivers/device permissions remain prerequisites; no graphics driver or external repository installation is automated. Other Linux systems can use preinstalled dependencies.
The helper budget must fit actual HIP runtime memory; `--check` validates without installing/building, and `--no-start` builds/configures without starting the dashboard. BIOS UMA size alone is not the HIP runtime allocation limit.
- Each setup builds in a fresh `build-cuda-hip/pair-*/` directory, with separate engine/module outputs and a manifest. It preserves ordinary builds and previous pairs, and publishes the new config only after both builds succeed.
- The generated launcher supports normal Maya startup, `--bench` and `--report`. Model/drafter, sampling and serving choices are retained. The Models page labels it **CUDA + HIP**; the live GPU monitor still charts the CUDA primary only.
- Startup verifies source/artifact identities and available HIP memory. A source update requires rebuilding the pair rather than refreshing only CUDA. CUDA and HIP ordinals are kept separate, CPU-lane calibration is skipped, and unsupported dashboard edits are rejected before saving.
I tested the actual bash setup, separate builds and generated launcher on the Ubuntu rig. A one-token HTTP smoke passed with both CUDA and HIP runtimes loaded; old stock/hybrid binaries retained their hashes. The setup correctly rejected the old 90 GiB helper budget after the BIOS change. The dependency follow-up was exercised in a fresh source folder and Python environment using the rig's existing compilers. Missing-package installation is covered by mocked package-manager tests and an actual apt simulation, not a clean-OS install. This is lifecycle validation, not a new performance benchmark.
Build prerequisites and all options: [paired setup guide](https://github.com/RenWuJun/project-maya/blob/06e4c81a387e63382203701b03347213ff550839/docs/EXPERT_PLUGIN.md).
I addressed two preflight review findings: the selected HIP runtime device is matched by PCI identity to KFD/DRM architecture metadata, and its target is selected automatically; an explicit `--hip-arch` must match. Preflight also reads the pack's source GGUF header and checks the helper's supported geometry before compiling. Launch validation repeats these checks. Native gfx1151/Maya-M preflight and existing-pair validation pass, and an explicit gfx1100 mismatch is rejected. These are configuration checks, not new inference performance measurements. Other GPU architectures remain unqualified on hardware. The 38 focused tests also pass on macOS; a broader Mac suite run encountered platform/environment failures, while the full Ubuntu tools suite passes.
### Historical v1.1.55 native benchmark
I benchmarked against upstream main v1.1.55 (`c4effee67cb95fb4303720919b075fddf04b4e69`). Ryzen AI Max+ 395, 128 GB unified RAM, RTX 5090 32 GB over **PCIe 4.0 x4 OCuLink**, Ubuntu, CUDA 13.1 / HIP 7.1. GLM-5.3-Flash-Maya-M IQ2\_S, context 9216, native INT8 KV. Unchanged `maya.py --bench`, greedy/thinking off, three answers up to 256 tokens, native warm-ups, two repeats per mode.
| Configuration | Decode tok/s | 2K prefill tok/s | 8K prefill tok/s |
| --- | --- | --- | --- |
| Stock CUDA+CPU, no speculation | 30.65 | 213.5 | 771.5 |
| CUDA+HIP, no speculation | **45.10** | **332** | **969** |
| Stock CUDA+CPU, built-in MTP2 | 32.95 | 209 | 752.5 |
| CUDA+HIP, built-in MTP2 | **64.85** | **321** | **932.5** |
| Stock CUDA+CPU, DFlash2 up to 4 drafts | 36.80 | 213.5 | 768.5 |
| CUDA+HIP, DFlash2 up to 4 drafts | **69.05** | **321.5** | **954** |
**Comparison limit:** stock used a 4 GiB UMA reservation and 119 GiB host RAM with native CPU/RAM scheduling; hybrid used 96 GiB UMA with CPU expert computation disabled. These are practical configurations with different memory reservations and settings, not a code-only A/B. Both used automatic CUDA cache sizing, the same model/tokenizer/start profile, and identical prefill prompt tokens. Stock CPU work and its native DFlash two-lane verification were active. Sampled peak total CUDA usage was approximately 31.0 GiB stock and 30.84 GiB hybrid. All 12 runs exited successfully.
### Opt-in cost-based prefill admission (v1.1.55 measurements)
I also measured an adaptive policy on the same HIP 7.1 fixture. With `STRATA_GLM_HELPER_COST=1`, the scheduler uses recent helper worker time per row and CUDA staging time per MiB to limit helper admission. It reuses existing CUDA events after the next routing synchronization, without an additional GPU wait. The existing share and result-buffer bounds remain; the estimator and its 15% headroom are heuristics. Static admission remains the default.
This is a separate static-versus-adaptive comparison on the CUDA+HIP implementation: Maya-M, 96 GiB UMA, context 9216, native INT8 KV, automatic CUDA pool, MTP/speculation off, unchanged native `--bench`. The control uses a 64-row per-exper