Skip to content

Add average_all_summaries context manager#1829

Merged
QuantuMope merged 4 commits intopytorchfrom
PR/andrew/average-all-summaries
Mar 27, 2026
Merged

Add average_all_summaries context manager#1829
QuantuMope merged 4 commits intopytorchfrom
PR/andrew/average-all-summaries

Conversation

@QuantuMope
Copy link
Copy Markdown
Contributor

A useful context manager for computing summary averages over an interval.

Nice to have because several alf algorithms have averaging off as default.
If using these summaries with a small mini-batch-size, we can selectively control which nested summaries get averaged without having to overwrite the source code.

@QuantuMope QuantuMope requested a review from emailweixu March 13, 2026 19:20
Comment on lines +144 to +145
alf.summary.record_if = _disabled_record_if
alf.summary.should_record_summaries = lambda: True
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these two need to be changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record_if must be changed so that the recording interval set by the user is actually used.

should_record_summaries actually shouldn't be overridden as doing so is redundant. I've removed this check. Unit test still passes successfully.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @emailweixu, I've pushed a fix concerning our offline discussion. Now the user has to provide a set of target names, so summaries that shouldn't be messed with don't get caught by accident. It also ensures that record_if logic does not get altered for any nested summary not included in target_names.

You can take a look at the updated unit test to see the correct behavior.

@QuantuMope QuantuMope merged commit de6a42f into pytorch Mar 27, 2026
2 checks passed
@QuantuMope QuantuMope deleted the PR/andrew/average-all-summaries branch March 27, 2026 21:04
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.

2 participants