Skip to content

Conversation

jeejeelee
Copy link
Collaborator

@jeejeelee jeejeelee commented Sep 10, 2025

Purpose

Split LoRA layers into separate files to facilitate maintenance and improve readability.

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: Jee Jee Li <[email protected]>
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 refactors the LoRA layers by splitting a large layers.py file into a more organized package structure. This is a great improvement for maintainability. I've found a critical issue that could break support for Marlin quantized models, and a high-severity typo in a new module's name that should be corrected.

Comment on lines +11 to +27
def _get_lora_device(base_layer: nn.Module) -> torch.device:
# code borrowed from https://github.com/fmmoret/vllm/blob/fm-support-lora-on-quantized-models/vllm/lora/layers.py#L34
"""Returns the device for where to place the LoRA tensors."""
# unquantizedLinear
if hasattr(base_layer, "weight"):
return base_layer.weight.device
# Compressed Tensor
elif hasattr(base_layer, "weight_packed"):
return base_layer.weight_packed.device
# GPTQ/AWQ
elif hasattr(base_layer, "qweight"):
return base_layer.qweight.device
# HQQ marlin
elif hasattr(base_layer, "W_q"):
return base_layer.W_q.device
else:
raise ValueError(f"Unsupported base layer: {base_layer}")
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The _get_lora_device function is missing a check for the B attribute, which is used by Marlin quantized models. This can cause a ValueError when using LoRA with Marlin quantization, as the function would fail to determine the correct device. The weight property in BaseLinearLayerWithLoRA correctly handles this case, and this function should be consistent with it to avoid a regression.

Suggested change
def _get_lora_device(base_layer: nn.Module) -> torch.device:
# code borrowed from https://github.com/fmmoret/vllm/blob/fm-support-lora-on-quantized-models/vllm/lora/layers.py#L34
"""Returns the device for where to place the LoRA tensors."""
# unquantizedLinear
if hasattr(base_layer, "weight"):
return base_layer.weight.device
# Compressed Tensor
elif hasattr(base_layer, "weight_packed"):
return base_layer.weight_packed.device
# GPTQ/AWQ
elif hasattr(base_layer, "qweight"):
return base_layer.qweight.device
# HQQ marlin
elif hasattr(base_layer, "W_q"):
return base_layer.W_q.device
else:
raise ValueError(f"Unsupported base layer: {base_layer}")
def _get_lora_device(base_layer: nn.Module) -> torch.device:
# code borrowed from https://github.com/fmmoret/vllm/blob/fm-support-lora-on-quantized-models/vllm/lora/layers.py#L34
"""Returns the device for where to place the LoRA tensors."""
# unquantizedLinear
if hasattr(base_layer, "weight"):
return base_layer.weight.device
# Compressed Tensor
elif hasattr(base_layer, "weight_packed"):
return base_layer.weight_packed.device
# GPTQ/AWQ
elif hasattr(base_layer, "qweight"):
return base_layer.qweight.device
# marlin
elif hasattr(base_layer, "B"):
return base_layer.B.device
# HQQ marlin
elif hasattr(base_layer, "W_q"):
return base_layer.W_q.device
else:
raise ValueError(f"Unsupported base layer: {base_layer}")

Comment on lines 12 to 14
from vllm.lora.layers.vocal_parallel_embedding import (
VocabParallelEmbeddingWithLoRA,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There appears to be a typo in the module name vocal_parallel_embedding. It should likely be vocab_parallel_embedding to be consistent with the class name VocabParallelEmbeddingWithLoRA and the general terminology. This should be corrected in the filename (vllm/lora/layers/vocal_parallel_embedding.py) and here in the import statement for better code clarity and maintainability.

Suggested change
from vllm.lora.layers.vocal_parallel_embedding import (
VocabParallelEmbeddingWithLoRA,
)
from vllm.lora.layers.vocab_parallel_embedding import (
VocabParallelEmbeddingWithLoRA,
)

@jeejeelee jeejeelee requested a review from Isotr0py September 10, 2025 10:35
Copy link
Member

@Isotr0py Isotr0py Sep 10, 2025

Choose a reason for hiding this comment

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

Should we also break this file's implementations into column_parallel_linear.py and row_parallel_linear.py etc to keep them in same file with parent class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense

Signed-off-by: Jee Jee Li <[email protected]>
Copy link
Member

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM!

Signed-off-by: Jee Jee Li <[email protected]>
@jeejeelee jeejeelee added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 10, 2025
@vllm-bot vllm-bot merged commit bb3eb80 into vllm-project:main Sep 10, 2025
48 of 50 checks passed
@jeejeelee jeejeelee deleted the split-lora-layer branch September 10, 2025 14:51
skyloevil pushed a commit to skyloevil/vllm that referenced this pull request Sep 13, 2025
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants