Skip to content

docs: Fix order of zero_grad#512

Merged
ValerianRey merged 2 commits intomainfrom
change-zero-grad-order
Jan 8, 2026
Merged

docs: Fix order of zero_grad#512
ValerianRey merged 2 commits intomainfrom
change-zero-grad-order

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

The idea is to free the .grad fields as early as we can in our usage examples, so that memory consumption is reduced for users that would follow these examples. See https://discuss.pytorch.org/t/order-of-backward-step-and-zero-grad/119023.

It also changes a test to use optimizer.zero_grad instead of model.zero_grad. Both are equivalent but I'd rather always use the former so that it's easier to find and replace.

@ValerianRey ValerianRey added the cc: docs Conventional commit type for changes to the documentation. label Jan 8, 2026
@ValerianRey ValerianRey self-assigned this Jan 8, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/torchjd/autogram/_engine.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey ValerianRey merged commit e890e65 into main Jan 8, 2026
13 checks passed
@ValerianRey ValerianRey deleted the change-zero-grad-order branch January 28, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: docs Conventional commit type for changes to the documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants