Repository navigation
[Fix] Align GLM-5.3 Flash clamped SwiGLU rounding with LMDeploy - #2304
Open
qescccczmr wants to merge 1 commit into
Open
qescccczmr wants to merge 1 commit into
qescccczmr wants to merge 1 commit into
Conversation
qescccczmr
force-pushed
the
fix/glm53-lmdeploy-swiglu-rounding
branch
from
November 12, 2026 12:45
2bef3aa to
7f738b4
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BF16 clamped SwiGLU currently rounds the SiLU result before multiplying by the up projection. LMDeploy's precise-multiply path retains that intermediate in FP32, introducing a training/rollout rounding difference even when both sides use BF16 activations.
This adds an opt-in
XTUNER_GLM53_LMDEPLOY_SWIGLU=1path for GLM-5.3 Flash clamped SwiGLU. It reuses LMDeploy's CUDA forward kernel and registers a mathematical backward in FP32 with the same clamp boundaries. Both fused gate/up and separate gate/up callers are covered. The custom operator includes fake-tensor registration for full-graph compilation.Set the variable before importing XTuner in every training worker. The enabled CUDA path requires LMDeploy with
silu_and_mul(..., precise_mul=True)support; LMDeploy is imported lazily. The default path and CPU/NPU fallback retain their existing behavior. Separate gate/up callers concatenate their inputs for the serving kernel.Validation: 15 focused tests passed on H200 with PyTorch 2.9.1 / CUDA 12.8, covering exact serving-forward parity (BF16/FP32, empty and non-last split dimensions), VJPs against an FP64 oracle including clamp boundaries, CPU fallback, AOT full-graph backward, and a nonzero SGD update. Ruff lint/format and
git diff --checkpassed.This addresses the activation rounding boundary only. Full-model PPO KL improvement has not yet been measured. KPool, FP8 quantization, KDA, and DeepEP changes are outside this PR.