Repository navigation
Fix AttributeError in gradient_checkpointing_enable(offload=True) - #48590
Conversation
…hout an accelerator
`torch.accelerator.current_accelerator()` returns `None` when no accelerator is
available, so `.type` raised `AttributeError: 'NoneType' object has no attribute
'type'` on CPU-only machines. Fall back to `torch.device("cpu")`, matching the
idiom already used in `quantizers/quantizer_mxfp4.py`.
|
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. |
CI recapDashboard: View test results in Grafana |
|
@askserge review this fix |
There was a problem hiding this comment.
🤗 Serge says:
Minimal, correct fix.
- Bug: On CPU-only hosts,
torch.accelerator.current_accelerator()returnsNone, so.typeraisedAttributeError. - Fix: Fall back to
torch.device("cpu"). - Rationale: Activations already live on the host when there is no accelerator, matching the existing idiom in
quantizers/quantizer_mxfp4.py.
serge v0.1.0 · model: moonshotai/Kimi-K2.7-Code · 4 LLM turns · 3 tool calls · 29.0s · 22220 in / 995 out tokens
|
@qgallouedec we've merged to fix |
|
Thks for the fix, no need to revert, but for the record I think it's the wrong shape. No one trains on cpu on purpose, and if someone did and passed the test is if (accelerator := torch.accelerator.current_accelerator()) is None:
raise ValueError("`offload=True` requires an accelerator")
device_type = accelerator.typeLinting should be a bug catcher. Here it flagged a |
makes total sense. I don't think the |
…ggingface#48590) Fix AttributeError in gradient_checkpointing_enable(offload=True) without an accelerator `torch.accelerator.current_accelerator()` returns `None` when no accelerator is available, so `.type` raised `AttributeError: 'NoneType' object has no attribute 'type'` on CPU-only machines. Fall back to `torch.device("cpu")`, matching the idiom already used in `quantizers/quantizer_mxfp4.py`.
What does this PR do?
torch.accelerator.current_accelerator()returnsNonewhen no accelerator is available, so.typeraisedAttributeError: 'NoneType' object has no attribute 'type'on CPU-only machines. Fall back totorch.device("cpu"), matching the idiom already used inquantizers/quantizer_mxfp4.py.