Repository navigation
【No.15】feat(agentic): audit weight versions at training consumption - #670
AllureCurtain wants to merge 11 commits into
Conversation
Track committed generation token intervals and successful policy publications, then join their provenance with final objective masks and optimizer outcomes. Report generation span, post-generation waiting lag and token-weighted ages. Preserve sparse training masks and publish DCS versions after quantization finalization. Add a reproducible CPU Session/tool-wait/publication/optimizer example and regressions for provenance, publication and loss accounting. Relates to redai-studio#321
|
Thanks for contributing to Relax, @AllureCurtain! 感谢你为 Relax 做出贡献! 📚 Contribution guide / 贡献指南Describe the problem, your changes, and how you validated them. Keep each PR focused and run 请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 🛠️ CI commands / CI 指令
Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access. 在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。 🔎 Merge requirements / 合入条件GitHub:⏳ 合入条件未满足
|
|
/review Please review commit 86af3c7. |
…ercount ## 🐛 Bug Fix Address two review findings where the weight audit could certify a complete effective mask while missing tokens that still participate in the objective: - `custom_loss` objectives may nest `policy_loss_function` and add further targets; the nested policy call previously wrote a `complete` mask before the outer terms ran. Reject certification up front with `custom_loss` so final membership stays unknown, matching the documented contract. - Sequence-ratio objectives (GSPO) build a differentiable sequence ratio from every log-prob inside `loss_masks` before per-token TIS/OPSM gating zeroes outer terms. Rejected tokens still contribute through the ratio, so a per-position mask cannot be exact: report `sequence_ratio_unresolved` whenever any in-mask token is filtered, unless an auxiliary entropy/KL term already keeps full-mask membership. ## ✅ Tests - New regressions drive the real `policy_loss_function` on CPU: GSPO+ICEPOP partial rejection reports unknown, full acceptance stays exact, and a `custom_loss` policy call reports `custom_loss` rather than `complete`. - Verified rejected tokens still receive gradient through the shared sequence ratio (-0.5 per position), confirming undercount was real.
…receivers
## 🐛 Bug Fix
Address two further review findings:
- **GPU scalar read in the loss hot path**: the previous sequence-ratio check
evaluated `(base & ~policy).any()` on training-device masks, converting the
result to `bool` triggers `.item()` and blocks the CUDA stream on every
micro-batch. Whether a gate actually filtered lives on the device, so the
combination is now conservatively reported `sequence_ratio_unresolved`
whenever a per-token gate (TIS weights or OPSM mask) is present — a pure
CPU-side check that preserves the corrected accuracy without synchronizing.
- **Divergent PP receiver sets**: each PP source rank prunes its DCS HTTP
proxy receivers independently, so sets can diverge (PP0={A,B}, PP1={B})
without any explicit rejection; a partially installed engine would then
inherit the new version label. `commit_publication` now gathers the
per-rank receiver key sets and certifies only when all reporting sets are
identical, leaving the evidence unknown otherwise.
## ✅ Tests
- GSPO regressions updated: gated sequence-ratio objectives report unknown,
an ungated GSPO objective stays exact; gradient sync removed from the path.
- New two-rank Gloo regression covers the intersection-non-empty-but-unequal
receiver sets the review called out: divergent sets stay unknown while
identical sets certify normally.
Provide the generation provenance defaults used by MsgNode in the existing six-stream observation test, so its trajectory writer can exercise the full prompt-to-training linkage after weight auditing was added. Reproduced the missing-field failure before the change. All 230 related CPU observation and audit tests and the full pre-commit checks pass afterward.
|
/review Please review the two-line test-fixture update in The CPU CI failure in Validation: all 230 tests across The separate Ray startup failure occurred before the test body; that fixture is identical to the base and upstream main, and the other parameter variant passed in the same CI run. Its discarded startup output does not establish the cause. Both previously failing cases now explicitly pass in CPU CI on Local Ray follow-up: the exact failing Final CI verification on |
|
麻烦帮这个 PR 补一下 |
Keep the LoRA session binding and managed-lora routing while preserving the weight-version audit fields. Record per-attempt generation segments and only treat an install as certified when all receiver sets match. - session: bind lora adapter before audit snapshot; keep adapter id as raw_version, leave certified source unknown without a publication map - device_direct: upstream restructured push-failure handling; commit publication unconditionally on the non-adapter path - tests: cover DCS receiver rejection and managed abort/resume segments
Restrict publication begin to the same full-weight paths as commit so adapter synchronization cannot leave the audit ledger in updating or replace the frozen base label with an uncertified epoch label. Extend the existing quantized-adapter lifecycle regression with the real publication helper and ledger behind mocked transport. The old condition fails with an updating snapshot; the fix passes both initial and delta sync checks. Apply the two ruff-format changes required by CI. Validation: 25 targeted CPU tests pass, including two-process Gloo publication tests; full pre-commit passes. Broader rollout tests require SGLang and managed publication tests require Megatron, absent locally. GPU/NPU and multi-node integration are left to repository CI.
Preserve generation-source auditing and publication certification while incorporating the latest session replay and recovery behavior.
| def weight_audit_enabled(args: Any) -> bool: | ||
| """Custom router middleware may require numeric labels; leave it | ||
| unknown.""" | ||
| return agentic_obs_enabled(args) and not ( | ||
| getattr(args, "use_slime_router", False) and getattr(args, "slime_router_middleware_paths", None) | ||
| ) |
There was a problem hiding this comment.
合入的 #805 已移除 Python SlimeRouter 和自定义中间件。若旧 YAML 仍带有 use_slime_router: true 和非空的 slime_router_middleware_paths,--custom-config-path 仍会把它们写进 args。原生路由照常运行,这里却会关闭发布审计,即使用户已启用 --dump-agentic-obs。
建议直接复用 agentic_obs_enabled,并删除仅覆盖旧路由分支的测试、示例参数和双语说明。 路由迁移约定 · YAML 参数覆盖
There was a problem hiding this comment.
已在 a335286 核实:中英文指南都移除了关于旧 SlimeRouter 中间件关闭审计的说明,和现行审计开关一致。原意见已处理。
| result.meta_info["engine_weight_version"] = result.meta_info.get("weight_version") | ||
| result.meta_info["weight_version"] = str(session.lora_binding.version_id) | ||
| elif audit_enabled: | ||
| end_version = await generation_snapshot(audit_coordinator) |
There was a problem hiding this comment.
Fully Async 下,权重发布可以在 adopt_response 等待 replay 存储确认期间完成。此时后端已经返回,但这里才读取结束序号。受控 CPU 复现中,后端返回时序号为 1,接管期间发布 2,最终把生成年龄和生成后等待从预期的 (0, 1) 记成了 (1, 0)。
建议在后端返回时发起快照读取,让 replay 接管照常进行。在接管成功且 IR 仍有效后使用读到的序号。这样可以保留 main 的引用清理顺序。 生成结束边界
There was a problem hiding this comment.
已在 feadc0e 核实:Session 在 replay 接管前发起结束快照,只有仍有效的 IR 才会写入分段记录。定向 CPU 回归通过,接管期间推进发布序号后,记录仍使用接管前的序号。本轮未运行真实分布式 replay 交错。
| from relax.utils.agentic_obs.weight_publication import generation_snapshot, weight_audit_enabled | ||
|
|
||
| audit_enabled = weight_audit_enabled(self.args) | ||
| audit_coordinator = getattr(self, "_sglang_request_limiter", None) |
There was a problem hiding this comment.
There was a problem hiding this comment.
已在 feadc0e 核实:启用审计时直接读取已初始化的请求协调器,关闭审计时跳过读取。原意见已处理。
Capture the generation-end publication frontier as soon as the backend returns, before replay adoption can wait on remote storage. Use the snapshot only after adoption succeeds and the request remains current. Enable weight auditing directly from Agentic observability, remove the obsolete router-flag gate, and initialize the CPU demo shard's cleanup state. Expose subprocess output when the demo regression fails.
## ✅ Tests ### Fix CPU observability regressions after direct limiter reads - Set `_sglang_request_limiter` to None in `_session_observation_fixture`, matching the constructor attribute that `_run_ir` now reads directly; a None coordinator yields the documented unknown-evidence path in `generation_snapshot`, so audit-free assertions are unchanged - Fixes 6 CPU failures: `test_session_attempt_tokens_include_abort_and_cleanup_result` (x4) and `test_request_infra_failure_closes_call_as_failed` (x2) ## 📝 Documentation ### Drop stale Slime router audit caveat - Remove the EN/ZH guide claim that custom Slime router middleware disables publication tracking: the Python SlimeRouter was removed upstream in redai-studio#805 and legacy YAML fields no longer gate weight auditing
|
/review Please review commit a335286a. It fixes the 6 Unit Tests (CPU) failures reported on feadc0e:
It also drops the stale Slime router audit caveat in both guides ( |
| adapter-only LoRA and uninstrumented backends cannot provide certified ages. | ||
| Audit-enabled publishers use a unique lifetime prefix in backend labels to prevent | ||
| restart collisions. Missing coordinator access also yields unknown evidence; | ||
| receiver rejections never count as successful publications. Certification additionally requires every PP |
There was a problem hiding this comment.
上文同时介绍了 Megatron tensor/distributed 和 DCS,容易让读者以为三条路径都会校验每个 PP 源的接收集合。实际比较只读取 DCS 的字典式接收集合。两种 Megatron updater 使用序列,仍会检查接收拒绝,但不向这项比较提供集合。建议在英文和中文对应句都加上 DCS 限定。校验实现 · 中文对应句
| receiver rejections never count as successful publications. Certification additionally requires every PP | |
| receiver rejections never count as successful publications. For DCS, certification additionally requires every PP |
There was a problem hiding this comment.
两份指南现在正确区分了 DCS 的接收集合校验和两种 Megatron updater 的接收拒绝检查。还有一个范围需要补齐。Hybrid 的权重更新也会调用 update_weights_fully_async(..., rollout_only=True),DCS 在确认完整或合并权重发布前会执行相同的 PP 接收集合比较。建议把两份指南中「仅 fully-async DCS」改为「通过 DCS 更新完整或合并权重时(包括 Fully Async 和 Hybrid)」。Hybrid 调用路径 · DCS 发布校验
## 📝 Documentation ### Clarify which updaters feed the receiver-set comparison - Note in both guides that only fully-async DCS updates certify identical receiver sets across PP source ranks; both Megatron updaters still check receiver rejections but store engines as sequences, not the dict the comparison reads - Addresses the non-blocking P3 review suggestion on PR redai-studio#670
|
/review Please review commit 74d84cd0, a docs-only clarification of the PP receiver-set certification scope per your P3 suggestion: both guides now state that only fully-async DCS updates feed the receiver-set comparison, while both Megatron updaters still check receiver rejections but do not participate in the set comparison (their |
## 📝 Documentation ### Extend the DCS scoping to hybrid mode - Hybrid pushes weights actor-to-rollout through the same DCS DeviceDirect path as fully-async, so the PP receiver-set certification applies there too; previous wording covered only fully-async - Follow-up to the P3 review suggestion on PR redai-studio#670
|
/review Please review commit 4cab9b2a, a follow-up docs correction: hybrid mode pushes weights actor-to-rollout through the same DCS DeviceDirect path as fully-async, so both guides now scope the PP receiver-set certification to DCS updates in fully-async and hybrid modes. |




What
Add weight-version provenance and consumption-age reports to Agentic training observations, enabled with
--dump-agentic-obs.The report traces effective training tokens back to their Session, turn and generation attempt. It separates version changes during generation from the wait between generation and training consumption.
Why
A multi-turn Agent can wait for a tool across several weight publications, generate again, then queue for training. Tracking committed token intervals and successful policy publications makes these different sources of lag measurable.
Relates to #321, contributor-program task 15.
How
For source publication
v, generation-end publicationeand consumption publicationc, generation age ise-v, waiting lag isc-e, and consumption age isc-v.Testing
Validated on macOS arm64 with Python 3.12:
pre-commit run --all-files --show-diff-on-failure: all hooks passed.npm run docs:build: passed.Targeted regression command
CUDA_VISIBLE_DEVICES='' python -m pytest -q --disable-warnings --tb=short \ tests/cpu/utils/test_weight_audit.py \ tests/cpu/utils/test_weight_publication.py \ tests/cpu/utils/test_agentic_obs.py \ tests/cpu/test_agentic_observability.py \ tests/cpu/distributed/checkpoint_service/test_dcs_fused_weight_buckets.py \ tests/cpu/distributed/checkpoint_service/test_weight_sync_lifecycle.py \ tests/cpu/components/test_rollout_weight_update_handshake.py \ tests/cpu/core/test_initial_weight_sync.py \ tests/cpu/test_agentic_rollout.py::test_agentic_weight_segments_follow_committed_partial_content \ tests/cpu/test_agentic_rollout.py::test_agentic_run_ir_requeues_empty_delta_abort_without_clearing_prefix \ tests/cpu/test_agentic_rollout.py::test_agentic_context_exhaustion_preserves_partial_generation \ tests/cpu/test_agentic_rollout.py::test_agentic_no_decode_capacity_returns_context_error_without_commitpre-commit run --all-filespassespytest tests/)Type of Change
Screenshots / Logs
Run the CPU example in a fresh process with project dependencies:
CUDA_VISIBLE_DEVICES='' python -m examples.agentic_weight_audit.demo --output weight-demo.json python -m relax.utils.agentic_obs.weight_report weight-demo-records --output rebuilt-report.jsonThe example generates 4 tokens with publication 1, waits for a tool while publications 2 and 3 complete, then generates 6 tokens with publication 3. Training consumes the sample after publication 4.
trueThe example uses a controlled generation backend, a real local Ray coordinator and Gloo publication hooks, and a CPU PyTorch loss/backward/SGD update. Raw JSONL records are written beside the report for independent inspection.