Conversation
for more information, see https://pre-commit.ci
Summary of ChangesHello @Datta0, 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 introduces comprehensive support for per-tensor FP8 quantization within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for FP8 per-tensor quantization by updating the logic in unsloth/kernels/fp8.py. The changes correctly handle scalar weight scales in weight_dequant and FP8BlockQuantLinear, and route per-tensor quantized operations to the appropriate functions. While the implementation for the forward pass is sound, I've identified a critical issue in the backward pass where the block_size is not being used, potentially leading to incorrect gradients for block-quantized weights with non-default block sizes. I've also noted a minor point of confusion in a comment.
I am having trouble creating individual review comments. Click here to see my feedback.
unsloth/kernels/fp8.py (351-353)
The block_size is no longer saved to the context. While it's true that ctx.block_size was unused in the backward pass, this points to a potential bug. The backward pass calls weight_dequant, which in turn calls weight_dequant_block with a hardcoded default block_size of 128. If a non-default block_size is used in the forward pass (e.g., from weight.block_size), the dequantization in the backward pass will be incorrect, leading to wrong gradients.
To fix this, block_size should be saved to the context and the backward pass should be updated to use it for correct dequantization. This might require changes to weight_dequant and weight_dequant_block to accept and use the block_size.
unsloth/kernels/fp8.py (309-310)
The comment at line 309 is a bit misleading. It states that the original scale is saved before any transformation, but original_weight_scale is updated on line 332 if the scale is transposed. This can be confusing. A more accurate comment would clarify that this variable holds the scale to be used in the backward pass.
# Save the scale for the backward pass.
original_weight_scale = weight_scale
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 400591fcf6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Fixes: #3862
We basically use the same code we have for block quant matmul but change the block size to tensor size