vllm - 💡(How to fix) Fix [Usage]: Improve error handling when task='classify' is used with decoder-only models (e.g., Qwen, Llama, Mistral) [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#37649Fetched 2026-04-08 01:04:22
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
commented ×2labeled ×1mentioned ×1referenced ×1

Error Message

ValueError: Following weights were not initialized from checkpoint: {'score.weight'} RuntimeError: Engine core initialization failed. See root cause above. Failed core proc(s): {}

Root Cause

ValueError: Following weights were not initialized from checkpoint: {'score.weight'}
RuntimeError: Engine core initialization failed. See root cause above. Failed core proc(s): {}

Code Example

ValueError: Following weights were not initialized from checkpoint: {'score.weight'}
RuntimeError: Engine core initialization failed. See root cause above. Failed core proc(s): {}

---

from vllm import LLM, SamplingParams
prompts = ['hello']
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=1024, stop=[])
llm = LLM(model='Qwen/Qwen2.5-0.5B-Instruct', enable_lora=True, task='classify')
outputs = llm.generate(prompts, sampling_params)

---

ValueError: The 'classify' task is only supported for encoder or encoder-decoder models 
(e.g., BERT, DeBERTa, T5). The model 'Qwen/Qwen2.5-0.5B-Instruct' uses a decoder-only 
architecture (Qwen2ForCausalLM) and does not include a classification head. 
Consider using prompt-based classification instead, or switch to a model trained for classification.

---

# Pseudocode
if task == "classify" and "CausalLM" in model_config.architectures:
    raise ValueError("task='classify' is not supported for decoder-only models...")
RAW_BUFFERClick to expand / collapse

Your current environment

Title:
Improve error handling when task='classify' is used with decoder-only models (e.g., Qwen, Llama, Mistral)

Body:

🐞 Problem Description

When initializing an LLM instance with task='classify' on a decoder-only causal language model (such as Qwen/Qwen2.5-0.5B-Instruct, meta-llama/Llama-3-8B, or mistralai/Mistral-7B-v0.1), vLLM fails during model loading with a cryptic error:

ValueError: Following weights were not initialized from checkpoint: {'score.weight'}
RuntimeError: Engine core initialization failed. See root cause above. Failed core proc(s): {}

This occurs because:

  • The task='classify' option triggers the use of a classification head (score layer).
  • However, standard Causal LM checkpoints (like those from Qwen, Llama, Mistral) do not contain a score.weight parameter, as they are not trained for sequence classification.
  • vLLM attempts to construct a model with this missing head and only fails at weight-loading time.

🔁 Reproduction Code

from vllm import LLM, SamplingParams
prompts = ['hello']
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=1024, stop=[])
llm = LLM(model='Qwen/Qwen2.5-0.5B-Instruct', enable_lora=True, task='classify')
outputs = llm.generate(prompts, sampling_params)

Note: Same issue occurs with meta-llama/Llama-3-8B, mistralai/Mistral-7B-v0.1, etc.

✅ Expected Behavior

vLLM should validate compatibility between task and model architecture early (e.g., in LLM.__init__ or engine args parsing) and raise a clear, actionable error such as:

ValueError: The 'classify' task is only supported for encoder or encoder-decoder models 
(e.g., BERT, DeBERTa, T5). The model 'Qwen/Qwen2.5-0.5B-Instruct' uses a decoder-only 
architecture (Qwen2ForCausalLM) and does not include a classification head. 
Consider using prompt-based classification instead, or switch to a model trained for classification.

💡 Suggested Fix

Check the model’s architecture before enabling classification mode:

# Pseudocode
if task == "classify" and "CausalLM" in model_config.architectures:
    raise ValueError("task='classify' is not supported for decoder-only models...")

Additionally, the documentation for the task parameter should explicitly list supported model types.

📌 Context

  • vLLM version: 0.12.0
  • Model: Qwen/Qwen2.5-0.5B-Instruct (but affects all Causal LMs)
  • Use case: User mistakenly assumed task='classify' works for any model; better guardrails would improve UX.

Feel free to adjust the tone or add more details, but this version clearly explains the problem, provides reproducible code, proposes a solution, and aligns with vLLM’s goal of being user-friendly and robust.

Let me know if you'd like a Chinese version or help submitting it!

How would you like to use vllm

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

extent analysis

Fix Plan

To address the issue, we need to add a check in the LLM class's __init__ method to validate the compatibility between the task parameter and the model architecture. Here are the steps:

  • Check if the task is set to 'classify' and if the model architecture is a decoder-only causal language model.
  • If the conditions are met, raise a ValueError with a clear and actionable error message.
  • Update the documentation for the task parameter to explicitly list supported model types.

Code Changes

class LLM:
    def __init__(self, model, enable_lora, task):
        #... existing code...
        if task == 'classify' and 'CausalLM' in model_config.architectures:
            raise ValueError(
                "The 'classify' task is only supported for encoder or encoder-decoder models "
                "(e.g., BERT, DeBERTa, T5). The model '{}' uses a decoder-only "
                "architecture and does not include a classification head. "
                "Consider using prompt-based classification instead, or switch to a model trained for classification.".format(model)
            )
        #... existing code...

Verification

To verify the fix, you can run the following code:

from vllm import LLM, SamplingParams

prompts = ['hello']
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=1024, stop=[])
try:
    llm = LLM(model='Qwen/Qwen2.5-0.5B-Instruct', enable_lora=True, task='classify')
    outputs = llm.generate(prompts, sampling_params)
except ValueError as e:
    print(e)

This should raise a ValueError with the expected error message.

Extra Tips

  • Make sure to update the documentation for the task parameter to reflect the supported model types.
  • Consider adding a warning or info message when the task parameter is set to 'classify' and the model architecture is not supported, to provide a better user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

vllm - 💡(How to fix) Fix [Usage]: Improve error handling when task='classify' is used with decoder-only models (e.g., Qwen, Llama, Mistral) [2 comments, 2 participants]