Skip to content

perf(agentic): compress loss masks as intervals - #605

Merged
xiaoliang0601 merged 2 commits into
redai-studio:mainfrom
xiaoliang0601:codex/agentic-loss-mask-ranges
Nov 10, 2026
Merged

xiaoliang0601 merged 2 commits into
redai-studio:mainfrom
xiaoliang0601:codex/agentic-loss-mask-ranges

Conversation

@xiaoliang0601

@xiaoliang0601 xiaoliang0601 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Store the Agentic training-input loss mask as nonzero token intervals in train JSONL. Relates to #555.

Why

Tool observations and model responses often form long runs of the same mask value. The interval representation keeps the positions needed for debugging while making those records smaller.

How

  • Encode loss_mask.ranges in the background writer as zero-based [start, end, value] triples with an exclusive end. Positions outside the ranges are zero up to response_length.
  • Compute effective_tokens from the interval lengths and values. Integer mask weights and all-zero samples can be reconstructed exactly.
  • Advertise train schema 4.0.0 through train_schema_version in the manifest. The format guide documents v3 arrays and v4 intervals, and the regression checks both with the existing DP update merge.

Testing

  • pre-commit run --all-files passes
  • Tests pass (pytest tests/)
  • New tests added (if applicable)
  • Documentation updated (if applicable)

The Agentic observability, JSONL writer, and stream-join CPU suites passed 201 tests. The round-trip test covers integer mask values and checks the same merged update summary for v3 and v4 records. The CUDA snapshot test skipped on the local CPU host, and integration tests require multi-node GPU hardware.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • CI/CD or build changes

Screenshots / Logs

The 42-token synthetic mask in the round-trip regression takes 126 bytes as a JSON array and 37 bytes as an interval object, counting the field value only.

Store nonzero mask runs as half-open response-token intervals in the
background train writer. The response length and interval values allow
lossless reconstruction and preserve the effective token sum.

Advertise the new train stream schema in the manifest and document both
encodings. Exercise JSONL round trips, zero masks, and update merging
with legacy records.
@rai-studio-bot

rai-studio-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @xiaoliang0601! 感谢你为 Relax 做出贡献!

📚 Contribution guide / 贡献指南

Describe the problem, your changes, and how you validated them. Keep each PR focused and run pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

🛠️ CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

🔎 Merge requirements / 合入条件

GitHub:❔ 部分检查未通过

Requirement / 条件 Status / 状态
审批人数 ✅ 1/1 · 至少 1 位有仓库 write 或更高权限的人 Approve · 已审批:Yangruipis
团队审批(relax-block-reviewers) ✅ 1/1 · 已审批:Yangruipis
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: da17cd4

目标分支: main

已完成 da17cd4 的八个文件及相关调用路径审查,未发现需修改的问题。区间边界、全零 mask、整数权重、schema 标识和 DP 合并契约一致。当前 head 的 pre-commit 已通过;CPU/GPU/NPU CI 尚在运行。本轮未运行本地测试或多节点训练;作者报告的 201 项 CPU 测试结果未独立复跑。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已核对后台写入、JSONL 的 ID/元组序列化、训练记录版本与 manifest、DP 合并及中英文文档;检查了新增往返回归和三个更新的断言路径。
深度审查 ➖ 无需执行 未发现需要额外实验或独立调查的实质疑点;本次变更是一项连贯的观测格式调整。

没有未解决的审查问题。

提交范围 · 接收 8 · 建议移出 0 · 待确认 0

接收 8 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
relax/utils/agentic_obs/config.py
relax/utils/agentic_obs/records.py
relax/utils/agentic_obs/train_hooks.py
接收 Agentic 训练观测记录的区间编码和版本标识,属于现有观测模块职责。 PR #605 的 What/How:压缩 train JSONL loss_mask 并标识 train schema 4.0.0。 沿用现有 agentic_obs 生产路径,当前位置适合此局部变更。
tests/cpu/test_agentic_observability.py
tests/cpu/utils/test_agentic_obs_isolation.py
tests/test_agentic_observability_cuda.py
接收 既有观测测试覆盖 JSONL 编码往返、六类数据流关联、DP update 合并和 CUDA 快照。 PR #605 的格式保真要求与仓库 CPU/GPU 测试归类规则。 扩展现有模块测试,无需新增独立验证工具。
docs/en/guide/agentic-rollout.md
docs/zh/guide/agentic-rollout.md
接收 双语格式说明解释新旧 schema 和区间边界,服务既有 JSONL 读取契约。 PR #605 的 breaking format change 及仓库双语文档约定。 更新现有 Agentic 格式章节是合适位置。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查通过

已审查 da17cd4 的区间编码、版本标识、JSONL 写入、DP 合并及配套文档和测试,未发现需修改的问题。Pre-commit 已通过;CPU/GPU/NPU CI 尚在运行。本轮未运行本地测试或多节点训练。

审查看板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@xiaoliang0601
xiaoliang0601 merged commit a1b88ed into redai-studio:main Nov 10, 2026
14 of 16 checks passed
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.

3 participants