Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507
Open
youssefbench wants to merge 1 commit into
Open
Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507youssefbench wants to merge 1 commit into
youssefbench wants to merge 1 commit into
Conversation
…board/jsonl
Metrics using format_as_percentage (padding_ratio, peak_active_mem_ratio,
peak_reserved_mem_ratio) were logged as raw 0-1 floats to numeric backends
(wandb, TensorBoard, JSONL) while the console logger correctly displayed
them as percentages. This happened because the formatter returns a string
("42%") which only the console logger uses — numeric backends skip it
entirely and pass raw values through.
The fix adds an optional `value_transform` field to MetricDescriptor that
applies a numeric transformation before logging. A new `scale_as_percentage`
function handles int, float, and Tensor types by multiplying by 100. The
three numeric recorders (wandb, TensorBoard, JSONL) now apply this transform
when present, while the console logger continues using the string formatter.
Also changes format_as_percentage to display 2 decimal places ("42.26%"
instead of "42%").
Changes:
- Add MetricValueTransform protocol and value_transform field to MetricDescriptor
- Add scale_as_percentage function to formatters
- Apply value_transform in WandbRecorder, TensorBoardRecorder, JsonlMetricRecorder
- Register value_transform=scale_as_percentage for the 3 percentage metrics
- Update format_as_percentage to use 2 decimal places
- Add 25 unit tests covering formatters and all 4 recorders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do? Please describe:
Metrics using format_as_percentage (padding_ratio, peak_active_mem_ratio, peak_reserved_mem_ratio) were logged as raw 0-1 floats to numeric backends (wandb, TensorBoard, JSONL) while the console logger correctly displayed them as percentages. This happened because the formatter returns a string ("42%") which only the console logger uses — numeric backends skip it entirely and pass raw values through.
Fix
The fix adds an optional
value_transformfield to MetricDescriptor that applies a numeric transformation before logging. A newscale_as_percentagefunction handles int, float, and Tensor types by multiplying by 100. The three numeric recorders (wandb, TensorBoard, JSONL) now apply this transform when present, while the console logger continues using the string formatter.Also changes format_as_percentage to display 2 decimal places ("42.26%" instead of "42%").
Changes:
Does your PR introduce any breaking changes? If yes, please list them:
None
Check list: