Repository navigation
fix: address CLI issues - #1829
Conversation
…ion errors Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…nt matches Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…status and pip_list Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…sonl files Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
|
/ok to test 00536e7 |
| _value_flag("prompt-config", "prompt_config", "Prompt template YAML to apply."), | ||
| _value_flag("output", "output_jsonl_fpath", "Output JSONL file.", aliases=("-o",)), | ||
| _value_flag("input", "input_jsonl_fpath", "Raw input JSONL file.", aliases=("-i",), required=True), | ||
| _value_flag("prompt-config", "prompt_config", "Prompt template YAML to apply.", required=True), |
There was a problem hiding this comment.
nit: this closes the hydra path of overriding, if this is fine then we should be good:
uv run gym eval profile +materialized_inputs_jsonl_fpath=/tmp/i.jsonl +rollouts_jsonl_fpath=/tmp/r.jsonl
usage: gym eval profile [-h] [-v] --inputs INPUTS --rollouts
ROLLOUTS
gym eval profile: error: the following arguments are required: --inputs, --rolloutsThere was a problem hiding this comment.
oh right, I couldn't remember why I didn't mark these flags as required... xD let me revert and just rely on error handling
| command.target(args, overrides) | ||
| else: | ||
| dispatch(command.target, overrides) | ||
| except ValidationError as exc: |
There was a problem hiding this comment.
So not sure, if this will be always ValidationError - I asked my Claude to investigate it and here is what it got:
What the PR was trying to do
When you run a gym command, the first thing each command does is validate your config (the flags/overrides you passed) with pydantic. If you forget a required value, pydantic raises a ValidationError — normally an ugly multi-line traceback. The PR wanted to catch that and print a friendly one-liner instead. So in main() it added (main.py:675–682):
try:
if callable(command.target):
command.target(args, overrides) # 677
else:
dispatch(command.target, overrides) # 679
except ValidationError as exc:
getattr(args, "_parser", parser).error(_format_validation_error(exc)) # 682
And _format_validation_error turns a ValidationError into either:
- "missing required configuration: <field>. Provide each via its flag (see --help) or as a +<field>=<value> override." (for a missing field), or
- "invalid configuration: <field> (<msg>)." (for a wrong type/value).
The bug: the try is wrapped around the wrong scope
Look at what's inside the try: command.target(...) / dispatch(...) — that's the entire command, start to finish, not just the config-validation step.
The intended target is the validation at the top of a command, e.g. collect_rollouts (eval.py:390):
config = RolloutCollectionConfig.model_validate(get_global_config_dict()) # <-- user's config; nice to catch
Catching that ValidationError and rendering it as "missing config" is correct.
But the command keeps running after that line — it does the actual rollout work, which makes HTTP calls to resources servers. And there's a second, unrelated model_validate buried deep in that work (rollout_collection.py:610):
agg_result = AggregateMetrics.model_validate(await get_response_json(agg_response))
This validates the JSON a resources server sent back from its /aggregate_metrics endpoint. It has nothing to do with your CLI config.
The failure trace
1. A resources server returns a malformed/incomplete aggregate-metrics payload (a server bug, a version mismatch, a truncated response — anything).
2. Line 610 AggregateMetrics.model_validate(...) raises a pydantic ValidationError.
3. That error is not a ConfigError, so the @exit_cleanly_on_config_error decorator on collect_rollouts (eval.py:388) does not catch it. It propagates up and out of the command.
4. It lands in main()'s except ValidationError (line 680), which calls _format_validation_error and prints:
gym eval run: error: invalid configuration: group_level_metrics (Input should be a valid list); agent_metrics (Input should be a valid dictionary).
Why that message is wrong
- Your CLI invocation and config were perfectly fine. The real problem is a server returned bad data.
- The message says "fix your configuration… pass it as a flag or +field=value" — but group_level_metrics / agent_metrics are server-response fields. There is no such CLI flag or config key. Following the advice does nothing.
- It hides the real cause and sends you debugging your command line instead of the server. (And if the server omits a required field, you get the even more misleading "missing required configuration: group_level_metrics. Provide via +group_level_metrics=<value>".)
In one line: the catch is meant for "the user's config failed validation" but it actually catches "any pydantic ValidationError raised anywhere in the whole command," including data validation deep in the rollout.
Why the repro is Python, not a gym command
To hit this via the real CLI you'd need a live resources server returning a malformed /aggregate_metrics body — heavy to stand up. So the repro constructs the exact same failing validation and feeds it through the exact same renderer main() uses, proving the message that would be shown:
uv run python -c "
from pydantic import ValidationError
from nemo_gym.base_resources_server import AggregateMetrics # the model validated at rollout_collection.py:610
from nemo_gym.cli.main import _format_validation_error # the renderer main() calls at line 682
try:
AggregateMetrics.model_validate({'group_level_metrics':'x','agent_metrics':1}) # simulate a bad server response
except ValidationError as e:
print('gym eval run: error:', _format_validation_error(e))
"
# -> gym eval run: error: invalid configuration: group_level_metrics (...); agent_metrics (...).
The fix
Scope the friendly rendering to only the config-validation step. Either:
- (a) validate the command's config in main() before dispatch, wrap only that in the try, and run the command itself outside the try; or
- (b) keep the catch but only render-and-exit when the ValidationError came from the command's own config model, and re-raise otherwise so a genuine server/data error surfaces as a real error rather than a fake "missing config" message.
Sorry for parsing Claude exactly, but maybe it's easier with grabbing entire context
There was a problem hiding this comment.
so the purpose of this was to capture errors related to misconfiguration. I don't try to catch all possible errors, just the ones that are directly related to user passing wrong params. but it caught one important thing - that the source of validation error might be different. Let me try to fix
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
…asses Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
|
/ok to test 24f5561 |
|
/ok to test 1ca4fca |
beep boop [🤖]: Hi @marta-sd 👋, we've cherry picked #1829 into for you! 🚀 Please review and approve this cherry pick by your convenience! Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]> Signed-off-by: NeMo Bot <[email protected]> Co-authored-by: Marta Stepniewska-Dziubinska <[email protected]>
No description provided.