Skip to content

Fix the transformers example when running with 4.57.0 #331

Closed

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'

Activity

  1. added
    bug
    on Oct 6, 2025
  2. ParagEkbote commented on Oct 7, 2025

    @ParagEkbote
    Contributor

    Looks like there was a breaking change while refactoring and a patch version should be released soon.

    Reference PR

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions