Skip to content

Conversation

@yiliu30
Copy link
Owner

@yiliu30 yiliu30 commented Oct 22, 2025

PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS (AT THE BOTTOM) HAVE BEEN CONSIDERED.

Purpose

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)

Signed-off-by: yiliu30 <[email protected]>
Signed-off-by: yiliu30 <[email protected]>
Signed-off-by: yiliu30 <[email protected]>
Signed-off-by: yiliu30 <[email protected]>
Signed-off-by: yiliu30 <[email protected]>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the quantization scheme implementation, focusing on MXFP4. It introduces a new fp4_utils.py file to centralize FP4-related operations and cleans up commented-out code and improves code style in several places. My review identifies a critical bug in an assertion that fails to check for tensor contiguity correctly, and a high-severity performance issue due to a redundant and inefficient function call which can be removed.

orig_shape = result_shape
else:
raise AssertionError("unsupported")
assert data_lp.is_contiguous, f"Data must be contiguous, got {data_lp.stride()}"

Choose a reason for hiding this comment

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

critical

This assertion has a syntax error and introduces a functional regression.

  1. Buggy Assertion: is_contiguous is a method and should be called as data_lp.is_contiguous(). The current code assert data_lp.is_contiguous, ... is always True because it asserts on the method object itself, not its result. This means the contiguity check is effectively disabled, which could lead to silent errors or incorrect behavior downstream if a non-contiguous tensor is passed.
  2. Functional Regression: The previous implementation handled non-contiguous tensors by transposing them. This new implementation removes that logic and intends to enforce contiguity via an assertion. This is a significant change in behavior that could break callers if they pass non-contiguous tensors.

Please fix the assertion and consider if dropping support for non-contiguous tensors is intended and safe.

Suggested change
assert data_lp.is_contiguous, f"Data must be contiguous, got {data_lp.stride()}"
assert data_lp.is_contiguous(), f"Data must be contiguous, got {data_lp.stride()}"


data_lp = data_lp.reshape(orig_shape)
orig_shape = [*orig_shape[:-1], orig_shape[-1] // 2]
data_lp = cast_to_fp4(data_lp)

Choose a reason for hiding this comment

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

high

The call to cast_to_fp4 on this line is redundant. The pack_fp4_to_uint8 function, called on the next line, already handles rounding the float tensor to the nearest FP4 value before packing. Removing this line will improve performance and simplify the code. The cast_to_fp4 function itself is also implemented inefficiently.

Comment on lines +107 to +118
def cast_to_fp4(x):
sign = torch.sign(x)
x = torch.abs(x)
x[(x >= 0.0) & (x <= 0.25)] = 0.0
x[(x > 0.25) & (x < 0.75)] = 0.5
x[(x >= 0.75) & (x <= 1.25)] = 1.0
x[(x > 1.25) & (x < 1.75)] = 1.5
x[(x >= 1.75) & (x <= 2.5)] = 2.0
x[(x > 2.5) & (x < 3.5)] = 3.0
x[(x >= 3.5) & (x <= 5.0)] = 4.0
x[x > 5.0] = 6.0
return x * sign No newline at end of file

Choose a reason for hiding this comment

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

high

Following the removal of its only call site in mxfp4_qdq_utils.py, this function cast_to_fp4 is now unused and can be removed. Additionally, its implementation using multiple masked assignments is inefficient on GPUs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants