fix: apply fp8 weight scale factors when loading scaled safetensors - #1898
Open
fszontagh wants to merge 2 commits into
Open
fix: apply fp8 weight scale factors when loading scaled safetensors#1898fszontagh wants to merge 2 commits into
fszontagh wants to merge 2 commits 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.
Summary
fp8 safetensors are dequantised to F16, but the companion per-tensor scale was never applied, so every fp8 weight loaded off by its scale factor. The scales are ~1e-3, so weights end up orders of magnitude too large, activations saturate and generation returns a pure white image. Nothing errors: the run reports
1/1 images saved.Two spellings ship in the wild and both are now handled, for F8 weights only, so
int8_tensorwisecheckpoints keep their existing.weight_scalepath:<module>.scale_weight(ComfyUI)<module>.weight_scale(diffusers).scale_inputis an activation hint with no meaning once the weight is materialised, so it is dropped alongside the weight scale.scripts/convert_fp8_scale_to_bf16.pyonly understood.weight_scaleand had the same blind spot, so it is updated to match.Related Issue / Discussion
None.
Additional Information
Affected checkpoints found locally, both spellings:
qwen_2.5_vl_7b_fp8_scaled.safetensors.scale_weightumt5_xxl_fp8_e4m3fn_scaled.safetensors(WAN encoder).scale_weightqwen3vl_8b_fp8_scaled.safetensors.weight_scaleBefore/after on two pipelines, same command and seed, measured on the decoded output:
For Qwen-Image-Edit the fixed output differs from the same prompt run through the GGUF build of the same encoder by mean 1.43, i.e. the scaling is numerically right rather than merely non-blank.
SD 1.5 was re-run as a regression check and is unchanged. The change is inert on checkpoints that carry no scale tensors.
Checklist