Repository navigation
feat(data): per-server task_data schemas, gym env schema, collate validation - #2795
Conversation
|
/ok to test e4aed2e |
e4aed2e to
cefa04e
Compare
|
/ok to test cefa04e |
9f81c6d to
000dff3
Compare
cefa04e to
d10ea57
Compare
|
/ok to test d10ea57 |
000dff3 to
bff41cd
Compare
d10ea57 to
3e44b4c
Compare
|
/ok to test 3e44b4c |
bff41cd to
350ed9c
Compare
350ed9c to
4f649fa
Compare
3e44b4c to
176039d
Compare
|
/ok to test 176039d |
| names = set(core.model_fields) | ||
| names.update(f.alias for f in core.model_fields.values() if f.alias) | ||
| return frozenset(names) | ||
| return None |
There was a problem hiding this comment.
Non-blocking: returning None here disables unknown-field reporting for a root Annotated[Union[...]]. For example, RULER2 can accept lenght instead of its optional length field because the selected model allows extras and the validator never records them. Pydantic returns the selected concrete model after validation, so inspecting its __pydantic_extra__ would make reporting work for unions too. That could also support an explicit schema policy: reject extras, accept and report them, or accept them as intentionally open.
There was a problem hiding this comment.
Fixed in 12a9154, using your approach. The validator now validates and keeps the returned model. Pydantic returns the selected union member, so unknown fields land on its pydantic_extra and get reported for unions too. Your ruler2 example is now a test: a typo'd lenght on a union member is recorded as an unknown key. On the explicit policy: reject maps to extra='forbid', accept-and-report is the default extra='allow' behavior, and 'ignore' stays banned. Intentionally-open payloads are typed as dict fields, so their contents never count as unknown.
8a62431 to
12a9154
Compare
|
/ok to test 12a9154 |
…idation A resources server can now ship resources_servers/<name>/task_data.py exporting a Pydantic TaskData model that types its dataset rows' task-owned fields. This PR ships the machinery plus the six example servers; the other 108 schemas follow in one batch. - nemo_gym/task_data.py: dependency-light leaf module with the schema loader, the framework-reserved row keys, and a row validator. Schemas are written flat in the planned end-state row shape; rows that still carry a legacy verifier_metadata dict have its contents spliced up before validation (equal duplicates tolerated, conflicting values reported), so one schema validates both today's rows and post-row-format-migration task_data contents. Fields living in verifier_metadata today are annotated with legacy_location so migration tooling has the reverse map. - gym env schema --resources-server <name>: prints the schema as JSON Schema. - gym dataset collate: validates each row against the declaring server's schema behind task_data_validation: off|warn|error (default warn; servers without a schema are skipped). Datasets declared by agents resolve to the resources server the agent references; self-contained agents are skipped. - Reference schemas for the six example servers, covering the three real patterns: top-level fields, verifier_metadata, and stateful servers with no task fields. - CI enforcement: every shipped task_data.py must import only stdlib/pydantic/nemo_gym.task_data/other task_data modules, and pydantic's silent-drop extra='ignore' is banned. Verified: full core suite passes; golden routing gate base-vs-branch is 0-diff strict; live collate smoke on clean data is silent, warn mode prints the per-row report, error mode fails collation with it. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Adil Asif <[email protected]>
12a9154 to
ecc19b8
Compare
| ref = getattr(inner, "resources_server", None) | ||
| rs_name = ref.get("name") if isinstance(ref, (dict, DictConfig)) else getattr(ref, "name", None) | ||
| if not isinstance(rs_name, str): | ||
| return None |
There was a problem hiding this comment.
I'm not sure if this works as expected - e.g. in L765 we check:
if other.SERVER_TYPE == "resources_servers" and other.name == rs_name:
I don't think it will work for agent-defined datasets.
But I also consider this non-blocking - can be addressed when we'll be adding schemas for self-contained agents.
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Per-server task-data schemas. | ||
|
|
||
| A resources server may ship a ``task_data.py`` module next to its ``app.py`` exporting a single |
There was a problem hiding this comment.
I think this description is outdated after you addressed comments from Ananth
There was a problem hiding this comment.
Correct. Updated in ac66f17. The docstring now covers agent-owned schemas: a self-contained agent ships task_data.py under responses_api_agents//, and an agent with a reference uses that resources server's schema.
| agents (which verify in-process) keep their schemas under ``responses_api_agents/<name>/``. | ||
| """ | ||
| rel = Path(base_folder) / server_name | ||
| for root in (Path.cwd(), Path(__file__).resolve().parent.parent): |
There was a problem hiding this comment.
Would it make sense to use component_search_roots here?
There was a problem hiding this comment.
or even _resolve_under_cwd_or_install - I think it does exactly what you need
There was a problem hiding this comment.
Good catch. Done in ac66f17. find_server_dir now resolves through _resolve_under_cwd_or_install with an is_dir validator. This also fixes a real gap: the old code missed NEMO_GYM_EXTRA_ROOTS, so schemas in plugin roots were not found.
| self.report.unknown_keys[key] = self.report.unknown_keys.get(key, 0) + 1 | ||
|
|
||
|
|
||
| def validate_jsonl_rows( |
There was a problem hiding this comment.
I think this function is not used anywhere except tests.
There was a problem hiding this comment.
True today. Its planned consumer is dataset tooling that validates a whole file against a schema, and the drift test added later in this stack uses it the same way. The docstring wrongly said CLI tooling; fixed in ac66f17 to describe it as the whole-file validation entry point.
| legacy_agent_ref_rows += 1 | ||
| row[TASK_SOURCE_KEY_NAME] = c.name | ||
| if validator is not None: | ||
| validator.validate_row(row_index, row) |
There was a problem hiding this comment.
non-blocking: I think if we use N repeats we report each broken row N times and the index does not match the index in the jsonl file. I'm not sure how hard it would be to deduplicate and use the original row indices
There was a problem hiding this comment.
Confirmed and fixed in ac66f17. Collate now validates only the first copy of each repeated line and reports the original jsonl index. Test added: a bad row with num_repeats=3 is reported once, as row 1.
|
/ok to test ac66f17 |
… dedupe, docs, tests find_server_dir now resolves through _resolve_under_cwd_or_install, so schemas in NEMO_GYM_EXTRA_ROOTS plugin roots are found too. Collate validation now checks only the first copy of a num_repeats-duplicated line and reports the original jsonl index. The module docstring covers agent-owned schemas. The validate_jsonl_rows docstring names its real consumer. Two tests added: an agent with a valid resources_server reference resolves that server's schema end to end, and a bad row under num_repeats=3 is reported once with its file index. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Adil Asif <[email protected]>
|
/ok to test b5cf00d |
|
/ok to test 361d638 |
|
/ok to test b993804 |
@adil-a, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 361d638 |
Problem
A dataset row's task fields have no machine-checkable definition. Each server types what it can on its verify request models. But that contract is invisible to data tooling. A typo'd or mistyped field is discovered at rollout time, or never. At least 12 servers use Pydantic's default
extra="ignore"and silently drop unrecognized row fields at the verify boundary. Learning what fields a server needs means reading its source code.Change
A resources server can now describe its task fields in one small file. This PR ships the machinery and six example servers. The schemas for the other 108 servers follow in one batch (#2800).
1. A server can ship
resources_servers/<name>/task_data.py. It exports one symbol,TaskData: a Pydantic model describing the row's task-owned fields. A server whose rows come in several distinct shapes exports one model per shape plus the field that names the shape, and validation picks the right model per row. Example: ruler2 rows carryeval_type; string-match rows must have a list of expected outputs, multichoice rows must have one answer letter. The file is dependency-light: it imports only stdlib, pydantic, andnemo_gym/task_data.py. Data tooling can load it without installing the server's requirements.2. Schemas describe the future row shape. Today task fields live in two places: most servers keep them as top-level row keys, 14 keep them inside a
verifier_metadatadict. We plan to move all task fields under onetask_datakey later. Schemas are written for that future shape now. Before validating a row, core code normalizes it: framework keys are removed, andverifier_metadatacontents are lifted to the top level. If the same key appears in both places with different values, the row is flagged. This way one schema checks today's rows and tomorrow's rows, and no schema needs a rewrite when the move happens. Fields that sit insideverifier_metadatatoday are markedlegacy_location, so the migration knows where each field came from.3.
gym env schema --resources-server <name>prints the schema as JSON Schema.4.
gym dataset collatevalidates rows against the declaring server's schema. New knob:task_data_validation: off|warn|error, defaultwarn. Warn prints a per-file report (failing rows, ambiguous duplicate keys, undeclared keys). Error fails collation. Servers without a schema are always skipped, so nothing changes for them. Datasets declared by an agent resolve to the resources server the agent references. Self-contained agents (tau2-style) are skipped.5. CI enforcement, both halves. A test imports every shipped
task_data.pyand rejects imports outside the allowed set. Pydantic's silent-dropextra="ignore"is banned in schemas (allowis the default,forbidis opt-in).Field rules encoded in the protocol
Required-ness mirrors the server's wire contract, not what
verify()happens to read. Several servers 422 on missing-but-unread fields, and existing datasets must keep validating. JSON-encoded-string fields staystr. Servers with several row shapes key the choice on a field their verify() already reads (ruler2eval_type, asr_with_pctask_type), never on a new field invented for the schema.How this was tested
gym dataset collateon clean example data prints nothing. A deliberately mistyped row prints the per-row report inwarnand fails collation inerror. Exact messages verified.gym env schemaverified for a schema-bearing server, an empty schema, and a server without one.Stack
PR 1 of the task-data-schema series. Base: #2717 (
data-prep/rs-datasets-collate). Next: #2800 (the 108 per-server schemas), then per-server flips oftask_data_validationtoerroronce each server's committed data validates clean.🤖 Generated with Claude Code