Repository navigation
[v5] 复用 Twinkle metric 记录 GRPO 性能指标 - #10512
Merged
Merged
Conversation
2 of 4 tasks
qychen2001
force-pushed
the
feat/add-log
branch
from
November 4, 2026 07:59
8c82b63 to
42d8242
Compare
Use Twinkle timing primitives, throughput metrics and native metric reporting. Keep iteration boundaries and sample accounting in GRPO, preserve the flat WebUI stream, and replace dedicated performance writers and remote observation threads with typed records. Co-authored-by: Codex
Extract stateless rollout timing and metric helpers into shared recipe utilities. Reuse Twinkle reporter normalization while preserving raw observations and legacy percentage values. Validation: 226 focused tests passed; historical metric replay and before/after accounting parity passed. Full pre-commit retains baseline failures, with no new Ruff findings in changed files. Co-authored-by: Codex
Move batch observation state, timing, training counters, memory snapshots and reporting into shared recipe utilities. Keep GRPO responsible for training and publication boundaries, support custom sample length extraction, and use a single recorder reference. Validation: 244 focused regression tests passed. Nine batch records and three run summaries match the prior implementation. Full pre-commit retains baseline failures, with no new Ruff findings in changed files. Statistics overhead was not benchmarked. Co-authored-by: Codex
tastelikefeet
approved these changes
Nov 6, 2026
Preserve rollout length balancing and generation-batch derivation alongside shared batch observations. Record balance metrics inside the timed optimizer update and count the reordered training samples. Add coverage for balancing and batch accounting in the same update. Validation: 406 focused regression tests passed against the latest dev-swift-v5 Twinkle source. Two distillation budget assertions and one CLI import test also fail on the unmodified target branch. Full pre-commit retains existing lint and formatting failures. Co-authored-by: Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
Related issue: 暂无。依赖配套 Twinkle #368,建议先合入 Twinkle。
为 Swift v5 GRPO 保存可复算的性能观测,复用 Twinkle 的计时、Metric 和输出接口。Swift 负责训练流程的边界与计数,不维护独立
performance.py、JSONL writer 或 RPC 观察线程。TimeRecorder / span,worker 方法使用@timed;辅助 forward 保持并发提交。优化器副作用在完成并传播错误后才记录成功更新。twinkle.metric.ThroughputMetric与memory_metrics;窗口吞吐使用总 token / 总秒数 / 物理设备数。RunTracker → MetricRecord → MetricsReporter。metrics_raw.jsonl区分train、rollout(scope=iteration)、run,summary.json保存终态汇总;包含 run_id、时间戳、阶段和优化器步数。原有 WebUImetrics.jsonl的平铺格式和频率保持兼容。performance.jsonl、optimizer_metrics.jsonl及其 writer;原始计时区间、prompt/response 长度和每卡内存读数放在 attributes,便于训练结束后核算。adv_pipeline,涵盖辅助前向和信号解析;worker 的原始方法耗时单独保留。不推测每条 RPC 的端到端时长,不把重叠阶段相加。本次整轮阶段观测覆盖 GRPO。只提交代码和测试,没有新增独立文档文件。使用 Codex 辅助实现、测试和提交,人工逐行 review 与提交者最终责任确认仍待完成。
Experiment results
2026-11-06 在最终实现上完成 3 轮真实 GRPO 训练。配置:8×PPU-ZW810(96 GiB)、Qwen3.5-4B、FSDP2、colocate、rollout TP=2×4、每轮 8 prompts×8 completions=64 条轨迹;每卡微批次 2、梯度累积 4、seed=42、thinking=false、回答上限 1024、context 上限 5120,不保存 checkpoint。回答上限 1024 用于缩短本次记录链路验证。
检查结果:
metrics_raw.jsonl共 7 条:3 条train、3 条rollout(scope=iteration)、1 条run;同一 run_id,包含时间戳和明确的优化器步数。WebUImetrics.jsonl保持原有平铺格式,共 3 条。summary.json正确汇总 24 个生成组、192 条生成样本、192 次训练样本访问、3 次更新,无记录丢弃。全窗口吞吐为 138.920 token/s/GPU,按总 token / 总逻辑秒数 / 8 计算。完整进程耗时 398.561 秒,含环境和模型初始化。这是一轮集成验证,不据此给出稳定提速或收敛结论;首轮含首次调用开销。阶段观测不相互独立,不能把并发或嵌套时间直接相加。
验证对应的提交:
4b0e012768ecb39d96ad759452f7834efa6f10d0160c12be82162b6a72ba16dbf007cab453cced6e训练时使用未提交工作区,提交后已逐文件核对两仓提交内容与被测源码的 SHA-256 一致。原始配置、源码变更快照、日志、逐步 CSV、验证结果和提交核验保存在本地
scripts/performance_a1/output/20261106-metric-pipeline-three-iterations/,实验产物不加入代码 diff。回归与静态检查
在两仓共同父目录、
swift-test环境运行:结果:236 passed, 4 warnings。覆盖 token/时间归一化、窗口吞吐采用总量之比、长度统计、内存转换、追加写入、并发记录、终态总数、日志重叠只扣一次、训练尾批/重复访问、辅助前向并发提交、远程优化器失败传播、发布边界和 WebUI 兼容。
其中 11 项来自既有 reporter 测试的隔离执行:原
test_async_rl_metrics.py导入当前检出缺失的twinkle_agentic.async_rl.metrics,无法整文件收集;临时文件仅去掉该无关导入及依赖它的 helper 测试,保留 reporter 测试行为。副本和运行日志保存在实验目录checks/;不声明该原始测试模块或全仓测试全部通过。两仓
git diff --check通过。完整pre-commit run --all-files已在隔离源码目录执行,仍有仓库已有的 Ruff、格式和文件末尾换行问题;批量格式化未带入提交,不声明全仓 lint 通过。Checklist