Remove unused Python variables in torch/[b-z]* (#136963)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/136963
Approved by: https://github.com/ezyang
This commit is contained in:
Tom Ritchford
2024-10-19 13:25:28 +00:00
committed by PyTorch MergeBot
parent fb44658415
commit c0582fd0f8
152 changed files with 376 additions and 528 deletions

View File

@ -34,7 +34,6 @@ def _reducer_allreduce_and_upcast_hook(
"""
ddp_weakref = hook_state.ddp_weakref
reducer, process_group = ddp_weakref().reducer, ddp_weakref().process_group
gradient_is_bucket_view = ddp_weakref().gradient_as_bucket_view
# Cast bucket if different than param_dtype.
if (
ddp_weakref().mixed_precision.param_dtype
@ -53,8 +52,7 @@ def _reducer_allreduce_and_upcast_hook(
ret_fut.set_result(bucket.buffer())
# Upcast parameters and gradients so optimizer step can run in fp32.
params, grads = bucket.parameters(), bucket.gradients()
for p, g in zip(params, grads):
for p in bucket.parameters():
p.data = p._fp_param
# free storage for mp param as it will be allocated again in next
# forward pass.
@ -70,7 +68,7 @@ def _reducer_allreduce_and_upcast_hook(
# they may participate in computation. However, they would not be recast
# by hook above as they don't have a grad hook installed, so cast them
# back here.
for n, p in ddp_weakref().module.named_parameters():
for _, p in ddp_weakref().module.named_parameters():
if hasattr(p, "_ddp_mp_hook_state"):
p._ddp_mp_hook_state[1].remove()
delattr(p, "_ddp_mp_hook_state")