Skip to content

[Kernel] Switch fp8 layers to use the CUTLASS kernels#5183

Merged
pcmoritz merged 9 commits intovllm-project:mainfrom
neuralmagic:tms/use_cutlass_4_fp8
Jun 7, 2024
Merged

[Kernel] Switch fp8 layers to use the CUTLASS kernels#5183
pcmoritz merged 9 commits intovllm-project:mainfrom
neuralmagic:tms/use_cutlass_4_fp8

Conversation

@tlrmchlsmth
Copy link
Copy Markdown
Member

@tlrmchlsmth tlrmchlsmth commented Jun 1, 2024

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and #5144 for comparisons across different GEMM sizes.


PR Checklist (Click to Expand)

Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Model] for adding a new model or improving an existing model. Model name should appear in the title.
  • [Frontend] For changes on the vLLM frontend (e.g., OpenAI API server, LLM class, etc.)
  • [Kernel] for changes affecting CUDA kernels or other compute kernels.
  • [Core] for changes in the core vLLM logic (e.g., LLMEngine, AsyncLLMEngine, Scheduler, etc.)
  • [Hardware][Vendor] for hardware-specific changes. Vendor name should appear in the prefix (e.g., [Hardware][AMD]).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to docs/source/ if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.

Notes for Large Changes

Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with rfc-required and might not go through the PR.

What to Expect for the Reviews

The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

Thank You

Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!

@robertgshaw2-redhat
Copy link
Copy Markdown
Collaborator

Comment thread vllm/model_executor/layers/quantization/fp8.py Outdated
@tlrmchlsmth
Copy link
Copy Markdown
Member Author

Just ran a quick sanity check for correctness. Output looks good on all three. I tried tensor_parallel_size=2 as well for the 70B model, and that looks good

return torch.narrow(output, 0, 0, x.shape[0])

# We use the CUTLASS kernels by default but they don't support bias yet
if bias is None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we also do a branch if we are on ada lovelace and CUDA 12.1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We will need to if on CUDA < 12.4. We also need a branch if on CUDA 11.8. @comaniac do you know if torch._scaled_mm is supported in that case?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I only know that it only supports SM89+. We can try to call this op with torch+cu118 to test out.

Copy link
Copy Markdown
Member Author

@tlrmchlsmth tlrmchlsmth Jun 1, 2024

Choose a reason for hiding this comment

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

The cutlass kernels need at least SM89 as well, for the record.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah that makes sense. Older architectures don't have native FP8 so we can't get speedup from them, which seems not necessary to be covered.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note: we already have a mechanism for determining if a LinearMethod can run on a specific cuda arch. The LinearMethod exposes get_min_capability which is called during model loading.

https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/layers/quantization/fp8.py#L46

@pcmoritz
Copy link
Copy Markdown
Collaborator

pcmoritz commented Jun 1, 2024

Did you run benchmarks to compare the end-to-end performance? ITL for different qps

@robertgshaw2-redhat
Copy link
Copy Markdown
Collaborator

Did you run benchmarks to compare the end-to-end performance? ITL for different qps

Not yet. But obviously need this before we merge

@comaniac
Copy link
Copy Markdown
Collaborator

comaniac commented Jun 1, 2024

I'll do a benchmark on Monday anyways. btw it'd be great if this PR is rebased onto the latest main that includes all required changes (it's likely the case already I suppose

@tlrmchlsmth
Copy link
Copy Markdown
Member Author

btw it'd be great if this PR is rebased onto the latest main that includes all required changes (it's likely the case already I suppose

It's on a very recent main (from this morning) so it's good to use as is. In particular both #5144 and #5137 were needed for the switchover and they are both in.

Comment thread vllm/_custom_ops.py
@comaniac
Copy link
Copy Markdown
Collaborator

comaniac commented Jun 6, 2024

@tlrmchlsmth @robertgshaw2-neuralmagic per offline discussion, this PR should be ok to go at least for now?

@tlrmchlsmth
Copy link
Copy Markdown
Member Author

Yeah, let's get it landed. It needs to check a few more cases for falling back to scaled_mm. I'll get to that today and then mark it ready for review

Comment thread vllm/model_executor/layers/quantization/fp8.py Outdated
@tlrmchlsmth tlrmchlsmth marked this pull request as ready for review June 6, 2024 22:05
Copy link
Copy Markdown
Collaborator

@robertgshaw2-redhat robertgshaw2-redhat left a comment

Choose a reason for hiding this comment

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

LGTM :)

