Skip to content

fix(nn.utils.prune): don't crash adding a method to an empty PruningContainer - #89

Open
laifenxiawucha wants to merge 1 commit into
mainfrom
issue-1895-pruning-container
Open

laifenxiawucha wants to merge 1 commit into
mainfrom
issue-1895-pruning-container

Conversation

@laifenxiawucha

Copy link
Copy Markdown
Owner

Summary

Fixes an AttributeError in torch.nn.utils.prune.PruningContainer when a method is added to an empty container.

Root Cause

PruningContainer.add_pruning_method assumed _tensor_name had already been initialized. For PruningContainer() followed by add_pruning_method(...), that attribute was missing, so the first add raised AttributeError instead of adopting the method's tensor name.

Changes

  • make PruningContainer adopt _tensor_name from the first added pruning method
  • add a regression test covering empty-container incremental construction

Verification

Used the issue reproducer with the patched torch.nn.utils.prune module loaded from this branch in the provided XPU Python environment:

/home/jyz/cuda-fix-alignment/.venv/bin/python <inline repro using /tmp/opencode/pytorch-issue-1895/torch/nn/utils/prune.py>

Observed:

torch 2.14.0.dev20260705+xpu
xpu_available True
container tensor weight xpu:0
RESULT: not-reproduced

Issue: https://github.com/intel-sandbox/torch-xpu-ops-exp/issues/1895

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.

1 participant