Skip to content

chore(typing): initial ty integration#43396

Closed
tarekziade wants to merge 23 commits intohuggingface:mainfrom
tarekziade:tarekziade-ty
Closed

chore(typing): initial ty integration#43396
tarekziade wants to merge 23 commits intohuggingface:mainfrom
tarekziade:tarekziade-ty

Conversation

@tarekziade
Copy link
Copy Markdown
Collaborator

What does this PR do?

Initial ty integration. To avoid a gigantic, risky patch, let's start with a baby step where we add the tooling to make repo-check and activate it on a subset of the repo.

That gives us a human-readable patch, and allows us to get confortable with the tool before we expand it.

This patch:

  • adds ty to make repo-check and the CI
  • runs only against src/transformers/utils
  • has a large list of ignores in its configuration for now, that we will loosen later

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43396&sha=6cce79

Copy link
Copy Markdown
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALright! Happy to start with ty! Asked quite a few questions in comments more for my understanding and get familiar with ty than anything else

Comment thread src/transformers/utils/backbone_utils.py Outdated
Comment thread src/transformers/utils/chat_template_utils.py Outdated
Comment thread src/transformers/utils/chat_template_utils.py Outdated
Comment thread src/transformers/utils/generic.py
Comment thread src/transformers/utils/doc.py Outdated
Comment on lines -171 to +172
account_id = os.getenv("TRAINING_JOB_ARN").split(":")[4] if "TRAINING_JOB_ARN" in os.environ else None
training_job_arn = os.getenv("TRAINING_JOB_ARN")
account_id = training_job_arn.split(":")[4] if training_job_arn is not None else None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason of ty complaining on this one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly-missing-attributebecause os.getenv can return None and ty can't know that the in os.environ check is similar. I think it's a pretty reasonable tradeoff, we remove that uncertainty by storing the getenv() value

Comment on lines +543 to +544
if hasattr(torch.backends, "fp32_precision"):
torch.backends.fp32_precision = precision_mode
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seem to require a lot of existence checks. Do you know how they are chosen to be required or not? Does ty base itself e.g. on your currently installed version of torch in the env? Because that may become an issue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this very specific case ty can't infere the existence of this attributes:

  • At runtime, torch.backends module replaces itself with a GenericModule instance (line 122 in torch/backends/init.py)
  • GenericModule defines fp32_precision as a ContextProp descriptor (lines 116-119)
  • However, there's no .pyi stub file for torch.backends, so type checkers can't see that the attribute exists

Does ty base itself e.g. on your currently installed version of torch in the env?

yes it uses its stubs

Comment thread src/transformers/utils/notebook.py Outdated
Comment thread src/transformers/utils/quantization_config.py Outdated
@tarekziade
Copy link
Copy Markdown
Collaborator Author

ALright! Happy to start with ty! Asked quite a few questions in comments more for my understanding and get familiar with ty than anything else

Thanks for the first pass!

one remark about the assert is not None checks:

it's all the same pattern:

  • a class has an attribute it sets to None in its constructor
  • a method B makes the assumption is has another value than None, set by another method A

So it makes sense for a type checker to detect that one possible code execution pass is to call B with no previous call to A. Adding assertions like this is the simplest non intrusive fix. With no assertions, we need to refactor the class so calls to B can't happen before calls to A by design.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

[For maintainers] Suggested jobs to run (before merge)

run-slow: dia, whisper

@tarekziade
Copy link
Copy Markdown
Collaborator Author

run-slow: dia, whisper

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

This comment contains run-slow, running the specified jobs:

models: ["models/dia", "models/whisper"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN b98e83f4 merge commit
PR 3556795b branch commit
main 0b2900dd base commit

✅ No failing test specific to this PR 🎉 👏 !

@tarekziade
Copy link
Copy Markdown
Collaborator Author

tarekziade commented Feb 20, 2026

supersed by #44167
(which is a branch in the same repo for convenency)

@tarekziade tarekziade closed this Feb 20, 2026
@tarekziade tarekziade deleted the tarekziade-ty branch February 20, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants