Skip to content

Fix distributedType -> distributed_type typo in downcast_bf16 guard - #4149

Merged
SunMarc merged 1 commit into
huggingface:mainfrom
uttam12331:fix-accelerator-distributed-type-typo
Sep 7, 2026
Merged

SunMarc merged 1 commit into
huggingface:mainfrom
uttam12331:fix-accelerator-distributed-type-typo

Conversation

@uttam12331

Copy link
Copy Markdown
Contributor

Summary

The downcast_bf16 validation in Accelerator.__init__ references self.state.distributedType, which does not exist — the attribute is distributed_type:

if (
    (mixed_precision != "bf16")
    and getattr(self.state, "downcast_bfloat", False)
    and (self.state.distributedType != DistributedType.XLA)   # <-- typo
):
    raise ValueError("Can only use `downcast_bf16` when using `mixed_precision='bf16'` and on a TPU")

self.state is an AcceleratorState, whose attribute is distributed_type (used one line above at ~520: self.state.distributed_type == DistributedType.FSDP, and throughout state.py). distributedType appears only on this line in the entire src/ tree.

Impact

Because of short-circuit evaluation, this line is reached when mixed_precision != "bf16" and downcast_bfloat is set. In that case — a user enabling downcast_bf16 without mixed_precision="bf16" — the code raises:

AttributeError: 'AcceleratorState' object has no attribute 'distributedType'

instead of the intended, actionable ValueError that explains the misconfiguration.

Fix

-            and (self.state.distributedType != DistributedType.XLA)
+            and (self.state.distributed_type != DistributedType.XLA)

One-token typo fix; the guard now raises the intended ValueError.

(Happy to add a regression test for the downcast_bf16-without-bf16 path if you'd like — let me know the preferred fixture for constructing that state.)

The downcast_bf16 validation in Accelerator.__init__ references
`self.state.distributedType`, which does not exist -- the attribute is
`distributed_type` (used on the line above at 520 and throughout state.py).
When mixed_precision != "bf16" and downcast_bfloat is set, the guard is
reached and raises `AttributeError: ... has no attribute 'distributedType'`
instead of the intended, clear ValueError.
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@SunMarc SunMarc left a comment

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.

Thanks for fixing the typo

@SunMarc
SunMarc merged commit 5d0176a into huggingface:main Sep 7, 2026
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.

2 participants