fix(models): preserve glm4 router correction bias in fp32 - #469
Open
taking-lying-flat wants to merge 1 commit into
Open
taking-lying-flat wants to merge 1 commit into
taking-lying-flat wants to merge 1 commit into
Conversation
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.
GLM-4's resident-weight loader casts the FP32 router correction bias to BF16, and the model declaration inherits the engine's default dtype. Upcasting the bias in
_route()cannot recover the lost precision and can change which experts are selected near a top-k boundary.Declare
e_score_correction_biasas FP32 and load it as FP32 so engine materialization preserves it. Correct the comments that describe rounding as safe for expert selection. This change is limited to the GLM-4 path.Validation: CPU only, Intel Core i7-12800HX, Linux x86_64, PyTorch 2.11.0+cu130; synthetic FP32 bias with BF16 gate/input, no model checkpoint or GPU execution.
[0]instead of[1], and top-2 selected[2, 0]instead of[2, 1]. Comparisons are strict, with no dependence on tie-breaking. The checks also cover the real model declaration, loader, engine materialization, and unbiased routing weights.PYTHONPATH=/home/cherry-cloud/FreeToken-glm-router-bias/python /tmp/freetoken-glm-shared-venv/bin/python -m pytest /tmp/freetoken-glm-bias-audit/test_models_loader.py -q --tb=short.git diff --checkpassed. Real-checkpoint disagreement rates and end-to-end model quality have not been measured.