Skip to content

Fix UnboundLocalError in shard_and_distribute_module for replicated parameters#45675

Merged
3outeille merged 2 commits intohuggingface:mainfrom
Abdennacer-Badaoui:small-fix-tp
Apr 28, 2026
Merged

Fix UnboundLocalError in shard_and_distribute_module for replicated parameters#45675
3outeille merged 2 commits intohuggingface:mainfrom
Abdennacer-Badaoui:small-fix-tp

Conversation

@Abdennacer-Badaoui
Copy link
Copy Markdown
Member

When a parameter has no entry in the model's TP plan (e.g. the score head in LlamaForSequenceClassification), shard_and_distribute_module correctly falls through to the replicate branch but then unconditionally calls tp_layer.update_module_attributes(...). In that path,tp_layer is unbound, causing an UnboundLocalError. Initialize tp_layer = None and guard the call.

Repro:
LlamaForSequenceClassification.from_pretrained(..., tp_plan="auto") under multi-GPU launch.

Found while validating accelerate on 8× AMD MI300X. Not AMD-specific, but discovered while fixing tests/tp/test_tp.py::TPIntegrationTest::test_working_of_tp.

@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.

@3outeille 3outeille enabled auto-merge April 28, 2026 08:55
@3outeille 3outeille added this pull request to the merge queue Apr 28, 2026
Merged via the queue into huggingface:main with commit 4287660 Apr 28, 2026
28 checks passed
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