Skip to content

Conversation

mgoin
Copy link
Member

@mgoin mgoin commented Jun 11, 2025

Purpose

We require that the inputs are contiguous for both the dynamic_per_token_scaled_fp8_quant and dynamic_scaled_int8_quant kernels. This PR enforces that as I ran into an error when evaluating a deepseek model.

Test Plan

Tested using FP8-dynamic DeepSeek V2 Lite (per token and per channel)

Test Result

Before:

lm_eval --model vllm --model_args pretrained=nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8-dynamic --trust_remote_code --tasks gsm8k --num_fewshot 5 --batch_size auto 
...
  File "/home/mgoin/code/vllm/vllm/model_executor/layers/quantization/compressed_tensors/schemes/compressed_tensors_w8a8_fp8.py", line 145, in apply_weights
    return self.fp8_linear.apply(input=x,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgoin/code/vllm/vllm/model_executor/layers/quantization/utils/w8a8_utils.py", line 351, in apply
    qinput, x_scale = ops.scaled_fp8_quant(
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgoin/code/vllm/vllm/_custom_ops.py", line 1269, in scaled_fp8_quant
    torch.ops._C.dynamic_per_token_scaled_fp8_quant(
  File "/home/mgoin/venvs/vllm/lib/python3.12/site-packages/torch/_ops.py", line 1158, in __call__
    return self._op(*args, **(kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Expected input.is_contiguous() to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.)

After:

lm_eval --model vllm --model_args pretrained=nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8-dynamic --trust_remote_code --tasks gsm8k --num_fewshot 5 --batch_size auto 
vllm (pretrained=nm-testing/DeepSeek-Coder-V2-Lite-Instruct-FP8-dynamic,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: auto
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.7528|±  |0.0119|
|     |       |strict-match    |     5|exact_match|↑  |0.7362|±  |0.0121|

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
Contributor

@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.

Summary of Changes

Hello @mgoin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the dynamic per-token FP8 and dynamic INT8 quantization kernels would fail if their input tensors were not contiguous in memory. The change ensures that the input is made contiguous before being passed to the underlying kernels, fixing the RuntimeError and allowing models like DeepSeek V2 Lite FP8-dynamic to run correctly.

Highlights

  • Fix Runtime Error: Addresses a RuntimeError that occurred when dynamic per-token FP8 or dynamic INT8 quantization kernels received non-contiguous input tensors.
  • Enforce Contiguity: Ensures that the input tensor passed to the dynamic_per_token_scaled_fp8_quant and dynamic_scaled_int8_quant C++ kernels is contiguous by explicitly calling .contiguous() on the input.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@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 effectively resolves a RuntimeError that occurred when non-contiguous tensors were passed as input to specific FP8 and INT8 quantization kernels. The fix involves adding .contiguous() calls to the input tensors in vllm/_custom_ops.py before they are processed by the underlying C++ operations. These changes are well-targeted and directly address the issue described.

My review feedback primarily focuses on enhancing code maintainability by suggesting the addition of inline comments. These comments would explain why the .contiguous() calls are necessary (i.e., due to kernel requirements), which is helpful for future developers and aligns with existing commenting practices within the codebase (such as for the rms_norm function).

Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

1 similar comment
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Looks good.

@houseroad houseroad added the ready ONLY add when PR is ready to merge/full CI is needed label Jun 11, 2025
@mgoin mgoin requested a review from LucasWilkinson June 11, 2025 13:50
@mgoin mgoin changed the title Enforce contiguous input for dynamic_per_token FP8/INT8 quant [Bugfix] Enforce contiguous input for dynamic_per_token FP8/INT8 quant Jun 11, 2025
@mgoin mgoin added the bug Something isn't working label Jun 11, 2025
Copy link
Collaborator

@LucasWilkinson LucasWilkinson left a comment

Choose a reason for hiding this comment

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

Can we just update the kernel to support non-contiguous data? I think this should be our default response to these kind of bugs

@mgoin
Copy link
Member Author

mgoin commented Jun 11, 2025

I worry about losing the vectorization for the non-contiguous case, but okay we can make the change after Wentao lands the vectorization refactor in #19233

@mgoin
Copy link
Member Author

mgoin commented Jun 12, 2025

Will address in future work, let us land fix for now

@mgoin mgoin merged commit a3319f4 into vllm-project:main Jun 12, 2025
76 checks passed
@mgoin mgoin deleted the contiguous-dynamic_per_token_scaled_quant branch June 12, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants