# Fine Tuning Llava 1.5 7b for Classification

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-llava-1-5-7b-for-classification%2F152433%3E%5C
**Category:** 🤗Transformers\
**Created:** [April 26, 2025, 6:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-llava-1-5-7b-for-classification%2F152433 "2025-04-26T18:29:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kallyy](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kallyy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkallyy)%5C
**Post date:** [April 26, 2025, 6:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-llava-1-5-7b-for-classification%2F152433%2F1 "2025-04-26T18:29:04Z")

</div>

Hello,  
im working on fine tuning Llava 1.5 7b Classification and VQA

the typical input for the model is a question along with a list of images as answer,  
the model should return 1 if the task has been well executed (the task being the question), 0 otherwise  
I have a decent dataset of around 1400 entries (entry is a single object with question,answer, compliance(being 1 or 0) )…  
my approach was to first fine tune the model for classification, and then use the processor.apply\_chat\_template to generate a justification with a prompt in case the model returned 0  
to be completely honest, I’m still learning all about fine tuning models so I don’t understand 100% of the code , it’s all put together through some basic knowledge, research and the help of chatGPT  
here’s the Cells I’m facing an issue with  
from transformers import DataCollatorForSeq2Seq

text\_collator = DataCollatorForSeq2Seq(  
tokenizer=processor.tokenizer,  
model=model,  
label\_pad\_token\_id=processor.tokenizer.pad\_token\_id,  
)

def data\_collator(features):  
pixel\_vals = [f.pop(“pixel\_values”) for f in features]  
imgs = [torch.stack(x if isinstance(x[0], torch.Tensor) else x[0], dim=0)  
for x in pixel\_vals]  
batch\_pixels = torch.stack(imgs, dim=0)

```
batch = text_collator(features)   
batch["pixel_values"] = batch_pixels
return batch

```

## trainer = Seq2SeqTrainer( model=model, args=training\_args, train\_dataset=train\_ds, eval\_dataset=eval\_ds, data\_collator=data\_collator, compute\_metrics=compute\_metrics, ) trainer.train()

TypeError Traceback (most recent call last)  
/tmp/ipykernel\_31/2454287461.py in \<cell line: 0\>()

----\> 2 trainer.train()

/usr/local/lib/python3.11/dist-packages/transformers/trainer.py in train(self, resume\_from\_checkpoint, trial, ignore\_keys\_for\_eval, \*\*kwargs)  
2243 hf\_hub\_utils.enable\_progress\_bars()  
2244 else:  
 → 2245 return inner\_training\_loop(  
2246 args=args,  
2247 resume\_from\_checkpoint=resume\_from\_checkpoint,

/usr/local/lib/python3.11/dist-packages/transformers/trainer.py in \_inner\_training\_loop(self, batch\_size, args, resume\_from\_checkpoint, trial, ignore\_keys\_for\_eval)  
2512 update\_step += 1  
2513 num\_batches = args.gradient\_accumulation\_steps if update\_step != (total\_updates - 1) else remainder  
 → 2514 batch\_samples, num\_items\_in\_batch = self.get\_batch\_samples(epoch\_iterator, num\_batches, args.device)  
2515 for i, inputs in enumerate(batch\_samples):  
2516 step += 1

/usr/local/lib/python3.11/dist-packages/transformers/trainer.py in get\_batch\_samples(self, epoch\_iterator, num\_batches, device)  
5241 for \_ in range(num\_batches):  
5242 try:  
 → 5243 batch\_samples.append(next(epoch\_iterator))  
5244 except StopIteration:  
5245 break

/usr/local/lib/python3.11/dist-packages/accelerate/data\_loader.py in **iter** (self)  
561 # We iterate one batch ahead to check when we are at the end  
562 try:  
 → 563 current\_batch = next(dataloader\_iter)  
564 except StopIteration:  
565 yield

/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py in **next** (self)  
699 # TODO([Bug in dataloader iterator found by mypy · Issue #76750 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/76750))  
700 self.\_reset() # type: ignore[call-arg]  
 → 701 data = self.\_next\_data()  
702 self.\_num\_yielded += 1  
703 if (

/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py in \_next\_data(self)  
755 def \_next\_data(self):  
756 index = self.\_next\_index() # may raise StopIteration  
 → 757 data = self.\_dataset\_fetcher.fetch(index) # may raise StopIteration  
758 if self.\_pin\_memory:  
759 data = \_utils.pin\_memory.pin\_memory(data, self.\_pin\_memory\_device)

/usr/local/lib/python3.11/dist-packages/torch/utils/data/\_utils/fetch.py in fetch(self, possibly\_batched\_index)  
53 else:  
54 data = self.dataset[possibly\_batched\_index]  
—\> 55 return self.collate\_fn(data)

/tmp/ipykernel\_31/4101348022.py in data\_collator(features)  
9 def data\_collator(features):  
10 pixel\_vals = [f.pop(“pixel\_values”) for f in features]  
—\> 11 imgs = [torch.stack(x if isinstance(x[0], torch.Tensor) else x[0], dim=0)  
12 for x in pixel\_vals]  
13 batch\_pixels = torch.stack(imgs, dim=0)

/tmp/ipykernel\_31/4101348022.py in (.0)  
9 def data\_collator(features):  
10 pixel\_vals = [f.pop(“pixel\_values”) for f in features]  
—\> 11 imgs = [torch.stack(x if isinstance(x[0], torch.Tensor) else x[0], dim=0)  
12 for x in pixel\_vals]  
13 batch\_pixels = torch.stack(imgs, dim=0)

TypeError: expected Tensor as element 0 in argument 0, but got list

---

<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:** [April 27, 2025, 2:39am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-llava-1-5-7b-for-classification%2F152433%2F2 "2025-04-27T02:39:25Z")

</div>

Hmm… This part?

> **[Expected Tensor as element 0 in argument 0, but got list](https://discuss.pytorch.org/t/expected-tensor-as-element-0-in-argument-0-but-got-list/108081)**
>
> I tried to convert tensor to list . But , the error occurred. What is the way to fix it? The value of list contains tensor(\[-0.2667, 0.1658, 0.0294, …, -0.0293, 0.3530, -0.4136\], grad\_fn=), error message emp = torch.stack(\[temp\], dim=1)...

```py
# imgs = [torch.stack(x if isinstance(x[0], torch.Tensor) else x[0], dim=0)
 imgs = [torch.stack([x] if isinstance(x[0], torch.Tensor) else [x[0]], dim=0)
# or torch.tensor ?

```
