Skip to content

Transformers crashes mypy #13390

Closed
python/mypy
#12023
@davidhewitt

Description

@davidhewitt

Ubuntu 21.04, tested on both Python 3.8 and Python 3.9 with mypy 0.910

I get a crash caused by transformers 4.10.0 when typechecking a private codebase which imports transformers. This is the error message:

src/transformers/trainer.py:1435: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.910

(I also get the crash trying mypy master. I'm going to submit a corresponding bug report directly to the mypy issue tracker.)

This is the corresponding line:

logs["learning_rate"] = self._get_learning_rate()

That method is imported into the class, which presumably upsets mypy somehow.

Repro

I can reproduce this locally in the following way:

  1. Clone the transformers repo
  2. Create a blank virtualenv and install mypy 0.910
  3. Add the following mypy.ini file:
    [mypy]
    check_untyped_defs=True
    
  4. Run mypy src/transformers/trainer.py

Confusingly, this local repro method also crashes mypy when using the 4.9.1 tag, but I don't experience the crash in my private codebase when using that transformers version 🤷

cc @sgugger

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions