[BUG] `PatchEmbed` 返回一个视图张量,导致 FSDP2 警告
作者: sjiang95创建于 2026年9月9日更新于 2026年9月16日
标签bug
Describe the bug
/usr/local/lib/python3.12/dist-packages/torch/distributed/fsdp/_fully_shard/_fsdp_state.py:336: UserWarning: FSDP2-wrapped module (FSDPPatchEmbed) returned a view tensor. An in-place op on this view (e.g., `x += y`) will silently drop the pre-backward hook and skip the all-gather, which can cause backward to fail or produce wrong gradients. Use out-of-place ops (`out = out + y`, not `out += y`) or `.clone()` the output before any in-place op.
output = self._register_pre_backward_hook(output)This warning was introduced to pytorch in https://GitHub.com/pytorch/pytorch/pull/181850
内容来源: huggingface/pytorch-image-models