Skip to content

Support BatchFeature in LengthGroupedSampler for Multimodal compatibility #42760

@npurson

Description

@npurson

Feature request

I am currently fine-tuning a multimodal model (Qwen2.5-VL) using the official Trainer. The training fails during the dataset length inference step in LengthGroupedSampler because the code strictly checks for dict or BatchEncoding, but multimodal processors often return BatchFeature.

Specifically, the following check raises a ValueError:

if not isinstance(dataset[0], (dict, BatchEncoding)) or model_input_name not in dataset[0]:

if not isinstance(dataset[0], (dict, BatchEncoding)) or model_input_name not in dataset[0]:

Motivation

As above.

Your contribution

Simply adding BatchFeature in the type check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions