Skip to content

Remove upstream partial transformers stubs #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented May 28, 2025

Upstreamed at huggingface/transformers#38335

I'm not entirely certain if it's worth mentioning in the Upstreamed libraries section given how tiny the stub was. Up to you.

…into Remove-upstream-partial-transformers-stubs
@debonte debonte merged commit ba1968b into microsoft:main May 28, 2025
8 checks passed
@Avasam Avasam deleted the Remove-upstream-partial-transformers-stubs branch May 28, 2025 23:18
@isaac-mcfadyen
Copy link

Hey 👋

I'm a user of Pylance and would like to +1 the request for putting in the Upstreamed libraries section of the README here.

I am currently hitting this old issue (microsoft/pylance-release#1258) which was resolved by adding type stubs in this package.

I'm guessing that they've been removed from this repo and added to Transformers but a new version of Transformers with the stubs hasn't been published yet (meaning there's probably a small limbo period where that old issue will occur), so it might be good to mention just in case anyone else runs into this in the next few days.

@Avasam
Copy link
Contributor Author

Avasam commented May 31, 2025

I could've kept this as draft until next transformers release since some type information is lost atm.

Right now as a quick fix you could install these stubs on the commit right before the partial transformers stubs were removed: pip install git+https://github.com/microsoft/python-type-stubs@aaa9f03e47df046345e6d17cea5a0ae1c53d1af7 if you really see a difference.

That would also cause pyright and mypy to find the stubs. Not just Pylance.

Looking at microsoft/pylance-release#1258 (comment) , I could not replicate those numbers, at most I got ~800ms
Similarly concerning huggingface/transformers#38335 (comment)

(Unless I just restarted the language server, but then, partial stubs or not, the initial run does take a lot more time, indeed 4-6s, because with from transformers import AutoTokenizer instead of from transformers.models.auto.tokenization_auto import AutoTokenizer analysis has to be run on a lot more files due to all the re-exports before pyright/pylance even finds the AutoTokenizer symbol)

@isaac-mcfadyen
Copy link

isaac-mcfadyen commented May 31, 2025

Interesting, perhaps my issue is something else then?

I also saw the initial ~3000ms at server reload, and then it looks like the language server is getting killed because of a timeout:

2025-05-31 14:02:42.911 [info] [Info  - 2:02:42 PM] (1492239) BG: [BG(1)] Long operation: binding: file:///data/PROJECT/.venv/lib/python3.12/site-packages/transformers/models/__init__.py (3385ms)
2025-05-31 14:02:42.917 [info] [Info  - 2:02:42 PM] (1492239) BG: [BG(1)] Long operation: binding: file:///data/PROJECT.venv/lib/python3.12/site-packages/transformers/__init__.py (3456ms)
2025-05-31 14:02:48.043 [info] (Client) The existing extension didn't exit within 10 seconds. New instance will start, but you might encounter issues.

I assumed that was the causing issues, because completions often hang for a while and syntax highlighting is sluggish (adding/changing a line sometimes takes upwards of ~2s to rehighlight), but maybe not? I'll try these stubs from the old commit and see if that works.

UPDATE: I think that works! I'm still seeing a tiny bit of lag for syntax highlighting, but more like ~1/2s instead of the ~2s from before!

@debonte
Copy link
Contributor

debonte commented May 31, 2025

@isaac-mcfadyen, for what it's worth, we haven't shipped a release of Pylance with this change yet.

@isaac-mcfadyen
Copy link

Oh that's definitely odd, my issue must be unrelated then... Sorry for hijacking this PR 😄

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