fix: compatibility with torch<=2.7#46393
Conversation
vasqu
left a comment
There was a problem hiding this comment.
LGTM but cc @IlyasMoutawwakil just in case
transformers 5.10.x (released 2026-06-03) evaluates torch.float8_e8m0fnu at import time (integrations/finegrained_fp8.py), which requires torch >= 2.7. The diffusion pool installs torch from the cu124 index, which tops out at torch 2.6.0, so the worker's `from diffusers import StableDiffusionPipeline` crashes with AttributeError: module 'torch' has no attribute 'float8_e8m0fnu'. This made test_batch_diffusion time out (45 min) in 4/4 attempts of the nightly --aws build 11109: the mapper dies before the first batch is fed, the managed job stays RUNNING at 0% instead of failing (separate framework issue), and the test hits its timeout. Upstream: huggingface/transformers#46389 (fix PR huggingface/transformers#46393 not yet released). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
IlyasMoutawwakil
left a comment
There was a problem hiding this comment.
LGTM ! thanks for the fix
|
@andylin-hao could you sync with main (merge/rebase)? I think CI should be green then 🤗 would merge after |
Signed-off-by: Hao Lin <linhaomails@gmail.com>
37602b2 to
12c96ac
Compare
Hi @vasqu, I just rebased main. Thanks! |
| _FP8_MIN = torch.finfo(_FP8_DTYPE).min | ||
| _FP8_MAX = torch.finfo(_FP8_DTYPE).max | ||
| _UE8M0_SF_DTYPE = torch.float8_e8m0fnu | ||
| _UE8M0_SF_DTYPE = getattr(torch, "float8_e8m0fnu", None) |
There was a problem hiding this comment.
sorry just noticed the default is None, hmm this will break the parameter creation no ? there's also some to(_UE8M0_SF_DTYPE) in the code, can you check please
There was a problem hiding this comment.
Yes. I think all the usages _UE8M0_SF_DTYPE require scale_fmt to be "ue8m0", and passing None to tensor.to() is basically a no-op with no side effect. But on the other hand, this may be a silent failure when the tensor should be converted to FP8 but really is not. So I added a function to raise with clear error message when this occurs (users request scale_fmt to be ue8m0 but FP8 is not supported by the torch version). What do you think?
|
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. |
Signed-off-by: Hao Lin <linhaomails@gmail.com>
Signed-off-by: Hao Lin <linhaomails@gmail.com>
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46393&sha=086be5 |
transformers 5.10.x (released 2026-06-03) evaluates torch.float8_e8m0fnu at import time (integrations/finegrained_fp8.py), which requires torch >= 2.7. The diffusion pool installs torch from the cu124 index, which tops out at torch 2.6.0, so the worker's `from diffusers import StableDiffusionPipeline` crashes with AttributeError: module 'torch' has no attribute 'float8_e8m0fnu'. This made test_batch_diffusion time out (45 min) in 4/4 attempts of the nightly --aws build 11109: the mapper dies before the first batch is fed, the managed job stays RUNNING at 0% instead of failing (separate framework issue), and the test hits its timeout. Upstream: huggingface/transformers#46389 (fix PR huggingface/transformers#46393 not yet released). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
CI Dashboard: View test results in Grafana |
What does this PR do?
This PR fixes #46389, which is transformers' compatibility with torch<=2.7 which does not have FP8 support (missing torch.float8_e8m0fnu).
When installing 5.10.1 with torch<=2.7, importing
AutoProcessorfrom transformers will import torch.float8_e8m0fnu in this line:transformers/src/transformers/integrations/finegrained_fp8.py
Line 45 in d3f0591
As a result, the import will fail with ModuleNotFoundError with the following stack:
This can be reproduced by installing torch==2.7 and transformers 5.10.1. Since transformers' dependency only requires torch>=2.4, I believe it's necessary to maintain support for these non-FP8 torch versions.
The fix uses getattr to check if FP8 is supported in the current torch and modifies
deepgemm_compatiblebased on the check.Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.