Copy link
Copy Markdown
Collaborator

@pcmoritz pcmoritz left a comment

Choose a reason for hiding this comment

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

Great work and thanks for adding the benchmarks :)

Copy link
Copy Markdown
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!
I also did some benchmarks with this PR. Note that all results are in TP=4 on H100 and with chunked prefill enabled (this is just my own requirement). Prompts are 550 tokens, decoding 150 tokens.

Model QPS scaled_mm-ITL cutlass-ITL scaled_mm-TTFT cutlass-TTFT
Llama-3-70B 1 17.3 16.3 68.7 68.7
Llama-3-70B 4 22.7 21.2 72.3 72.6
Llama-3-70B 8 35.9 33.6 83.1 81.2
Mixtral-8x7B 1 9.1 8.9 43.1 40.7
Mixtral-8x7B 4 11.4 10.7 42.6 38.4
Mixtral-8x7B 8 15.6 14.3 43.4 42.8

@pcmoritz pcmoritz enabled auto-merge (squash) June 7, 2024 00:32
@pcmoritz pcmoritz merged commit 8d75fe4 into vllm-project:main Jun 7, 2024
@cli99
Copy link
Copy Markdown
Contributor

cli99 commented Jun 7, 2024

@tlrmchlsmth Awesome work! Was trying this but ran into a problem when checking the cutlass fp8 support. Made a fix that works in my case in #5352.

pcmoritz pushed a commit that referenced this pull request Jun 8, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in #5183.
dtrifiro pushed a commit to opendatahub-io/vllm that referenced this pull request Jun 10, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
dtrifiro pushed a commit to opendatahub-io/vllm that referenced this pull request Jun 10, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project#5183.
robertgshaw2-redhat pushed a commit to neuralmagic/nm-vllm that referenced this pull request Jun 11, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
robertgshaw2-redhat pushed a commit to neuralmagic/nm-vllm that referenced this pull request Jun 11, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project#5183.
joerunde pushed a commit to IBM/vllm that referenced this pull request Jun 13, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project/vllm#5183.
@tlrmchlsmth tlrmchlsmth deleted the tms/use_cutlass_4_fp8 branch June 14, 2024 17:20
joerunde pushed a commit to joerunde/vllm that referenced this pull request Jun 17, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jun 27, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jun 27, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project#5183.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jul 8, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jul 8, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project#5183.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jul 24, 2024
)

Switching from torch._scaled_mm to vLLM's cutlass fp8 kernels when supported as we are seeing 5-15% improvement in e2e performance on neuralmagic/Meta-Llama-3-8B-Instruct-FP8

see https://docs.google.com/spreadsheets/d/1GiAnmzyGHgZ6zL_LDSTm35Bdrt4A8AaFEurDlISYYA4/ for some quick e2e benchmarks and vllm-project#5144 for comparisons across different GEMM sizes.
xjpang pushed a commit to xjpang/vllm that referenced this pull request Jul 24, 2024
Bug description:
With torch 2.4.0.dev20240603+cu121,
cutlass_fp8_supported outputs False, and the (capability, version) before the comparison is (90, 11111111112)

This PR fixes the support check for FP8 CUTLASS ( cutlass_fp8_supported) which was introduced in vllm-project#5183.
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.

5 participants