Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507
Fix metrics logged as percentage in wandb/tensorboard/jsonl#1507youssefbench 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
|
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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
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: