Skip to content

CI fails for Python 3.9 tests: TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' #4208

@albertvillanova

Description

@albertvillanova

CI fails for Tests 3.9: https://github.com/huggingface/trl/actions/runs/18230859667/job/51913590683

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Traceback:

tests/slow/test_dpo_slow.py:24: in <module>
    from transformers.testing_utils import backend_empty_cache, require_peft, require_torch_accelerator, torch_device
.venv/lib/python3.9/site-packages/transformers/testing_utils.py:54: in <module>
    from transformers import Trainer
<frozen importlib._bootstrap>:1055: in _handle_fromlist
    ???
.venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:2317: in __getattr__
    module = self._get_module(self._class_to_module[name])
.venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:2347: in _get_module
    raise e
.venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:2345: in _get_module
    return importlib.import_module("." + module_name, self.__name__)
/__w/_tool/Python/3.9.23/x64/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
.venv/lib/python3.9/site-packages/transformers/trainer.py:311: in <module>
    class Trainer:
.venv/lib/python3.9/site-packages/transformers/trainer.py:5593: in Trainer
    def _get_num_items_in_batch(self, batch_samples: list, device: torch.device) -> int | None:
E   TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

After investigation, it seems transformers-4.57.0 introduced a compatibility issue for Python 3.9 environments in this PR:

The issue has already been reported:

and a fix has been proposed:

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions