Skip to content

Mypy errors since v4.51.0 #37339

@jc-louis

Description

@jc-louis

@cyyever this is a direct result of #37022 which marked the library as typed.

from typing import reveal_type

from transformers import Trainer, PreTrainedModel

def mypy_errors(trainer: Trainer, model: PreTrainedModel) -> None:
    reveal_type(trainer)
    reveal_type(trainer.train())
    trainer.train()
    model.dequantize()

Using mypy test.py, I get the following errors:

script.py:5: note: Revealed type is "def (*args: Any, **kwargs: Any) -> transformers.utils.dummy_pt_objects.Trainer"
script.py:8: note: Revealed type is "transformers.utils.dummy_pt_objects.Trainer"
script.py:9: error: "Trainer" has no attribute "train"  [attr-defined]
script.py:9: note: Revealed type is "Any"
script.py:10: error: "Trainer" has no attribute "train"  [attr-defined]
script.py:11: error: "PreTrainedModel" has no attribute "dequantize"  [attr-defined]

Theses errors are false positives, it seems like there is a config issue, all types are pulled from dummy_pt_objects.py


  • transformers version: 4.51.0
  • Platform: macOS-14.7.3-arm64-arm-64bit
  • Python version: 3.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions