Skip to content

feat(agentic): weight-version spans and policy provenance audit (No.15) - #516

Open
hongwei-2026 wants to merge 1 commit into
redai-studio:mainfrom
hongwei-2026:feat/task15-weight-version-audit
Open

hongwei-2026 wants to merge 1 commit into
redai-studio:mainfrom
hongwei-2026:feat/task15-weight-version-audit

Conversation

@hongwei-2026

@hongwei-2026 hongwei-2026 commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary

  • Record per-call absolute token spans (WeightVersionsPerCall) for successfully committed generation, covering multi-turn agentic rollout and partial-rollout abort/resume prefixes.
  • Add side-channel rollout/policy_provenance/* metrics that separate generation version span, post-generation wait lag, token-weighted lag, and missing/unknown version rates without changing sampling or GRPO group semantics.
  • Ship Session/turn/segment diagnostics plus a reproducible tool-wait example under examples/agentic_weight_version_audit/.

Task

Closes contributor-program task No.15: Agentic 异步训练的权重版本追踪与滞后审计.

Related: #321

Test plan

  • pytest tests/utils/test_weight_version.py (10 passed)
  • PYTHONPATH=. python examples/agentic_weight_version_audit/reproduce_tool_wait_audit.py
  • CI required checks
  • Mentor review (@yuanlehome)

Collaborators

Record per-call token spans for committed generation, report generation
span vs post-generation lag for selected training samples, and ship a
reproducible Session/turn diagnostic for async agentic tool waits (No.15).

Co-authored-by: Cursor <[email protected]>
@rai-studio-bot

rai-studio-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @hongwei-2026! 感谢你为 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 / 状态
审批人数 ⏳ 0/1 · 至少 1 位有仓库 write 或更高权限的人 Approve
团队审批(relax-block-reviewers) ⏳ 0/1 · 可联系:Aurelius84, Yangruipis, yuanlehome, SigureMo, NINGBENZHE
CI ❌ 未通过

@hongwei-2026

Copy link
Copy Markdown
Author

协作说明:本 PR 由 @hongwei-2026 提交,组队队友请 @yuhongming-2026 共同跟进 CI / review(对应 Issue #321 认领账号)。

@rai-studio-bot

rai-studio-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: 🚧 需要修改

审查版本: efa600a

目标分支: main

已完成固定版本的 11 个变更文件及相关调用链审查。版本跨度的三层列表会使默认 TensorDict 转换失败,阻断带版本样本进入训练队列;另确认消费版本接线和有效 token 计权两处审计偏差。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已检查 Session 提交、暂停恢复、失败重试、分支导出、Sample 序列化、采样复制及示例;记录路径未确认其他新增缺陷。
深度审查 ✅ 已完成 定向 CPU 复现确认:带版本单 token 样本在 head 转换失败而基线成功;v2 样本缺少消费版本时年龄为 0;mask 排除旧 token 后仍计入年龄。复核了默认普通及 Agentic 交接链路。无多节点 GPU 环境,未验证真实引擎和分布式集成;取消竞态仅做源码分析。

CI 异常

检查版本: efa600a · 已分析

失败检查原因与现状证据建议下一步
Pre-commit Checks 确定性的 lint/格式问题:示例脚本两处 E402,且 Ruff、mdformat、docformatter 报告需要改写文件。 run 41015676913 第 2 次运行的 Run prek 步骤失败,checkout 为 head efa600a 合入 base ea3f0ce 的 6293031。E402 位于 reproduce_tool_wait_audit.py:29–30;ruff check 报 3 项问题(修复 1 项、剩余 2 项),ruff format 改写 4 个文件,mdformat 改写示例 README,docformatter 也报告改写。日志未单列 docformatter 的文件归属。https://github.com/redai-studio/Relax/actions/runs/41015676913/job/123939773052#step:4:1 保留示例的独立运行能力并处理两处 E402,运行仓库 pre-commit hooks、提交必要的格式修正,再由正常 PR CI 验证新版本。
Qwen3-4B-4xnpu-async 训练数据交接遇到三层 weight_versions,触发默认 TensorDict 转换的深度限制;与已报告 P1 为同一原因。 run 41015676872 第 2 次运行的 Run integration test 步骤在 07:15:30 UTC 报 ValueError(weight_versions 嵌套深度 3,最大支持 2),调用链为 transfer_batch_to_data_system → convert_samples_to_train_data:222 → dict_to_tensordict:378。日志确认 checkout 为 efa600a 合入 ea3f0ce 的 6293031;未见先发设备、OOM 或超时错误。https://github.com/redai-studio/Relax/actions/runs/41015676872/job/123939809960#step:7:1 按现有 P1 修正版本跨度的传输表示及消费契约,再验证该 NPU 异步集成检查。原发现:https://github.com/redai-studio/Relax/pull/516#discussion_r4421201692
Qwen3-4B-4xgpu-async 默认训练转换拒绝三层 weight_versions;与已报告 P1 及 NPU 集成失败为同一原因。 run 41015676872 第 2 次运行的 Run integration test 步骤在GPU 异步 rollout 第 0 步失败:transfer_batch_to_data_system → convert_samples_to_train_data:222 → dict_to_tensordict:378,明确报 weight_versions 嵌套深度 3、最大支持 2 的 ValueError。日志确认 checkout 为 efa600a 合入 ea3f0ce 的 6293031。该日志未打印实际 span payload。https://github.com/redai-studio/Relax/actions/runs/41015676872/job/123939809970#step:8:1 按现有 P1 修正版本跨度的传输表示及消费契约,再验证该集成检查。原发现:https://github.com/redai-studio/Relax/pull/516#discussion_r4421201692
Qwen3-VL-4B-2xgpu 默认训练转换拒绝三层 weight_versions;与已报告 P1 及 NPU 集成失败为同一原因。 run 41015676872 第 2 次运行的 Run integration test 步骤在多模态 rollout 转换阶段失败:transfer_batch_to_data_system → convert_samples_to_train_data:222 → dict_to_tensordict:378,明确报 weight_versions 嵌套深度 3、最大支持 2 的 ValueError。日志确认 checkout 为 efa600a 合入 ea3f0ce 的 6293031。该日志未打印实际 span payload。https://github.com/redai-studio/Relax/actions/runs/41015676872/job/123939809986#step:8:1 按现有 P1 修正版本跨度的传输表示及消费契约,再验证该集成检查。原发现:https://github.com/redai-studio/Relax/pull/516#discussion_r4421201692

审查发现

待处理
编号 严重性 问题状态规则来源
F1 High severity 版本跨度的三层列表阻断默认训练交接 🚧 未解决 —
F2 Medium severity 未接入训练消费时的已发布版本 🚧 未解决 No.15:实际训练 token 来源与消费时版本滞后
F3 Medium severity 加权年龄计入了 loss mask 排除的旧 token 🚧 未解决 No.15:实际训练 token 来源与消费时版本滞后
已解决或已取代
编号 严重性 问题状态规则来源
暂无已解决或已取代的记录。
提交范围 · 接收 11 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
relax/agentic/session/service.py
relax/agentic/session/state.py
relax/engine/rollout/data_source.py
relax/utils/metrics/rollout_metrics.py
relax/utils/types.py
relax/utils/utils.py
relax/utils/weight_version.py
接收 生成片段版本记录、序列化及训练样本审计指标属于现有 Session 和 rollout 职责。 No.15 官方任务要求成功提交片段的 token 区间、多轮/恢复覆盖及实际训练样本的版本滞后统计。 沿现有 SessionForest、Sample 和 rollout 指标扩展,当前目录符合职责。
tests/test_agentic_rollout.py
tests/utils/test_weight_version.py
接收 为片段记录和版本审计提供可持续的回归保护。 No.15 验收要求覆盖多轮、暂停恢复、缺失版本和取消重试。 保留在 tests 的对应模块,便于长期回归。
examples/agentic_weight_version_audit/README.md
examples/agentic_weight_version_audit/reproduce_tool_wait_audit.py
接收 复用生产 SessionForest 与审计函数,提供可复现的工具等待诊断用例。 No.15 明确要求诊断示例及工具等待期间两次权重更新的可复现展示。 当前 examples 目录适合此用户可运行示例,验证其行为与说明是否一致。
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.

需要修改

发现会阻断默认训练数据交接的回归,当前不建议合入。已检查固定版本的 11 个变更文件和相关调用链,并用定向 CPU 复现核实问题;本地无多节点 GPU 环境,未执行分布式集成验证,真实取消竞态也未实测。

审查看板

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

Comment on lines +69 to +74
if any(sample.weight_versions for sample in samples):
current_version = getattr(args, "current_weight_version", None)
if current_version is not None:
current_version = int(current_version)
log_dict |= dict_add_prefix(
compute_policy_provenance_metrics(samples, current_version=current_version),

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.

Medium severity P2 · 接入训练消费时的已发布权重版本

生产代码没有设置 args.current_weight_version,这里只能回退到本批样本的最大生成版本;而调用点是 rollout 结束,并非训练消费边界。样本全来自 v2、等待到已发布 v7 才训练时,当前路径的 avg_staleness、avg_post_generation_staleness 和 token 加权滞后全部为 0,真实年龄应为 5。新增字段也未被 train_async 的 data_fields 读取,因此把跨度放入训练数据尚未补上这条链路。请在实际消费这些样本时关联同一策略的已发布版本序号并计算审计值;缺少消费版本时应显式标记不可用或下界,避免将它呈现为消费滞后。这是 No.15 明确要求的消费时刻关联,示例中手工传入版本无法验证生产接线。

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

Comment on lines +218 to +225
for span in iter_sample_weight_spans(sample):
numeric = parse_numeric_version(span.version)
if numeric is None:
unknown_span_count += 1
unknown_token_count += span.token_count
continue
versioned_token_count += span.token_count
token_version_sum += numeric * span.token_count

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.

Medium severity P2 · 按有效训练 token 汇总版本年龄

这里对每个跨度的完整长度计权,未与 sample.loss_mask 相交。已有 mask_offpolicy_in_partial_rollout 会把恢复前的旧前缀置零,因此旧前缀并不参与训练:例如两个响应 token 分别来自 v2/v7,mask 为 [0, 1]、消费版本为 v7 时,应报告有效 token 的年龄 0,目前却得到 token_weighted_staleness=2.5、最旧年龄 5。请保留完整来源记录,但在训练旁路审计时按响应区间与有效 loss mask 裁剪跨度,再计算年龄和覆盖率,不改变现有采样或 GRPO 处理。

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

Comment thread relax/utils/utils.py
Comment on lines +205 to +208
if any(sample.weight_versions for sample in samples):
from relax.utils.weight_version import encode_weight_versions_for_train

train_data["weight_versions"] = [encode_weight_versions_for_train(sample) for sample in samples]

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.

High severity P1 · 为版本跨度使用训练转换器支持的表示

批首样本首轮有版本跨度时,这里生成 [sample][call][span dict] 三层列表,随后第 222 行交给仅支持两层列表的 dict_to_tensordict,直接报 ValueError: Unsupported nesting depth 3 for key 'weight_versions'。最小复现中,一个通过 update_from_meta_info 标记 v7 的单 token 响应即失败;同一输入使用基线转换器成功。普通 rollout 和 Agentic 的默认交接路径都会调用此转换器,异常发生在 async_put 之前,导致正常带版本样本无法进入训练队列。请为旁路元数据提供兼容的表示或独立传递路径,并补充经过默认 convert_samples_to_train_data 的回归用例;只测试跨度助手函数无法覆盖此边界。

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants