Skip to content

Conversation

@danielhanchen
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danielhanchen, 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 significantly improves the integration and handling of FP8 compressed tensors within the vLLM utility. It introduces robust mechanisms for identifying different FP8 quantization schemes, correctly interpreting their weight scales, and configuring the appropriate FP8 linear layers for efficient model loading and operation. The changes aim to enhance compatibility and performance when working with FP8 quantized models.

Highlights

  • FP8 Compressed Tensor Support: Enhanced handling of FP8 compressed tensors by introducing logic to detect CompressedTensors quantization methods and adjust weight scale naming conventions accordingly, specifically switching from .weight_scale_inv to .weight_scale.
  • Dynamic FP8 Layer Configuration: Added explicit support for compressed-tensors quantization in the convert_vllm_to_huggingface utility, allowing dynamic configuration of FP8Linear layers with appropriate block sizes derived from the quantization configuration.
  • Unified FP8 Scale Handling: Refactored the loading of FP8 weight scales to check for both weight_scale and weight_scale_inv and dynamically select between FbgemmFp8Linear (for row-quantized, ndim=1) and FP8Linear (for block-quantized, ndim=2) based on the scale's dimensionality.
  • vLLM Compilation Config Adjustment: The compilation_config parameter has been commented out during vLLM loading, potentially streamlining the loading process or addressing a compatibility concern.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

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

@danielhanchen danielhanchen merged commit e3dad1f into unslothai:nightly Nov 23, 2025
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 adds support for FP8 compressed tensors by detecting this new quantization method, handling its specific configuration for block size, and refactoring the layer creation logic. My review focuses on improving the robustness and readability of the new code. I've suggested refactoring a type check to be less brittle, simplifying configuration parsing, and using a more specific exception handler.

Comment on lines +942 to +943
is_compressed_linear = "CompressedTensors" in str(type(getattr(proj, 'quant_method', None)))
if is_compressed_linear:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The check for is_compressed_linear relies on the string representation of a type, which can be brittle. This can be refactored to check the class name directly and combine the variable assignment and the conditional check into one if statement for improved robustness and conciseness.

Suggested change
is_compressed_linear = "CompressedTensors" in str(type(getattr(proj, 'quant_method', None)))
if is_compressed_linear:
quant_method = getattr(proj, 'quant_method', None)
if quant_method is not None and "CompressedTensors" in quant_method.__class__.__name__:
Comment on lines +1213 to +1216
config_groups = quantization_config.get('config_groups', None)
group_0 = config_groups.get(0, None) if config_groups else None
weights = group_0.get('weight', None) if group_0 else None
block_size = weights.get('block_size', block_size) if weights else block_size
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for extracting block_size from the configuration can be simplified for better readability and maintainability. Using chained .get() calls with default values makes the code more concise and less prone to errors from None values, assuming config_groups is a dictionary.

Suggested change
config_groups = quantization_config.get('config_groups', None)
group_0 = config_groups.get(0, None) if config_groups else None
weights = group_0.get('weight', None) if group_0 else None
block_size = weights.get('block_size', block_size) if weights else block_size
config_groups = quantization_config.get('config_groups', {})
group_0 = config_groups.get(0, {})
weights = group_0.get('weight', {})
block_size = weights.get('block_size', block_size)
kwargs['block_size'] = block_size
try:
from transformers.integrations.finegrained_fp8 import FP8Linear # This has patched forward pass for LoRA and training support. Patched in unsloth/kernels/fp8.py
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using a bare except: is generally discouraged as it can catch unexpected exceptions (like KeyboardInterrupt or SystemExit) and hide bugs. It's better to catch the specific ImportError that is expected in this case.

Suggested change
except:
except ImportError:
danielhanchen added a commit that referenced this pull request Nov 25, 2025
* Update gpt_oss.py

* torch compile

* Update attention_sink.py

* Update common.py

* Update common.py

* Patches

* Compiled mask creation

* Update attention_sink.py

* Update gpt_oss.py

* Update gpt_oss.py

* Revert

* Update gpt_oss.py

* Update gpt_oss.py

* Fix up

* Update attention_sink.py

* Update attention_sink.py

* Update utils.py

* Update attention_sink.py

* Update attention_sink.py

* Retry

* Update gpt_oss.py

* Update gpt_oss.py

* Fix Flex

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Bug fixes

* Update patching_utils.py

* Update patching_utils.py

* Update patching_utils.py

* Update rl_replacements.py

* Update patching_utils.py

* Update patching_utils.py

* Update patching_utils.py

* flash attn

* Update gpt_oss.py

* Update __init__.py

* Update attention_sink.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* dropout_p

* Update gpt_oss.py

* Update gpt_oss.py

* Update attention_sink.py

* Update gpt_oss.py

* Update gpt_oss.py

* fix

* Update attention_sink.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update loss_utils.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update loss_utils.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Update gpt_oss.py

* Versioning

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Update saving_utils.py

* Fix Gemma 3

* Update misc.py

* Update rl_environments.py

* Update pyproject.toml

* Update rl_environments.py

* Update __init__.py

* Update empty_model.py

* Update empty_model.py

* Update empty_model.py

* Update empty_model.py

* Device type

* Update vllm_utils.py

* Update compiler.py

* Update empty_model.py

* Update vllm_utils.py

* Update empty_model.py

* Fixes

* Update empty_model.py

* Update empty_model.py

* Update __init__.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update rl_environments.py

* Update cross_entropy_loss.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update rl_environments.py

* Update vllm_utils.py

* Qwen3 VL vLLM (#324)

* qwen3 vl additional layers

* qwen3 fused vision qkv

* refactor for handling qwen 3 vl

* [WIP] fix backward pass issues

* out hidden size change

* Qwen 2.5 and qwen 3 conv3d->Linear vLLM changes

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update pyproject.toml

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update __init__.py

* Update compiler.py

* Update __init__.py

* Update vllm_utils.py

* Update rl_replacements.py

* Update rl_replacements.py

* Update rl_replacements.py

* Fix CE compile

* Update loss_utils.py

* Update cross_entropy_loss.py

* Fix

* Deepseekocr fix: save single model shard (#346)

* DeepSeekOCR Fix: check for saftensors_list shard naming convention

* turned off shard padding length check bc deepseeks padding is different

* if you try to copy the index.json file and the same file alredy exists it wil throw and error.

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update patching_utils.py

* Fp8 compressed (#358)

* [WIP] compressed tensors support for FP8

* [WIP 2/n] improve loading fake layer

* [WIP 3/n] improve loading fake layer

* [WIP 4/n] improve loading fake layer

* revert seq and token util calculation

---------

Co-authored-by: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>

* Update vllm_utils.py

* Update vllm_utils.py

* Update vllm_utils.py

* Update gradient_checkpointing.py

* Update gpt_oss.py

* Update gpt_oss.py

* updates for vLLM compativility with lora (#359)

* updates for vLLM compativility with lora

* LoRA extra vocab cleanup

---------

Co-authored-by: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>

* Update vllm_utils.py

* Versioning

---------

Co-authored-by: Datta Nimmaturi <venkatadattasainimmaturi@gmail.com>
Co-authored-by: DoubleMathew <mmathew23@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants