Skip to content

Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507

Open
youssefbench wants to merge 1 commit into
mainfrom
youssefb/fix_formatter_percentage
Open

Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507
youssefbench wants to merge 1 commit into
mainfrom
youssefb/fix_formatter_percentage

Conversation

@youssefbench

@youssefbench youssefbench commented Apr 8, 2026

Copy link
Copy Markdown

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_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

Does your PR introduce any breaking changes? If yes, please list them:
None

Check list:

  • Was the content of this PR discussed and approved via a GitHub issue? (no need for typos or documentation improvements)
  • Did you read the contributor guideline?
  • Did you make sure that your PR does only one thing instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (no need for typos, documentation, or minor internal changes)

…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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@youssefbench youssefbench changed the title Fix percentage metrics logged as percentage in wandb/tensorboard/jsonl Fix metrics logged as percentage in wandb/tensorboard/jsonl Apr 8, 2026
@meta-cla

meta-cla Bot commented Jun 23, 2026

Copy link
Copy Markdown

Hi @youssefbench!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant