Skip to content

fix transformers + torchao nvfp4 serialization#45573

Merged
SunMarc merged 2 commits intohuggingface:mainfrom
vkuzo:20260421_torchao_nvfp4_fix
Apr 23, 2026
Merged

fix transformers + torchao nvfp4 serialization#45573
SunMarc merged 2 commits intohuggingface:mainfrom
vkuzo:20260421_torchao_nvfp4_fix

Conversation

@vkuzo
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo commented Apr 22, 2026

Summary:

  1. fix torchao NVFP4 serialization with transformers
  2. add a test to cover the fix

While i'm here, also did the following bundled into this PR:
3. make the torchao serialization test have human readable names (easier to debug)
4. fix the float8 test (update the expected output)

after this PR the test command for all torchao configs passes on an NVIDIA B200

Co-developed with Claude.

Test Plan:

RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py -k "Serialization" -s

What does this PR do?

Fixes # (issue)

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.

  • I confirm that this is not a pure code agent PR.

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.

@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Apr 22, 2026

test failure looks unrelated

vkuzo added a commit to pytorch/ao that referenced this pull request Apr 22, 2026
Summary:

remove the hacky transformers version check, and replace it with proper
workarounds:

1. ensure the user has transformers with
   huggingface/transformers#45573 for nvfp4
   serialization to work
2. manually attach an HF quantizer to ensure deserialization works (this
   is required with transformers 5.0.0+).

Test Plan:

```

```
ghstack-source-id: 8376570
ghstack-comment-id: 4295746737
Pull-Request: #4313
vkuzo added a commit to pytorch/ao that referenced this pull request Apr 22, 2026
Summary:

remove the hacky transformers version check, and replace it with proper
workarounds:

1. ensure the user has transformers with
   huggingface/transformers#45573 for nvfp4
   serialization to work
2. manually attach an HF quantizer to ensure deserialization works (this
   is required with transformers 5.0.0+).

Test Plan:

```

```
ghstack-source-id: 8376570
ghstack-comment-id: 4295746737
Pull-Request: #4313
Copy link
Copy Markdown
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks, just a nit

Comment thread tests/quantization/torchao_integration/test_torchao.py Outdated
@vkuzo vkuzo force-pushed the 20260421_torchao_nvfp4_fix branch from c0892f0 to 4b69954 Compare April 22, 2026 17:38
Summary:

1. fix torchao NVFP4 serialization with transformers
2. add a test to cover the fix

While i'm here, also did the following bundled into this PR:
3. make the torchao serialization test have human readable names (easier
   to debug)
4. fix the float8 test (update the expected output)

after this PR the test command for all torchao configs passes on an
NVIDIA B200

Test Plan:

```
RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py -k "Serialization" -s
```
@vkuzo vkuzo force-pushed the 20260421_torchao_nvfp4_fix branch from 4b69954 to 4b8ceaa Compare April 22, 2026 17:51
@SunMarc SunMarc enabled auto-merge April 22, 2026 19:02
@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.

@jerryzh168
Copy link
Copy Markdown
Contributor

so torchao tests are actually running in transformers repo's CI and only nvfp4 is broken right?

@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: torchao_integration

@SunMarc
Copy link
Copy Markdown
Member

SunMarc commented Apr 22, 2026

so torchao tests are actually running in transformers repo's CI and only nvfp4 is broken right?

The tests are working fine, we are just adding coverage for nvfp4 here @jerryzh168. I've reworked the testing suite + the integration a few weeks again to clean a bit.

@SunMarc SunMarc added this pull request to the merge queue Apr 23, 2026
Merged via the queue into huggingface:main with commit 0323898 Apr 23, 2026
28 checks passed
tarekziade pushed a commit that referenced this pull request Apr 23, 2026
Summary:

1. fix torchao NVFP4 serialization with transformers
2. add a test to cover the fix

While i'm here, also did the following bundled into this PR:
3. make the torchao serialization test have human readable names (easier
   to debug)
4. fix the float8 test (update the expected output)

after this PR the test command for all torchao configs passes on an
NVIDIA B200

Test Plan:

```
RUN_SLOW=1 pytest tests/quantization/torchao_integration/test_torchao.py -k "Serialization" -s
```

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
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.

4 participants