Skip to content

Fix the transformers example when running with 4.57.0 #331

@c-bata

Description

@c-bata

Expected behavior

After the release of transformers 4.57.0, the CI related to transformers started failing. To temporarily resolve the issue, I opened a PR to add the version constraint. This issue proposes resolving the failure.

Environment

See https://github.com/optuna/optuna-examples/actions/runs/18260421197/job/51987583269

Error messages, stack traces, or logs

Traceback (most recent call last):
  File "/home/runner/work/optuna-examples/optuna-examples/transformers/transformers_simple.py", line 17, in <module>
    from transformers import Trainer
  File "<frozen importlib._bootstrap>", line 1055, in _handle_fromlist
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 2317, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 2347, in _get_module
    raise e
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 2345, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/site-packages/transformers/trainer.py", line 311, in <module>
    class Trainer:
  File "/opt/hostedtoolcache/Python/3.9.23/x64/lib/python3.9/site-packages/transformers/trainer.py", line 5593, in Trainer
    def _get_num_items_in_batch(self, batch_samples: list, device: torch.device) -> int | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue/PR about behavior that is broken. Not for typos/CI but for example itself.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions