Skip to content

Fix SummaryWriter writing to disk when write_to_disk=False in add_scalars (#748)#765

Merged
lanpa merged 1 commit intomasterfrom
fix-748-add-scalars-write-to-disk
Apr 3, 2026
Merged

Fix SummaryWriter writing to disk when write_to_disk=False in add_scalars (#748)#765
lanpa merged 1 commit intomasterfrom
fix-748-add-scalars-write-to-disk

Conversation

@lanpa
Copy link
Copy Markdown
Owner

@lanpa lanpa commented Apr 2, 2026

This PR fixes issue #748 where SummaryWriter continued to write to disk even when write_to_disk=False was specified. The bug was in the add_scalars method, which directly instantiated a FileWriter instead of checking the flag. I have also added a regression test in tests/test_writer.py.\n\nAI assisted

@lanpa
Copy link
Copy Markdown
Owner Author

lanpa commented Apr 3, 2026

@copilot review this PR

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

@copilot review this PR

The fix in commit 2b76fac looks correct. Here's a summary of the review:

What was changed:

  • add_scalars in writer.py previously always created a FileWriter for each scalar tag, bypassing the write_to_disk flag entirely. The fix checks self._write_to_disk and creates a DummyFileWriter instead when it's False.
  • The fix also correctly passes max_queue, flush_secs, and filename_suffix to FileWriter (previously these were not forwarded, so add_scalars would have used defaults even when write_to_disk=True).
  • A regression test test_write_to_disk_false is added that covers both add_scalar and add_scalars.

One observation (pre-existing, not introduced by this PR):
The _get_file_writer() method (line 372–374) recreates the DummyFileWriter and resets all_writers on every call when _write_to_disk=False. This is harmless since DummyFileWriter is a no-op, but it means all_writers can grow with add_scalars tags and then get replaced on the next _get_file_writer() call. Not a bug, but worth knowing.

Overall the fix is minimal, targeted, and correct.

Copilot finished work on behalf of lanpa April 3, 2026 03:25
@lanpa lanpa merged commit 25a1451 into master Apr 3, 2026
11 checks passed
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