Repository navigation
Quant: OCP FP8 E4M3 support - #27512
Conversation
|
AMD FNUZ is only CDNA3, see https://rocm.docs.amd.com/projects/HIP/en/latest/reference/low_fp_types.html#id4 RDNA4 and CDNA4 use FP8 OCP. |
7ab744c to
d21c273
Compare
I don't have BW to look at MXFP8 atm, but intuitively feel this should come as an extension to OCP FP8, as MXFP8 uses OCP FP8 |
d21c273 to
cef6c52
Compare
91fe47f to
d904f34
Compare
479c902 to
574eb98
Compare
| if (type_a == GGML_TYPE_F8_E4M3 && backend_has_feature(backend, "NATIVE_FP8")) { | ||
| return 5e-3; | ||
| } |
There was a problem hiding this comment.
Based on testing with a B4500 & CUDA, it could be 1e-3 also. I don't have a strong stance on the strictness of this
574eb98 to
8efdff0
Compare
41dbb3b to
62a9875
Compare
There was a problem hiding this comment.
Just a few nits. I haven't looked at the conversion/quantization code, the ggml side looks fine. My general opinion is that we should try and support the 128x128 tile which would enable us to run "true" inference for safetensors checkpoints for a lot of a Chinese OSS models, but understand if that's too much to add.
Added in ggml-org/llama.cpp#27512 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Metadata and enum additions only; no runtime inference or security-sensitive logic changes. > > **Overview** > Adds **F8_E4M3** (OCP-FP8 E4M3) so GGUF tooling stays aligned with llama.cpp (ggml-org/llama.cpp#27512). > > In `packages/tasks`, the type is registered on **`GGMLFileQuantizationType`** (42) and **`GGMLQuantizationType`** (43), and **`GGUF_QUANT_ORDER`** places it with other 8-bit formats after `Q8_0`. In `packages/gguf`, **`GGUF_QUANT_DESCRIPTIONS`** documents the format (with an FP8 reference link) and **`GGML_QUANT_SIZES`** records **8 bits per weight** via `calcBPW(1, 1)`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 231fb19. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
… = 43 GGML_TYPE_Q4_1_G64 43 -> 99, GGML_TYPE_Q4_16 44 -> 100, LLAMA_FTYPE_MOSTLY_Q4_1_G64 42 -> 99; GGML_TYPE_F8_E4M3 = 43 and LLAMA_FTYPE_MOSTLY_F8_E4M3 = 42 as upstream (ggml-org#27512). GGML_TYPE_COUNT 101: ids 44..98 are gaps (zero type_traits, blck_size 0), handled like upstream's existing gaps 31-33/36-38 (gguf rejects them at load, the quantize/test loops skip null names / zero sizes). Upstream's future ids grow from 44 and can no longer collide with ours. gguf-py constants likewise (+ LlamaFileType.MOSTLY_Q4_1_G64); convert_to_g64.py takes the ids from gguf-py. RPC patch version 4 + static_assert on GGML_TYPE_COUNT (head and rpc-server must be the same build). Files written with the old ids are migrated in place by runs/fn-m2/rel3_retype.py (header only; --reverse for builds <= r31). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… since ggml-org#27512 (signbit/isnan/isinf undeclared in ggml_fp32_to_f8_e4m3), GCC 16.2 and clang 22 with libstdc++ 16 (cherry picked from commit d2516b5) Picked from ggml-org#31454 (open at the time of picking).
* WIP OCP FP8 E4M3 support * Fix python type-checker * Materialize input_scales also for FP8 when converting * Fix conversion of https://huggingface.co/RedHatAI/Qwen3.8-27B-NVFP4 1. Per row FP8 wrongly fell to NVFP4 conversion, as NVFP4 checked on dims alone. Also check on dtype for FP8 2. Need to reshape FP8 QKV projections scales in the same way that weights are reshaped * Allow remaining FP8 tensors to be dequantized during conversion * Allow tensor-strategy for FP8-only compressed-tensor ckpts * Fix and test gguf-py behavior for FP8_E4M3 * Disallow QKV-fusion for FP8 temporarily * Fix conversion of fused qkvz & FP8 for Qwen3-Next * Avoid fusing FP8 for --fuse-gate-up-exps as we may have different ws * Emit warnings when not fusing FP8 during conversion * More FP8 conversion fixes * Add supported for strided copies to/from FP8 in CPU * remove unneeded scratch buffer from FP8 cpu cpy/dup path * add explanatory comments and TODOs * Add dedicated encoder and decoder tests for FP8 * Whitelist ggml_op_get_rows in metal instead of blacklisting required to fix failing CI, and white-listing should be more future-proof than adding FP8 to the black-list https://github.com/ggml-org/llama.cpp/actions/runs/38433916498/job/115422880633?pr=27512 * Fix more conversion bugs * Defer weight materialization during conversion * Blacklist fp8 in metal backend instead of white-list * Adjust indents * Fix lint + execute tests * Add fast CPU kernel for F8_E4M3 * Conversion fixes * Fix remaining gaps * Enable tied weights with shared scales * Make mandatory-F32 rules apply to FP8 during conversion * Fix python type checks https://github.com/ggml-org/llama.cpp/actions/runs/39765670052/job/119780379595?pr=27512 * Fix kaleidai unit-test failures https://github.com/ggml-org/llama.cpp/actions/runs/39765670125/job/119780383150 * Relax numeric precision constraints for pre-check * Leave fast-FP8 CPU on RISC-V for follow-up We already exclude arm from the fast-path * Allow output scale tensors to be located in any gguf shard * Move test_conversion_fp8.py test execution to behavior-check.yaml * Apply batched suggestions from code review Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * Move mixed compressed-tensor logic into dequant_fp8 + add unit-tests for it * Install all requirements also on Windows for behavior-check Fixes https://github.com/ggml-org/llama.cpp/actions/runs/40535852590/job/122300758223?pr=27512 * Unmap lazy tensors before clean-up in Windows Should fix https://github.com/ggml-org/llama.cpp/actions/runs/40539797824/job/122314782459?pr=27512 * LF line endings https://github.com/ggml-org/llama.cpp/actions/runs/40539798168/job/122314791118?pr=27512 * Extract FP8 tests from llama-arch to its own test-fixture See ggml-org/llama.cpp#27512 (comment) * Update gguf-py/gguf/scripts/gguf_convert_endian.py Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
The port of ggml-org#27512 @ 41ee520 asked for output.scale and output.input_scale on every output weight. test-llama-archs creates every tensor a model asks for, so the generated models with a tied output got both scales and failed to load ("output scales require a separate output weight"), and the draft of --fit-borrowing-draft had two tensors more than its loader expected. The merged ggml-org#27512 (68d20b8) creates them only when the file has them; do the same. Assisted-by: Claude Opus 5.5
qwen3next now multiplies the gate projection by attn_gate.scale when the model has one (from the port of ggml-org#27512, as upstream). The models test-llama-archs generates carry every optional tensor, so the extra MUL sits between the gated norm's nodes and RMS_NORM+MUL+UNARY+MUL becomes RMS_NORM+MUL and UNARY+MUL. Models without the scale are unchanged. Assisted-by: Claude Opus 5.5
* WIP OCP FP8 E4M3 support * Fix python type-checker * Materialize input_scales also for FP8 when converting * Fix conversion of https://huggingface.co/RedHatAI/Qwen3.8-27B-NVFP4 1. Per row FP8 wrongly fell to NVFP4 conversion, as NVFP4 checked on dims alone. Also check on dtype for FP8 2. Need to reshape FP8 QKV projections scales in the same way that weights are reshaped * Allow remaining FP8 tensors to be dequantized during conversion * Allow tensor-strategy for FP8-only compressed-tensor ckpts * Fix and test gguf-py behavior for FP8_E4M3 * Disallow QKV-fusion for FP8 temporarily * Fix conversion of fused qkvz & FP8 for Qwen3-Next * Avoid fusing FP8 for --fuse-gate-up-exps as we may have different ws * Emit warnings when not fusing FP8 during conversion * More FP8 conversion fixes * Add supported for strided copies to/from FP8 in CPU * remove unneeded scratch buffer from FP8 cpu cpy/dup path * add explanatory comments and TODOs * Add dedicated encoder and decoder tests for FP8 * Whitelist ggml_op_get_rows in metal instead of blacklisting required to fix failing CI, and white-listing should be more future-proof than adding FP8 to the black-list https://github.com/ggml-org/llama.cpp/actions/runs/38433916498/job/115422880633?pr=27512 * Fix more conversion bugs * Defer weight materialization during conversion * Blacklist fp8 in metal backend instead of white-list * Adjust indents * Fix lint + execute tests * Add fast CPU kernel for F8_E4M3 * Conversion fixes * Fix remaining gaps * Enable tied weights with shared scales * Make mandatory-F32 rules apply to FP8 during conversion * Fix python type checks https://github.com/ggml-org/llama.cpp/actions/runs/39765670052/job/119780379595?pr=27512 * Fix kaleidai unit-test failures https://github.com/ggml-org/llama.cpp/actions/runs/39765670125/job/119780383150 * Relax numeric precision constraints for pre-check * Leave fast-FP8 CPU on RISC-V for follow-up We already exclude arm from the fast-path * Allow output scale tensors to be located in any gguf shard * Move test_conversion_fp8.py test execution to behavior-check.yaml * Apply batched suggestions from code review Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * Move mixed compressed-tensor logic into dequant_fp8 + add unit-tests for it * Install all requirements also on Windows for behavior-check Fixes https://github.com/ggml-org/llama.cpp/actions/runs/40535852590/job/122300758223?pr=27512 * Unmap lazy tensors before clean-up in Windows Should fix https://github.com/ggml-org/llama.cpp/actions/runs/40539797824/job/122314782459?pr=27512 * LF line endings https://github.com/ggml-org/llama.cpp/actions/runs/40539798168/job/122314791118?pr=27512 * Extract FP8 tests from llama-arch to its own test-fixture See ggml-org/llama.cpp#27512 (comment) * Update gguf-py/gguf/scripts/gguf_convert_endian.py Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
This adds partial support for [OCP FP8](https://github.com/opencomputeproject/FP8/tree/main) (E4M3). It makes no claim of being compliant with the specification. It is a result of PR ggml-org#27512 - Quant: OCP FP8 E4M3 support. This commit is support for the ADD op, in ggml-sycl/binbcast.cpp. Assisted-by: pi (Greatjedi/Qwen3.8-27B-Intel-Arc-Tuned-GGUF:Q4_K via llama.cpp)
This adds partial support for [OCP FP8](https://github.com/opencomputeproject/FP8/tree/main) (E4M3). It makes no claim of being compliant with the specification. It is a result of PR ggml-org#27512 - Quant: OCP FP8 E4M3 support. This commit is FP8 e4m3 support for the MUL_MAT and MUL_MAT_ID ops, in ggml-sycl/convert.cpp. It uses the generic fp32 GEMM fallback, no DMMV/MMVQ/XMX/reorder fast path. I have not investigated oneDNN support of FP8 e4m3, but there may be opportunties for low-effect / high-impact speed improvements there. Assisted-by: pi (Greatjedi/Qwen3.8-27B-Intel-Arc-Tuned-GGUF:Q4_K via llama.cpp)
This adds partial support for [OCP FP8](https://github.com/opencomputeproject/FP8/tree/main) (E4M3). It makes no claim of being compliant with the specification. It is a result of PR ggml-org#27512 - Quant: OCP FP8 E4M3 support. This commit is support for the CPY op, in ggml-sycl/cpy.cpp. Infrequent (~5-10% of runs) the backend-ops test may fail, due to a precision / tolerance issue in quantizing f16 to low-bit quants. This is pre-existing, and outside of the scope of this work. Assisted-by: pi (Greatjedi/Qwen3.8-27B-Intel-Arc-Tuned-GGUF:Q4_K via llama.cpp)
This adds partial support for [OCP FP8](https://github.com/opencomputeproject/FP8/tree/main) (E4M3). It makes no claim of being compliant with the specification. It is a result of PR ggml-org#27512 - Quant: OCP FP8 E4M3 support. This commit is support for the SET_ROWS op, in ggml-sycl/set_rows.cpp. Assisted-by: pi (Greatjedi/Qwen3.8-27B-Intel-Arc-Tuned-GGUF:Q4_K via llama.cpp)
ggml, cuda : FP8 E4M3 weights and FP8 prefill attention for temp-11739 (port of ggml-org#27512, ggml-org#28392, ggml-org#28413)
Squashed port of the runtime part onto fabric. GGML_TYPE_F8_E4M3 keeps upstream's ID 43; fabric's KV-cache-only TBQ/PQ types move to 52-59. Converter changes and the test-llama-archs FP8 cases are not ported yet. b12032 rebase: b12032 already has upstream ggml-org#27512, so only the move of the TBQ/PQ types to 52-59 remains. RPC goes to 115 here so peers with the old ids are rejected at HELLO, and the assert on TBQ3_0 follows to 52. Assisted-by: Claude Opus 5.5 (cherry picked from commit 7291978)
qwen3next now multiplies the gate projection by attn_gate.scale when the model has one (from the port of ggml-org#27512, as upstream). The models test-llama-archs generates carry every optional tensor, so the extra MUL sits between the gated norm's nodes and RMS_NORM+MUL+UNARY+MUL becomes RMS_NORM+MUL and UNARY+MUL. Models without the scale are unchanged. Assisted-by: Claude Opus 5.5 (cherry picked from commit b35ec1e)
Overview
Add OCP FP8 (E4M3) in saturating mode to ggml.
Additional information
This stacked PR chain does not add plumbing of scales ala ORippler#2, which would have to be done eventually (#28898 will make misuse of scaled types error at least)
I'll mark each of them as ready when I have cleaned them up (functionally everything is there)
Requirements