Repository navigation
Fix FP8 conversion corruption by separating value-preserving and scaled quantization - #4
Merged
lmangani merged 10 commits intoFeb 13, 2026
Merged
Conversation
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for Float8_e4m3fn conversion to MPS backend
Fix FP8 conversion corruption by separating value-preserving and scaled quantization
Feb 13, 2026
lmangani
marked this pull request as ready for review
February 13, 2026 05:49
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.
FP8 conversions on MPS produced corrupted results (values scaled 100-400x) because
fp8_quantize()applied automatic scaling to use the full FP8 range but the scale was lost sincetorch.float8_e4m3fndoesn't store metadata.Changes
Core implementation:
fp8_encode()for value-preserving conversion (no automatic scaling)_metal_tensor_to()to usefp8_encode()for.to(dtype=torch.float8_e4m3fn)_metal_tensor_copy()to usefp8_encode()for float→FP8 copiesfp8_quantize()with scaling fortorch._scaled_mm(backward compatible)Affected code paths:
.to(torch.float8_e4m3fn): now preserves value semantics viafp8_encode().to(torch.float32)from FP8: now works via dequantization.copy_()with FP8 destination: usesfp8_encode()for conversionstorch._scaled_mm: unchanged, still usesfp8_quantize()with explicit scalesThe distinction:
fp8_encode()treats FP8 as a data type (preserve values), whilefp8_quantize()treats it as a storage format (maximize precision with separate scale management).Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.