Skip to content

Feat: Implementation of the DeepSeek blockwise quantization for fp8 tensors #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Degnel
Copy link

@Degnel Degnel commented Feb 22, 2025

This PR is the first step towards addressing issue #1594. It includes the following implementations:

  • fp8 triton gemm for blockwise quantisation
  • quant, dequant and linear utilities
  • time & precision benchmarks
  • basic tests

If the code is validated, it would be great to bench it on H100.

Copy link

pytorch-bot bot commented Feb 22, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1763

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 26bb079 with merge base f343336 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 22, 2025
@danielvegamyhre
Copy link
Contributor

Thanks for your work on this! I'll take a closer look next week.

cc @vkuzo @drisspg

@Degnel
Copy link
Author

Degnel commented Feb 25, 2025

Thanks for running the tests. I have two questions regarding the errors:

  • Where should I add Triton to allow the tests to run successfully without introducing unnecessary dependencies in dev-requirements.txt?
  • Does torchao provide any utility to check the available FP8 types for each gpu architecture?

@danielvegamyhre
Copy link
Contributor

danielvegamyhre commented Feb 27, 2025

Thanks for running the tests. I have two questions regarding the errors:

  • Where should I add Triton to allow the tests to run successfully without introducing unnecessary dependencies in dev-requirements.txt?

Can you clarify what you mean? Are tests failing in CI due to a missing triton installation? That shouldn't be happening, please share the link/logs if so.

  • Does torchao provide any utility to check the available FP8 types for each gpu architecture?

We just use helpers which skip tests if GPU architecture is not at least SM 89:

def is_sm_at_least_89():

You can find examples in the float8 tests (example).

@danielvegamyhre danielvegamyhre self-assigned this Feb 27, 2025
@danielvegamyhre danielvegamyhre self-requested a review February 27, 2025 17:45
@Degnel
Copy link
Author

Degnel commented Feb 28, 2025

Can you clarify what you mean? Are tests failing in CI due to a missing triton installation? That shouldn't be happening, please share the link/logs if so.

Indeed, they are. It looks like only the CPU runs are failing. I presume that bitsandbytes might not install triton when no GPU is available (I might be missing something there). Here is an instance of a failing log:

https://github.com/pytorch/ao/actions/runs/13484452669/job/37730985419?pr=1763#step:14:1276

We just use helpers which skip tests if GPU architecture is not at least SM 89:

def is_sm_at_least_89():

You can find examples in the float8 tests (example).

Thank you for the hint, I've locally updated the code accordingly 👍

W_q, W_s = fp8_blockwise_weight_quant(W, block_size, dtype)
output_blockwise = blockwise_fp8_gemm(A_q, A_s, W_q, W_s)

quantize_(lin, int8_dynamic_activation_int4_weight())
Copy link
Contributor

Choose a reason for hiding this comment

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

why is int8_dynamic_activation_int4_weight being used here?

Copy link
Author

Choose a reason for hiding this comment

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

Thank's for noticing it. I was aiming for a static W4A8 quantization and I overlooked that it was dynamic. I will try to address this within the week.

@danielvegamyhre
Copy link
Contributor

Can you clarify what you mean? Are tests failing in CI due to a missing triton installation? That shouldn't be happening, please share the link/logs if so.

Also @Degnel you should skip tests requiring triton if CUDA is not available.

@danielvegamyhre
Copy link
Contributor

@Degnel thanks for your work on this, i ran the tests and it looks like your blockwise fp8 gemm test is failing due to quantization error

@Degnel
Copy link
Author

Degnel commented Mar 7, 2025

@Degnel thanks for your work on this, i ran the tests and it looks like your blockwise fp8 gemm test is failing due to quantization error

Thanks for pointing that out! I had also noticed the issue, and I think I was just a bit too harsh with the threshold. I'll increase it to make it more reasonable. That said, I'll still double-check the calculations manually to ensure everything is mathematically correct.

@Degnel
Copy link
Author

Degnel commented Mar 13, 2025

@danielvegamyhre I believe that everything should be alright except for the PR Label Check (I'm not sure if I have the required rights to edit this). The test-mps-ops (macos-m1-stable) failed, but I think that the merge will fix it as it seems to be a newly introduced test.

@danielvegamyhre danielvegamyhre added the topic: new feature Use this tag if this PR adds a new feature label Mar 13, 2025
@Degnel
Copy link
Author

Degnel commented Mar 14, 2025

The test-mps-ops (macos-m1-stable) failed once again. I've seen other recent PRs both succeeding and failing this test (due to the same missing package 'importlib_metadata'). I don't think this is related to the code I wrote, but I might be missing something. Please, let me know if you have any insights.

@drisspg
Copy link
Contributor

drisspg commented Mar 14, 2025

the test mps is unrleated, re-running tests

@Degnel
Copy link
Author

Degnel commented Apr 21, 2025

It seems like the new PRs are not failing anymore due to the macOS tests. Maybe we should try to rerun it here :) @danielvegamyhre @drisspg

@drisspg
Copy link
Contributor

drisspg commented Apr 24, 2025

Sorry, could you do 1 more rebase to kick back off ci

Degnel added 7 commits April 25, 2025 14:08
- fp8 triton gemm
- quant, dequant and linear utils
- time & precision benchmarks
- basic tests
- removing triton dependency
- cleanning adaptative dtype
- fixing W4A8 quantization for cutlass kernel in precision benchmark
- importing triton only if cuda available
- setting a less harsh threshold for quant-dequant and for gemm kernel mm precision
- condition triton import in gemm
- linting
@Degnel Degnel force-pushed the feat/blockwise_fp8_quant_triton_gemm_ker branch from e8edea9 to e41457c Compare April 25, 2025 12:11
@Degnel
Copy link
Author

Degnel commented Apr 25, 2025

Sorry, could you do 1 more rebase to kick back off ci

No problem, it should be ok

@Degnel
Copy link
Author

Degnel commented Apr 26, 2025

Thank you @drisspg I've made the linting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: new feature Use this tag if this PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants