Skip to content

Validation during training for VLMs? #1341

Closed

Description

@benjamin-marie

Is eval_dataset in the SFTTrainer supported by Unsloth for VLMs?

When I fine-tune Qwen2-VL and pass an evaluation dataset

trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    data_collator = UnslothVisionDataCollator(model, tokenizer), # Must use!
    train_dataset = dataset_train,
    eval_dataset = dataset_validation,
    args = training_args
)

it triggers this error when it reaches the evaluation steps:

[/usr/local/lib/python3.10/dist-packages/transformers/trainer.py](https://localhost:8080/#) in compute_loss(self, model, inputs, return_outputs, num_items_in_batch)
   3652         else:
   3653             if isinstance(outputs, dict) and "loss" not in outputs:
-> 3654                 raise ValueError(
   3655                     "The model did not return a loss from the inputs, only the following keys: "
   3656                     f"{','.join(outputs.keys())}. For reference, the inputs it received are {','.join(inputs.keys())}."

ValueError: The model did not return a loss from the inputs, only the following keys: logits. For reference, the inputs it received are input_ids,attention_mask,pixel_values,image_grid_thw,labels.

I processed the evaluation dataset the same way as the training dataset (as in Unsloth's notebooks for VLMs).

Activity

  1. danielhanchen commented on Nov 28, 2024

    @danielhanchen
    Member

    @Erland366 Could you investigate this :) Thanks!

  2. Erland366 commented on Nov 29, 2024

    @Erland366
    Collaborator

    will check it

  3. Erland366 commented on Dec 1, 2024

    @Erland366
    Collaborator

    it's working fine in my local. I just updated my environment since my previous environment is not working at all. Can you try updating your environment?

  4. benjamin-marie commented on Dec 1, 2024

    @benjamin-marie
    Author

    Thanks for the update.
    Ok, I will try!

  5. danielhanchen commented on Jun 17, 2026

    @danielhanchen
    Member

    This should be supported now - sorry on the delay - please update with uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir - if it's still not working, please open another issue - appreciate it again!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions