question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transformers crashes mypy

See original GitHub issue

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:

https://github.com/huggingface/transformers/blob/b91e65afe0f467e24183928bf57d92b2cef4b69f/src/transformers/trainer.py#L1435

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aphedgescommented, Oct 5, 2021

Although I hope mypy fixes the bug on their side, I did some digging into possible workarounds:

  • The transformers commit that causes mypy to crash is d8fb278, which makes sense. Adding a py.typed enabled the type checking, which exposed the bug even though no code was changed in the commit itself. Any commit before it works without issues.
  • If you want to use mypy but are okay with not having transformers type checked, add the following code to mypy.ini:
[mypy-transformers.*]
follow_imports = skip

Hope this helps!

0reactions
phireskycommented, Feb 9, 2022

Just want to mention that the workaround for the newer pyproject.toml-based config files is

[[tool.mypy.overrides]]
follow_imports = "skip"
module = [
  "transformers.*",
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash when typechecking transformers 4.10.0 #11045 - GitHub
Crash Report I am typechecking a codebase which imports transformers 4.10.0 and hitting a mypy internal error.
Read more >
MyPy crashes due to syntax error in underlying modules
I'm trying to run MyPy on my package, but I'm running into issues due to a syntax error in an underlying package, that...
Read more >
PC crashes and turns off when using large hidden size - PyTorch ...
Hello, I'm trying to replicate the ViT paper: [2010.11929] An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale I've reproduced...
Read more >
Python Type Checking (Guide) - Real Python
The most common tool for doing type checking is Mypy though. ... If you try to run the reveal.py file as a Python...
Read more >
Static type checking(with mypy): What's the official position?
Type annotation is half-there, half-not-there, mainly because the transformers library used to support python 2.7. For instance a new file like ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found