Skip to content

fix(logger): flatten nested lists in flatten_dict for add_hparams - #5447

Open
bzantium wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
bzantium:flatten-dict-nested-lists
Open

bzantium wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
bzantium:flatten-dict-nested-lists

Conversation

@bzantium

@bzantium bzantium commented Nov 25, 2026 •

Copy link
Copy Markdown
  • I, the PR author, have personally reviewed every line of this PR.

What and why

flatten_dict expands a list into one key per index, but only one level deep. A list inside a list stays a list value. Logger.log_hyperparams passes the flattened master config to TensorBoard's add_hparams, and add_hparams raises ValueError: value should be one of int, float, str, bool, or torch.Tensor on a list value. With TensorBoard enabled, any config that holds a matrix therefore stops GRPO setup before the first step. Our case was Muon's polar coefficients in the Megatron optimizer config, a list of [a, b, c] triples.

This PR makes flatten_dict recurse through lists at any depth, so every index path ends in its own key (coeffs.0.0, coeffs.0.1, ...). Dicts nested in lists flatten as before. expand_lists=False still keeps every list intact. MLflow's log_params, which uses the same function, gets the same keys.

Tests:

  • A list of lists, including a dict inside a nested list, flattens to scalars.
  • expand_lists=False leaves it unchanged.

Issues

None filed.

Convergence / perf / functionality proof

N/A: this only changes the keys the hyperparameter loggers receive for nested lists. Configs without nested lists flatten exactly as before.

Needs upstream changes

None

@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 25, 2026
…-of-list configs

A list inside a list stayed a list value after flatten_dict, and
TensorBoard's add_hparams raises on it in Logger.log_hyperparams, which
stops GRPO setup before the first step for a config holding a matrix
(for example Muon polar coefficients in the Megatron optimizer config).
Each index path now ends in its own scalar key; expand_lists=False keeps
lists intact as before.

Signed-off-by: bzantium <[email protected]>
@bzantium
bzantium force-pushed the flatten-dict-nested-lists branch from 2e69cac to 430ffdb Compare November 25, 2026 12:47
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 27, 2026
@bzantium bzantium changed the title fix(logger): flatten nested lists in flatten_dict so add_hparams accepts list-of-list configs fix(logger): flatten nested lists in flatten_dict for add_hparams Dec 2, 2026
@bzantium
bzantium force-pushed the flatten-dict-nested-lists branch from 430ffdb to c268857 Compare December 2, 2026 15:35
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:low Small, contained change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) labels Dec 2, 2026

This branch has not been deployed

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

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) community-request complexity:low Small, contained change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants