# How to run Trainer + vLLM on Quantized LLMs?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%3E%5C
**Category:** Beginners\
**Created:** [March 31, 2025, 2:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207 "2025-03-31T14:05:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AllIllusion](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@AllIllusion](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAllIllusion)%5C
**Post date:** [March 31, 2025, 2:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F1 "2025-03-31T14:05:09Z")

</div>

Hi everyone, I am a beginner of the Mini-R1, trying to play the Countdown task with GRPOTrainer and vLLM, however, always fail whenever applying quantization.

The code works well for:

> > accelerate + DeepSpeed + + Qwen2.5 + vLLM  
> > accelerate + + PEFT + + Qwen2.5 + vLLM  
> > accelerate + + PEFT + Quantize 4bit + Qwen2.5

When “accelerate + PEFT + Quantize 4bi + Qwen2.5 + vLLM”, I always get error:  
`[rank0]: File "/opt/Miniconda3/lib/python3.12/site-packages/vllm/model_executor/layers/linear.py", line 1008, in weight_loader [rank0]: assert param_data.shape == loaded_weight.shape`

Anyone can help me with it, please?

Any tutorial to make SFTTrainer with vLLM on Quantized LLMs, please?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 31, 2025, 2:46pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F2 "2025-03-31T14:46:17Z")

</div>

It seems it doesn’t supported for now…

> <https://github.com/huggingface/trl/issues/3125>
>
> \### Feature request
> 
> I saw another issue #3054 mentioning how the GRPO Config do…es not support all vLLM parameters. The specific issue I am having is that when I want to a quantized model like \`unsloth/Qwen2.5-7B-Instruct-bnb-4bit\` I am forced to edit the code in the GRPO Trainer where we load the model with vLLM to this:
> \`\`\`
> self.llm = LLM(
> model=model.name\_or\_path,
> device=vllm\_device,
> gpu\_memory\_utilization=self.args.vllm\_gpu\_memory\_utilization,
> dtype=self.args.vllm\_dtype,
> # Automatic Prefix Caching caches the KV cache of existing queries, so that a new query can
> # directly reuse the KV cache if it shares the same prefix with one of the existing queries.
> # This is particularly useful here because we generate completions from the same prompts.
> enable\_prefix\_caching=self.args.vllm\_enable\_prefix\_caching,
> max\_model\_len=self.args.vllm\_max\_model\_len,
> quantization="bitsandbytes", 
> load\_format="bitsandbytes",
> )
> \`\`\`
> 
> per this \[unsloth issue\](https://github.com/unslothai/unsloth/issues/960#issuecomment-2395887281) otherwise I get \`KeyError: 'layers.0.mlp.down\_proj.weight'\`. I saw \[#2728 comment\](https://github.com/huggingface/trl/pull/2728#issuecomment-2635166424) so maybe something similar could be done here where we pass some quantization config to vLLM.
> 
> \### Motivation
> 
> I want to be able to use quantized models with vLLM and GRPO without modifying the trainer myself, but rather by passing in some configs.
> 
> \### Your contribution
> 
> Add the arguments \`vllm\_quantization\` and \`vllm\_load\_format\` similarly to \[this pr\](https://github.com/huggingface/trl/pull/2728/files). I saw some discussion in the same PR suggesting \`vllm\_init\_kwargs\` e.g. \[this comment\](https://github.com/huggingface/trl/pull/2728#issuecomment-2629328181) but I do not see it in the merged PR. This approach seems fine as well.

And GRPO vLLM related issues:

> <https://github.com/huggingface/trl/issues/2922>
>
> https://github.com/huggingface/trl/blob/e5ae703d352b29537159180087ef8bd4b41bf625…/trl/trainer/grpo\_trainer.py#L439-L461
> 
> In the current GRPO implementation, VLLM can only run on a single GPU, which becomes a performance bottleneck. For example, in an 8-GPU setup, the remaining 7 GPUs have to wait for 1 GPU to complete inference, and it also can't accommodate larger models.
> 
> How can we enable VLLM to run on multiple GPUs? The only concern is that we need to figure out a way to update the parameters across multiple GPUs each time the model is reloaded:
> 
> https://github.com/huggingface/trl/blob/e5ae703d352b29537159180087ef8bd4b41bf625/trl/trainer/grpo\_trainer.py#L624-L653

> <https://github.com/huggingface/trl/issues/2706>
>
> \### Feature request
> 
> It seems that the vLLM device can only be set in \[GRPOConfi…g.vllm\_device\](https://github.com/huggingface/trl/blob/main/trl/trainer/grpo\_config.py#L130), which is a string corresponding to a CUDA device identifier. I think this implies that the vLLM device can only use a single GPU, which can be a bottleneck for RL. It is also possible to use a subset by setting the CUDA\_VISIBLE\_DEVICE environment variable, but this might break TRL. Is there a more convenient way to specify multiple GPUs in a single node for training (or any hacks that would work now)? Furthermore, there might need to be more detailed configurations for multi-node vLLM/GPRO training runs.
> 
> \### Motivation
> 
> Enhance training efficiency for RL with \>single GPU sampling.
> 
> \### Your contribution
> 
> N/A

---

<div class="post-metadata">

**Author:** ![AllIllusion](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@AllIllusion](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAllIllusion)%5C
**Post date:** [March 31, 2025, 3:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F3 "2025-03-31T15:03:18Z")

</div>

Any tutorial teaching how to modify the configuration file can also help, please.

I saw that the vLLM official website said they support Quantized LLM with PEFT, however, wasn’t able to find any tutorial teaching how to modify the existing Trainer. 😅

Even not with GRPOTrainer, any tutorial teaching how to make the SFTTrainer work can also help, please

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 31, 2025, 3:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F4 "2025-03-31T15:32:19Z")

</div>

I can’t find a tutorial or reference either…🤔  
Is it possible that the only way to train is with Transformers or other libraries…?  
If you’re looking for speed, you could check out unsloth’s training tools.

---

<div class="post-metadata">

**Author:** ![AllIllusion](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@AllIllusion](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAllIllusion)%5C
**Post date:** [March 31, 2025, 6:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F5 "2025-03-31T18:12:12Z")

</div>

Unfortunately, unsloth does not seem to offer free service for DDP. 🫠

---

<div class="post-metadata">

**Author:** ![watermeleon](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@watermeleon](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fwatermeleon)%5C
**Post date:** [October 23, 2025, 9:51am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-run-trainer-vllm-on-quantized-llms%2F148207%2F7 "2025-10-23T09:51:20Z")

</div>

As I stumbled upon this post twice now, so wanted to share another source I found. From the vLLM documentation it seems this should be possible now.

> **[BitsAndBytes - vLLM](https://docs.vllm.ai/en/latest/features/quantization/bnb.html#openai-compatible-server)**

However, I am also still figuring this out so would love to get other reference implementations 🙂  
From what I gather you can either 1) use a HF model\_name for an existing model that is already quantized (e.g. `model_id = "unsloth/tinyllama-bnb-4bit"`))or 2) update vLLM package and use it as a parameter, but I think you will have to modify your TRL package a bit to support this argument.

```auto
import torch
model_id = "huggyllama/llama-7b"
llm = LLM(
    model=model_id,
    dtype=torch.bfloat16,
    trust_remote_code=True,
    quantization="bitsandbytes",
)

```
