Skip to content

CUDA: tighter MMQ src1 buffer size for native fp4#25613

Draft
leonardHONG wants to merge 1 commit into
ggml-org:masterfrom
leonardHONG:cuda-mmq-fp4-pool-size
Draft

CUDA: tighter MMQ src1 buffer size for native fp4#25613
leonardHONG wants to merge 1 commit into
ggml-org:masterfrom
leonardHONG:cuda-mmq-fp4-pool-size

Conversation

@leonardHONG

Copy link
Copy Markdown
Contributor

Overview

The native FP4 path still sizes the src1 quantization buffer using the Q8_1 layout.

block_fp4_mmq has the same size as block_q8_1_mmq, but stores twice as many values, so the buffer is over-allocated by 2x in both MUL_MAT and MUL_MAT_ID.

This PR uses the actual block layout of the selected quantizer. The extra tail padding is unchanged.

Additional information

Tested on RTX 5090 with MXFP4 and NVFP4 for both MUL_MAT and MUL_MAT_ID.

All test-backend-ops cases passed. Around 300 FP4 cases also passed under compute-sanitizer --tool memcheck with 0 errors.

Requirements

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jul 13, 2026
@leonardHONG leonardHONG marked this pull request as ready for review July 13, 2026 06:33
@leonardHONG leonardHONG requested a review from a team as a code owner July 13, 2026 06:33
Comment thread ggml/src/ggml-cuda/mmq.cu Outdated
const bool use_native_fp4 = blackwell_mma_available(cc) && (src0->type == GGML_TYPE_MXFP4 || src0->type == GGML_TYPE_NVFP4);
// Native fp4 packs twice as many values per MMQ block as q8_1.
const size_t y_block_size = use_native_fp4 ? sizeof(block_fp4_mmq) : sizeof(block_q8_1_mmq);
const size_t y_values_per_block = use_native_fp4 ? QK_K : 4*QK8_1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QK_K is probably overloaded here, we should use a better term

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added QK_FP4_MMQ.

@leonardHONG leonardHONG force-pushed the cuda-mmq-fp4-pool-size branch from 5b50dee to 4e896d2 Compare July 13, 2026 07:39
@JohannesGaessler

Copy link
Copy Markdown
Contributor

This should be scheduled after #24127 .

@leonardHONG

Copy link
Copy Markdown
Contributor Author

OK, I’ll rebase after it lands.

@leonardHONG leonardHONG marked this pull request as draft July 13, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants