Skip to content

Added support for logging dicts/iterables of metrics#3369

Merged
vfdev-5 merged 1 commit intomasterfrom
fix-3294-support-logging-pytrees
Mar 29, 2025
Merged

Added support for logging dicts/iterables of metrics#3369
vfdev-5 merged 1 commit intomasterfrom
fix-3294-support-logging-pytrees

Conversation

@vfdev-5
Copy link
Copy Markdown
Collaborator

@vfdev-5 vfdev-5 commented Mar 28, 2025

Fixes #3294
Closes #3295

Description:

  • Added support for logging dicts/iterables

For example:

evalutator.state.metrics = {
    "a": 0,
    "dict_value": {
        "a": 111,
        "c": {"d": 23, "e": [123, 234]},
    },
    "list_value": [12, "13", {"aa": 33, "bb": 44}],
    "tuple_value": (112, "113", {"aaa": 33, "bbb": 44}),
}

handler = OutputHandler(
  tag="tag",
  metric_names="all",
)

handler(evaluator, tb_logger, event_name=Events.EPOCH_COMPLETED)
# Behind it would call `tb_logger.writer.add_scalar` on 
# {
#     "tag/a": 0,
#     "tag/dict_value/a": 111,
#     "tag/dict_value/c/d": 23,
#     "tag/dict_value/c/e/0": 123,
#     "tag/dict_value/c/e/1": 234,
#     "tag/list_value/0": 12,
#     "tag/list_value/1": "13",
#     "tag/list_value/2/aa": 33,
#     "tag/list_value/2/bb": 44,
#     "tag/tuple_value/0": 112,
#     "tag/tuple_value/1": "113",
#     "tag/tuple_value/2/aaa": 33,
#     "tag/tuple_value/2/bbb": 44,
# }

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added the module: handlers Core Handlers module label Mar 28, 2025
@vfdev-5 vfdev-5 force-pushed the fix-3294-support-logging-pytrees branch 2 times, most recently from d58f6e7 to 927eb6c Compare March 29, 2025 00:29
@vfdev-5 vfdev-5 force-pushed the fix-3294-support-logging-pytrees branch from 927eb6c to 1c27199 Compare March 29, 2025 00:30
@vfdev-5 vfdev-5 marked this pull request as ready for review March 29, 2025 01:09
@vfdev-5 vfdev-5 merged commit e205e61 into master Mar 29, 2025
20 checks passed
@vfdev-5 vfdev-5 deleted the fix-3294-support-logging-pytrees branch March 29, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: handlers Core Handlers module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the logging of dict metrics

1 participant