Skip to content

CI fails for Python 3.9: ValueError: zero-size array to reduction operation maximum which has no identity #4308

@albertvillanova

Description

@albertvillanova

CI fails for Python 3.9: https://github.com/huggingface/trl/actions/runs/18605452485/job/53053774127

ValueError: zero-size array to reduction operation maximum which has no identity

FAILED tests/test_online_dpo_trainer.py::TestOnlineDPOTrainer::test_training_with_transformers_paged_0_standard_prompt_only - ValueError: zero-size array to reduction operation maximum which has no identity
FAILED tests/test_online_dpo_trainer.py::TestOnlineDPOTrainer::test_training_with_transformers_paged_1_conversational_prompt_only - ValueError: zero-size array to reduction operation maximum which has no identity

Stacktrace:

tests/test_online_dpo_trainer.py:453: in test_training_with_transformers_paged
    trainer.train()
.venv/lib/python3.9/site-packages/transformers/trainer.py:2325: in train
    return inner_training_loop(
.venv/lib/python3.9/site-packages/transformers/trainer.py:2674: in _inner_training_loop
    tr_loss_step = self.training_step(model, inputs, num_items_in_batch)
trl/trainer/online_dpo_trainer.py:1280: in training_step
    prompt_ids, prompt_mask, completion_ids, completion_mask = self._generate(model, prompts, images)
trl/trainer/online_dpo_trainer.py:1128: in _generate
    completion_ids = pad(completion_ids, padding_value=self.pad_token_id, padding_side="right")
trl/trainer/utils.py:348: in pad
    output_shape = np.max([t.shape for t in tensors], 0).tolist()
.venv/lib/python3.9/site-packages/numpy/_core/fromnumeric.py:2899: in max
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

obj = [], ufunc = <ufunc 'maximum'>, method = 'max', axis = 0, dtype = None
out = None
kwargs = {'initial': <no value>, 'keepdims': <no value>, 'where': <no value>}
passkwargs = {}

    def _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs):
        passkwargs = {k: v for k, v in kwargs.items()
                      if v is not np._NoValue}
    
        if type(obj) is not mu.ndarray:
            try:
                reduction = getattr(obj, method)
            except AttributeError:
                pass
            else:
                # This branch is needed for reductions like any which don't
                # support a dtype.
                if dtype is not None:
                    return reduction(axis=axis, dtype=dtype, out=out, **passkwargs)
                else:
                    return reduction(axis=axis, out=out, **passkwargs)
    
>       return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
E       ValueError: zero-size array to reduction operation maximum which has no identity

.venv/lib/python3.9/site-packages/numpy/_core/fromnumeric.py:86: ValueError

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions