Reach current DS4 performance parity on Apple Metal from the Rust execution path #78
Reference in New Issue
Block a user
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?
Goal
Bring DS4Server's Rust-owned Metal execution path to current DS4 performance parity, with particular emphasis on the exact M5 fast paths when DS4Server runs on an M5-class Apple Silicon device.
DS4 remains the behavioral oracle. Device-specific paths must be selected automatically using the same capability and shape gates as DS4: M5 optimizations run only on supported M5 hardware and matching graph shapes, pre-M5 paths remain limited to their supported devices, and every fused operation retains the exact unfused fallback.
Audit evidence
The comparison range is DS4 efdadd41e20134af4f3381e1ed90e96fe4faef6f through 8db89fe083ae4d17c9a2428ccd29803d3ae8f577.
DS4Server already vendors the current native Metal implementation:
The remaining gap is host scheduling. Rust owns the model graph and does not currently bind or call several APIs that current ds4.c uses. The kernels are present but cannot deliver their intended gains while Rust continues to dispatch the older unfused sequence.
Relevant upstream work includes 4893e0c, 4e401a1, 0e125e6, 71d8c2a, b64d3e0, 0e8fb54, e6a6ab5, 0ad494e, and 42033ee. The implementation must recheck the final upstream range before coding rather than treating this list as exhaustive.
Phase 1: freeze the comparison and establish an M5 baseline
The benchmark format should be compatible with DS4's speed benchmark so results can be compared directly rather than inferred from whole-turn UI timing.
Phase 2: bind device policy and exact decode fusions
Add the smallest missing Rust FFI surface and mirror current DS4 eligibility rules for:
Port the scheduling in dependency order:
Preserve DS4's precise guards for model shape, tensor type, quality mode, SSD mode, tensor parallelism, retained outputs, and device generation. A fused function returning unavailable or failure must execute the established unfused path without changing tokens, state, or cache accounting. Do not add a user-facing preference or enable an M5 path merely because its symbol exists.
The already-ported Q-head normalization plus RoPE fusion must be verified and reused, not implemented a second time.
Phase 3: streamed experts and prefill
Phase 4: remaining applicable runtime gains
Port the GLM live-prefix rewind from 7694112: when a shorter incoming GLM prompt exactly matches the live token prefix, rewind to prompt_len - 1 and reevaluate the final prompt token instead of rebuilding the complete prompt.
Verify rather than reimplement the already-present behavior that keeps successfully loaded disk KV checkpoints. Delete only invalid checkpoints according to the existing policy.
Phase 5: correctness and performance gates
Add focused coverage for:
Add a release performance gate based on the Phase 1 harness. It must compare like for like and retain the raw run data.
Acceptance criteria
Non-goals
Implemented and pushed in
1ac559b(Reach DS4 Metal performance parity).Implementation:
Parity and performance on Mac17,7 / Apple M5 Max:
Commit gates passed after the final test change:
The resident and SSD three-run release performance gates also pass with five-second cooldowns and frozen DS4/baseline thresholds.