Skip to content

[Transformers backend] Serve Llama with the Transformers modeling backend - #66547

Draft
hmellor wants to merge 9 commits into
vllm-project:mainfrom
hmellor:transformers-backend-llama
Draft

hmellor wants to merge 9 commits into
vllm-project:mainfrom
hmellor:transformers-backend-llama

Conversation

@hmellor

@hmellor hmellor commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Overview

Serve Llama with the Transformers modeling backend. vllm/model_executor/models/llama.py moves to vllm/model_executor/layers/llama.py, kept only for the models that still build on the native Llama classes. Draft until the gaps below are closed. Tracked in #67003.

Claims

  • LlamaForCausalLM, LLaMAForCausalLM, LlamaModel and MistralModel resolve to the Transformers modeling backend.
  • InternLM3ForCausalLM and IQuestCoderForCausalLM stay native here, importing from vllm/model_executor/layers/llama.py. [Transformers backend] Migrate InternLM3 and IQuestCoder #66416 moves them. [Model] Remove TeleChat2 and TeleChat3 #67035 removes TeleChat2ForCausalLM and TeleChat3ForCausalLM.
  • LlamaBidirectional* stay native here, [Transformers backend] Serve bidirectional Llama with the Transformers modeling backend #67018 moves them.
  • Every module that imported from llama.py (Mistral, Llama 4, Eagle/Eagle3, GLM4, MiniCPM-V, ...) imports from vllm/model_executor/layers/llama.py instead.
  • VLMs built with init_vllm_registered_model call self.language_model(...) instead of self.language_model.model(...), so their text model can be a Transformers modeling backend model (Llava-1.5 fails at startup without this).
  • Phi3-V's text model is the backend's Phi3ForCausalLM, built from a Transformers Phi3Config converted from its remote-code config (it keeps going through the registry, so VLM2Vec still gets the embedding adapter). Kanana-V keeps the native LlamaForCausalLM: its remote-code text config can't be built by the Transformers modeling backend.

Gaps

Validation

B200 bf16 Llama-3.1-8B-Instruct, native vs backend: GSM8K (500q, 5-shot) 0.782 vs 0.790, throughput (1024 in / 256 out) 43.15/43.24/43.15 vs 42.88/43.90/42.73 req/s, latency (bs 1) 0.956 vs 0.913 s. FP8 (compressed-tensors, ModelOpt), FP8 KV cache, W4A16, Quark FP8, GPTQ, AWQ, bitsandbytes, tensorizer, runai_streamer and TP=2 match native on GSM8K.

vllm bench throughput --model meta-llama/Llama-3.1-8B-Instruct --model-impl {vllm,transformers} --input-len 1024 --output-len 256 --num-prompts 1000

Passing on this branch: test_registry, test_config, test_common (Llama), and test_initialization for every Llama arch and native Llama dependent (Mistral, Llama 4, Eagle/Eagle3, GLM4, Jina v5, MiniCPM-V, Idefics3, LlamaBidirectional*) and every VLM whose language_model.model(...) call changed (50 passed after merging main; Eagle2.5 fails only because it's gated). InternLM3, IQuestCoder, TeleChat2/3 and IQuestLoopCoder pass test_initialization natively on this branch. Llava-1.5 generates correctly and passes multimodal test_common. Phi-3-vision-128k-instruct generates the same greedy text as main for an image and a text prompt.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

🤖 Generated with Claude Code

…kend

Move `LlamaForCausalLM`, `LLaMAForCausalLM`, `LlamaModel` and `MistralModel`
to the Transformers modeling backend. Rename `llama.py` to `llama_layers.py`
for the models that still build on the native Llama classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify

mergify Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

@mergify mergify Bot added documentation Improvements or additions to documentation ci/build llama Related to Llama models mistral Related to Mistral models new-model Requests to new models glm speculative-decoding kv-connector labels Nov 9, 2026
hmellor and others added 2 commits November 9, 2026 10:59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify mergify Bot added cohere Related to Cohere models qwen Related to Qwen models kimi labels Nov 9, 2026
hmellor and others added 2 commits November 9, 2026 11:22
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
…ers modeling backend

These need huggingface/transformers#50477.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify

mergify Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hmellor.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 9, 2026
hmellor and others added 2 commits November 10, 2026 11:55
…d-llama

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

# Conflicts:
#	vllm/model_executor/models/phi3.py
Phi3 moved to the backend in vllm-project#66559, so convert the remote config to a
Transformers Phi3Config rather than pinning a native architecture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@mergify

mergify Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @hmellor.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Their move to the Transformers modeling backend lands in vllm-project#66416 instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build cohere Related to Cohere models documentation Improvements or additions to documentation glm kimi kv-connector llama Related to Llama models mistral Related to Mistral models needs-rebase new-model Requests to new models qwen Related to Qwen models speculative-decoding

Projects

Development

Successfully merging this pull request may close these issues.

1 participant