Skip to content

[misc] fix: validate DataProtoItem consistency - #7450

Open
0z5a wants to merge 1 commit into
verl-project:mainfrom
0z5a:codex/protocol-consistency
Open

[misc] fix: validate DataProtoItem consistency#7450
0z5a wants to merge 1 commit into
verl-project:mainfrom
0z5a:codex/protocol-consistency

Conversation

@0z5a

@0z5a 0z5a commented Aug 17, 2026

Copy link
Copy Markdown

What does this PR do?

Validate DataProtoItem invariants at construction time and expose the same validation through check_consistency(). A DataProtoItem now requires an unbatched TensorDict (num_batch_dims == 0) plus dictionary-valued non_tensor_batch and meta_info fields.

This resolves the existing consistency-check TODO with a narrow correctness change and targeted CPU tests. Invalid items now fail at their construction boundary instead of propagating into later protocol operations.

This PR was prepared with AI assistance. The human submitter reviewed every changed line, understands the implementation and tests, and can defend the change end to end.

Duplicate-work check: searches for DataProtoItem consistency and protocol consistency found no matching open PR. The only protocol-related result, #4030, addresses DataProto.concat timing metadata and is unrelated.

Checklist Before Starting

  • Searched for similar PRs using the query links above; no duplicate implementation was found.
  • Formatted the PR title as [{modules}] {type}: {description}.

Test

  • uvx --with hydra-core pre-commit run --files verl/protocol.py tests/test_protocol_on_cpu.py
    • All hooks passed, including Ruff, Ruff format, Mypy, generated-config verification, license, device/API checks, test structure, and Python compilation.
  • python -m pytest -q tests/test_protocol_on_cpu.py
    • 41 passed, with one upstream PyTorch nested-tensor warning.

API and Usage Example

No new API is introduced. Construction now fails early for inconsistent values instead of allowing an invalid DataProtoItem to propagate. Existing valid construction remains unchanged.

item = DataProtoItem(batch=batch[0], non_tensor_batch={}, meta_info={})
item.check_consistency()

Design & Code Changes

  • Add DataProtoItem.__post_init__() so validation always runs after dataclass construction.
  • Add public check_consistency() for explicit revalidation after mutation.
  • Cover a valid indexed item plus batched-TensorDict and non-dictionary metadata failures.

Checklist Before Submitting

  • Read the Contribute Guide and AGENTS.md.
  • Applied pre-commit checks to every changed file.
  • Documentation changes are not applicable because this is an internal invariant check with no new user-facing API.
  • Added targeted CPU unit tests covering the new behavior.
  • Upstream CI request has not been posted to Slack or Feishu; it can be requested after maintainer triage.
  • Recipe submodule update is not applicable.

Assisted-by: OpenAI Codex
Signed-off-by: 0z5a <dinadegttyarenko6@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant