feat(kt): add --kt-skip-gpu-expert-cpu-copy to reclaim host RAM for GPU experts#64
feat(kt): add --kt-skip-gpu-expert-cpu-copy to reclaim host RAM for GPU experts#64gvr13n wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the --kt-skip-gpu-expert-cpu-copy option to skip allocating CPU copies of GPU-resident experts, reclaiming host RAM. The feedback suggests normalizing the method string to uppercase to ensure the case-insensitive comparison works correctly and prevents the option from being silently ignored.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| _method = self.kt_config.method | ||
| _dyn = self.kt_config.kt_enable_dynamic_expert_update | ||
| _mask_static = _method == "MXFP4" or (_method == "MXFP8" and not _dyn) |
There was a problem hiding this comment.
The comparison of _method with "MXFP4" and "MXFP8" is case-sensitive. If a user specifies --kt-method mxfp4 or --kt-method mxfp8 in lowercase, the condition _mask_static will evaluate to False, and the --kt-skip-gpu-expert-cpu-copy flag will be silently ignored (or a warning will be logged).
To ensure robustness and consistency with other parts of the codebase where self.kt_config.method is normalized using .upper(), we should normalize _method to uppercase.
| _method = self.kt_config.method | |
| _dyn = self.kt_config.kt_enable_dynamic_expert_update | |
| _mask_static = _method == "MXFP4" or (_method == "MXFP8" and not _dyn) | |
| _method = (self.kt_config.method or "").upper() | |
| _dyn = self.kt_config.kt_enable_dynamic_expert_update | |
| _mask_static = _method == "MXFP4" or (_method == "MXFP8" and not _dyn) |
There was a problem hiding this comment.
Fixed in d9a8b1c — --kt-method has no argparse choices constraint, so lowercase input was indeed possible and would silently disable the flag. The method string is now normalized with .upper() before the comparison.
…PU experts In a hybrid GPU/CPU MoE split, kt-kernel keeps a CPU copy of every expert, including the ones placed on and computed by the GPU. The companion kt-kernel change adds an opt-in MOEConfig.skip_gpu_expert_cpu_copy that drops those redundant host copies (~63GB at 110 GPU experts for DeepSeek-V4-Flash). Wire it through from the server: - server_args: new --kt-skip-gpu-expert-cpu-copy flag (off by default) - kt_ep_wrapper: resolve the public opt-in into an effective flag, honored only where the GPU/CPU expert mask is static so no runtime path reads a skipped buffer -- MXFP4 (dynamic expert update is a no-op there, so the skip is safe even with --kt-enable-dynamic-expert-update on), or MXFP8 with dynamic update off. If it can't be honored the wrapper warns once and falls back to stock.
f375568 to
d9a8b1c
Compare
Companion to the kt-kernel PR (kvcache-ai/ktransformers#2085); see kvcache-ai/ktransformers#2084 for the full rationale and numbers.
Adds the user-facing
--kt-skip-gpu-expert-cpu-copyserver arg and resolves it into an effective flag passed toKTMoEWrapper:Only paths whose full-GPU prefill fallback is mask-aware may skip: MXFP4's
_prepare_weight_mxfp4→_prepare_weight_fp8copies GPU experts device-to-device fromoriginal_layerand never reads the CPU copies; MXFP4's dynamic-update mask rewrite is unconditionally skipped, so its mask is static even with--kt-enable-dynamic-expert-updateon. If the flag cannot be honored (e.g. MXFP8 + dynamic update), it warns once at layer 0 and falls back to stock behavior — safe by construction.Measured on DeepSeek-V4-Flash (MXFP4, 100–110 GPU experts, RTX PRO 6000 + 123GB RAM): scheduler RSS ~172GB → ~99GB, decode swap io → 0, identical output.
Diff is pure additions (+29, 2 files:
server_args.py,kt_ep_wrapper.py), rebased on current main.