Skip to content

Fix deepgemm on multiple devices#47323

Open
IlyasMoutawwakil wants to merge 5 commits into
mainfrom
fix-deepgemm-arbitrary-N
Open

Fix deepgemm on multiple devices#47323
IlyasMoutawwakil wants to merge 5 commits into
mainfrom
fix-deepgemm-arbitrary-N

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Jul 14, 2026

Copy link
Copy Markdown
Member

CI

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. These often are low-quality, or fix extremely minor issues that occur rarely or never in practice.
As a result, we're instituting a rule that first-time contributors should not use code agents to submit PRs or issues.
We'd also ask autonomous "OpenClaw"-like agents not to open any PRs or issues.

Issues/PRs from first-time contributors that violate this rule will probably just be closed without review, and we
might block you, especially if you open more than one or appear to be deliberately ignoring this. We especially do not
want new contributors to jump in on random issues to contribute an agent-written fix. This creates lots of noise
for reviewers and other users and will almost certainly get you blocked.

For more information, please read CONTRIBUTING.md.

  • (First-time contributors only): I confirm that this PR description and code is not written by an LLM or code agent

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 and the
    Pull Request checks?
  • 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 according to the guidelines?
  • 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.

Comment on lines -244 to -248
# DeepGEMM linear off). Also temporarily skipped under ``torch.compile`` — DeepGEMM's
# per-token cast calls ``pack_ue8m0_to_int`` which has data-dependent bit-twiddling that
# dynamo can't guard. TODO: remove the ``is_torchdynamo_compiling`` gate once the upstream
# ``pack_ue8m0_to_int`` is rewritten to be FakeTensor-friendly; the Triton fallback is
# dynamo-friendly today via its ``@triton_op`` registration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this was already fixed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah nice, is it already also the correct version we use and we just forgot?

@IlyasMoutawwakil IlyasMoutawwakil Jul 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes i already submitted the fix as part of the dsv4 static cache PR but that never got merged (perf not so great for now)

block_size: list[int] | None = None,
bias: torch.Tensor | None = None,
activation_scale: torch.Tensor | None = None,
output_dtype: torch.dtype | None = None,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this was just bad because it defaulted to None and deepgemm and fp8 don't behave the same on None output dtype anyways

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add * at least to be not BC in case anyone used the interface? Similar to others, it is slightly breaking because an output dtype is no longer possible

Maybe we could default to input dtype on None instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

defaulted to input.dtype but i think we should deprecate it, in general linears don't really interface an output dtype, see torch's linear https://docs.pytorch.org/docs/2.13/generated/torch.nn.functional.linear.html

@IlyasMoutawwakil IlyasMoutawwakil requested a review from vasqu July 14, 2026 15:38
@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.

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Imo, looks good and nice _process_model_after_weight_loading coming in clutch :D just a few style / nit comments overall

cc @Dovis01

block_size: list[int] | None = None,
bias: torch.Tensor | None = None,
activation_scale: torch.Tensor | None = None,
output_dtype: torch.dtype | None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add * at least to be not BC in case anyone used the interface? Similar to others, it is slightly breaking because an output dtype is no longer possible

Maybe we could default to input dtype on None instead?

Comment on lines -244 to -248
# DeepGEMM linear off). Also temporarily skipped under ``torch.compile`` — DeepGEMM's
# per-token cast calls ``pack_ue8m0_to_int`` which has data-dependent bit-twiddling that
# dynamo can't guard. TODO: remove the ``is_torchdynamo_compiling`` gate once the upstream
# ``pack_ue8m0_to_int`` is rewritten to be FakeTensor-friendly; the Triton fallback is
# dynamo-friendly today via its ``@triton_op`` registration.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah nice, is it already also the correct version we use and we just forgot?

class FP8Linear(nn.Linear):
# Set True at load when the model spans >1 CUDA device in one process; DeepGEMM's
# context-bound kernels corrupt across devices (see `quantizer_finegrained_fp8.py`).
_deepgemm_disabled = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit, would set on init either way, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no only when we have than one device do we update it, i can remove this but will have to do getattr and it will be there sometimes and sometimes not so i thought it could make sense to add it like the _can_compile_fullgraph and other capability flags

class FP8Experts(nn.Module):
# Set True at load when the model spans >1 CUDA device in one process; DeepGEMM's
# context-bound kernels corrupt across devices (see `quantizer_finegrained_fp8.py`).
_deepgemm_disabled = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same

Comment thread src/transformers/quantizers/quantizer_finegrained_fp8.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: finegrained_fp8

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29360490448:1
Result: failure | Jobs: 15 | Tests: 165,552 | Failures: 1 | Duration: 14h 40m

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