Skip to content

optimizer.zero_grad out of order #59

@jsta

Description

@jsta

I believe the following chunk that appears throughout src/yoke/torch_training_utils.py:

optimizer.zero_grad(set_to_none=True)  # Possible speed-up
loss.mean().backward()
optimizer.step()

should instead be:

loss.mean().backward()
optimizer.step()
optimizer.zero_grad(set_to_none=True)  # Possible speed-up

as is, I think there is gradient leakage across epochs and higher than necessary usage overall:

with order corrected:
Image

without order correction:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions