[FRONTEND] Low-precision float support: resolve_dot capability contract, fp8 cast routing, interpreter float conversion rewrite - #1112
Closed
zeroherolin wants to merge 1 commit into
Conversation
…, fp8 cast dtype routing, interpreter float conversion rewrite, precision tutorials Common-layer groundwork for per-backend low-precision float support: - backends/compiler.py: DotCap/DotSupport, the answer type for the new optional resolve_dot / resolve_dot_scaled codegen-function queries. Backends that do not register them keep the legacy dot dtype rules. - language/semantic.py: query resolve_dot(_scaled) once shapes are known; reject UNSUPPORTED combinations and warn on EMULATED ones. fp8 cast routing via supported_fp8_cast_dtypes / custom_cast_fp8_dtypes options; the default preserves the legacy fp8e4b15-only custom-cast routing. - runtime/interpreter.py: rewrite _convert_float as exact decode/encode through fp64 with strict RTNE/RTZ and correct fn/fnuz/none special-value conventions (the old path rounded half-up and mishandled specials); fnuz zero results encode as +0, never the sign-only NaN code. Also add the flagtree_hints parameter to create_load/create_masked_load to match the semantic layer's call signature. - backends/__init__.py: dunder probes on the lazy language-extensions proxy raise AttributeError instead of failing module resolution. - tutorials/precision: runnable fp8 (E4M3FN) and fp4 (E2M1) walkthroughs driven by the declared capabilities, portable across backends.
zeroherolin
requested review from
Galaxy1458,
menchunlei,
sunnycase and
zhzhcookie
as code owners
September 7, 2026 02:59
This was referenced Sep 7, 2026
Collaborator
Author
|
goto #1116 |
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
Common-layer groundwork for per-backend low-precision float (fp8/fp4) support. The backend PRs (PPU, MThreads, and so on) build on this branch.
backends/compiler.py: addsDotCap/DotSupport— the answer type for two new optional codegen-function queries,resolve_dot(a_dtype, b_dtype, acc_dtype, M, N, K)andresolve_dot_scaled(lhs_format, rhs_format). A backend that registers them owns its dot legality rules; the semantic layer raises onUNSUPPORTED(with the backend's diagnostic) and emits a compile-time warning onEMULATED, so non-native paths cannot degrade silently.language/semantic.py: queriesresolve_dot(_scaled)after the legacy e4b15/fnuz upcasts so rules see effective dtypes; adds fp8 cast routing viasupported_fp8_cast_dtypes(numeric-cast whitelist) andcustom_cast_fp8_dtypes(dtypes lowered throughconvert_custom_types).runtime/interpreter.py: rewrites_convert_floatas exact decode/encode through fp64 with strict RTNE/RTZ and correctfn/fnuz/nonespecial-value conventions. The previous implementation rounded half-up (not round-to-nearest-even) and mishandled inf/NaN of the non-IEEE fp8 formats.python/tutorials/precision/: runnable fp8 (E4M3FN) and fp4 (E2M1) walkthroughs driven by the declared capabilities; they degrade gracefully on backends that do not declare them.Backward compatibility
Every existing backend is unaffected:
resolve_dot/resolve_dot_scaledare looked up withcodegen_fns.get(...); absent means the legacy dtype whitelist path runs unchanged.custom_cast_fp8_dtypesdefaults to("fp8e4b15",), preserving the legacy fp8e4b15-onlyconvert_custom_typesrouting;supported_fp8_cast_dtypesis only enforced when a backend's options define it.Behavior changes to be aware of
0x7F/0xFF, fnuz NaN = sign-only pattern, e4b15 has neither inf nor NaN). fnuz results that round to zero encode as+0, never the sign-only NaN code. This is a correctness fix; results move closer to hardware.0x00(previously0x80= NaN for fnuz formats).Bug fixes included
runtime/interpreter.py:create_load/create_masked_loadwere missing theflagtree_hintsparameter that the semantic layer passes since the hints feature landed — interpreter mode currently fails on any load.backends/__init__.py: dunder probes (inspect,copy, ...) on the lazytl.extproxy now raiseAttributeErroras the protocol expects, instead of failing backend-module resolution.