Skip to content

[Model] Enable LoRA support for Pixtral#31724

Merged
vllm-bot merged 1 commit intovllm-project:mainfrom
A1c0r-Z:feature/pixtral-lora-support
Jan 8, 2026
Merged

[Model] Enable LoRA support for Pixtral#31724
vllm-bot merged 1 commit intovllm-project:mainfrom
A1c0r-Z:feature/pixtral-lora-support

Conversation

@A1c0r-Z
Copy link
Copy Markdown
Contributor

@A1c0r-Z A1c0r-Z commented Jan 5, 2026

Purpose

Enable LoRA adapters on the vision tower and connector components of Pixtral models (Part of #31479).

Technical Details

  • Implement get_mm_mapping(), get_num_mm_encoder_tokens(), and get_num_mm_connector_tokens().
  • Add SupportsLoRA to PixtralForConditionalGeneration inheritance.
  • Patch Merge Logic: Account for the $S \times S$ (typically $2 \times 2$) patch merging in Pixtral.
    • get_num_mm_encoder_tokens scales up the LLM budget by $S^2$ to match the Vision Tower's raw output.
    • get_num_mm_connector_tokens scales down the raw count by $S^2$ to match the Connector's input after merging.

Part of #31479

FIX #8802

@mergify
Copy link
Copy Markdown

mergify bot commented Jan 5, 2026

Documentation preview: https://vllm--31724.org.readthedocs.build/en/31724/

@mergify mergify bot added the documentation Improvements or additions to documentation label Jan 5, 2026
Copy link
Copy Markdown
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 enables LoRA support for the vision tower and connector components of Pixtral models. The changes include adding the SupportsLoRA interface to PixtralForConditionalGeneration and implementing the necessary methods for LoRA integration with multi-modal components, such as get_mm_mapping, get_num_mm_encoder_tokens, and get_num_mm_connector_tokens. My review found a critical issue in the implementation of get_mm_mapping that would prevent LoRA from being applied correctly. I've provided a suggestion to fix it.

@mergify
Copy link
Copy Markdown

mergify bot commented Jan 5, 2026

Hi @A1c0r-Z, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

@A1c0r-Z A1c0r-Z force-pushed the feature/pixtral-lora-support branch 2 times, most recently from dc5cf7f to 15d574c Compare January 5, 2026 22:37
@A1c0r-Z A1c0r-Z force-pushed the feature/pixtral-lora-support branch 2 times, most recently from 57957a5 to 383d556 Compare January 7, 2026 00:10
@jeejeelee
Copy link
Copy Markdown
Collaborator

Thank you for contribution, have you tested it locally?

@heheda12345 heheda12345 requested a review from jeejeelee January 7, 2026 06:40
@jeejeelee jeejeelee self-assigned this Jan 7, 2026
@A1c0r-Z
Copy link
Copy Markdown
Contributor Author

A1c0r-Z commented Jan 7, 2026

Thank you for contribution, have you tested it locally?

Yes, I have tested it locally using a "probe test" method.

I inserted debug print statements into the Pixtral model definition to verify that the token counts calculated by the new get_num_mm_* methods strictly match the actual tensor shapes observed during the forward pass (_process_image_input).

Here is the test detail:

1. Methodology

I instrumented the code to print:

  • Calculated Values: The output of get_num_mm_encoder_tokens and get_num_mm_connector_tokens.
  • Runtime Shapes: The actual tensor shapes before and after the patch_merger layer in _process_image_input.
# Instrumentation Logic
def get_num_mm_encoder_tokens(self, num_image_tokens: int) -> int:
    # ... logic ...
    print(f"[DEBUG PROBE encoder]: {calculated_val}")
    return calculated_val

def get_num_mm_connector_tokens(self, num_vision_tokens: int) -> int:
    # ... logic ...
    print(f"[DEBUG PROBE connector]: {calculated_val}")
    return calculated_val

def _process_image_input(self, ...):
    # ...
    image_features = self.vision_encoder(images)
    print(f"[DEBUG PROBE 1] Vision Encoder Output Shape: {image_features[0].shape}")
    
    if self.patch_merger is not None:
         image_features = self.patch_merger(...)
         
    print(f"[DEBUG PROBE 2] Shape BEFORE connector: {image_features.shape}")
    # ...

2. Test Case A: mistralai/Pixtral-12B-2409 (No Patch Merger)

This model does not use a patch merger, so the mapping should be 1:1.

Startup Profile:

(EngineCore_DP0) [DEBUG PROBE encoder]: 4096
(EngineCore_DP0) [DEBUG PROBE connector]: 4096
(EngineCore_DP0) [DEBUG PROBE 1] Vision Encoder Output Shape: torch.Size([4096, 1024])
(EngineCore_DP0) [DEBUG PROBE 2] Shape BEFORE connector: torch.Size([4096, 1024])

Inference (Small Image):

(EngineCore_DP0) [DEBUG PROBE encoder]: 16
(EngineCore_DP0) [DEBUG PROBE connector]: 16
(EngineCore_DP0) [DEBUG PROBE 1] Vision Encoder Output Shape: torch.Size([16, 1024])
(EngineCore_DP0) [DEBUG PROBE 2] Shape BEFORE connector: torch.Size([16, 1024])

Result: The calculated budget matches the runtime tensor shape perfectly (Identity).

3. Test Case B: mistralai/Ministral-3-3B-Instruct-2512 (With Patch Merger)

This model uses a 2x2 patch merger, so the encoder tokens should be the connector tokens.

Startup Profile:

(EngineCore_DP0) [DEBUG PROBE encoder]: 12100
(EngineCore_DP0) [DEBUG PROBE connector]: 3025
(EngineCore_DP0) [DEBUG PROBE 1] Vision Encoder Output Shape: torch.Size([12100, 1024])
(EngineCore_DP0) [DEBUG PROBE 2] Shape BEFORE connector: torch.Size([3025, 1024])

Note: . The calculation is correct.

Inference (Small Image):

(EngineCore_DP0) [DEBUG PROBE encoder]: 16
(EngineCore_DP0) [DEBUG PROBE connector]: 4
(EngineCore_DP0) [DEBUG PROBE 1] Vision Encoder Output Shape: torch.Size([16, 1024])
(EngineCore_DP0) [DEBUG PROBE 2] Shape BEFORE connector: torch.Size([4, 1024])

Copy link
Copy Markdown
Collaborator

@jeejeelee jeejeelee left a comment

Choose a reason for hiding this comment

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

Thank you

@jeejeelee jeejeelee added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 8, 2026
@jeejeelee jeejeelee enabled auto-merge (squash) January 8, 2026 06:52
auto-merge was automatically disabled January 8, 2026 06:52

Head branch was pushed to by a user without write access

@A1c0r-Z A1c0r-Z force-pushed the feature/pixtral-lora-support branch 2 times, most recently from 115c313 to 383d556 Compare January 8, 2026 07:52
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>

Signed-off-by:  <>
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>
Signed-off-by: 赵策 <alcor@mac.mynetworksettings.com>
@A1c0r-Z A1c0r-Z force-pushed the feature/pixtral-lora-support branch from 383d556 to 471bfb0 Compare January 8, 2026 07:53
@vllm-bot vllm-bot merged commit 1123a87 into vllm-project:main Jan 8, 2026
50 of 52 checks passed
yugong333 pushed a commit to yugong333/vllm that referenced this pull request Jan 9, 2026
Signed-off-by: <>
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>
Signed-off-by: 赵策 <alcor@mac.mynetworksettings.com>
Co-authored-by: 赵策 <alcor@mac.mynetworksettings.com>
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Jan 16, 2026
Signed-off-by: <>
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>
Signed-off-by: 赵策 <alcor@mac.mynetworksettings.com>
Co-authored-by: 赵策 <alcor@mac.mynetworksettings.com>
dsuhinin pushed a commit to dsuhinin/vllm that referenced this pull request Jan 21, 2026
Signed-off-by: <>
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>
Signed-off-by: 赵策 <alcor@mac.mynetworksettings.com>
Co-authored-by: 赵策 <alcor@mac.mynetworksettings.com>
Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
ItzDEXX pushed a commit to ItzDEXX/vllm that referenced this pull request Feb 19, 2026
Signed-off-by: <>
Signed-off-by: 赵策 <alcor@zhaocedeMacBook-Air.local>
Signed-off-by: 赵策 <alcor@mac.mynetworksettings.com>
Co-authored-by: 赵策 <alcor@mac.mynetworksettings.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation 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.

[Feature]: LoRA support for Pixtral

3 participants