Commit Graph

75 Commits (40efec2c24e3d55e3e0ef10881dd07f94e10df94)

Author SHA1 Message Date
Neil Ge 40efec2c24
Merge 9cb07dd1ec into e41bf7cacf 2026-09-20 19:49:53 +08:00
Linxiushen cb08b9300b [fix] train_tokenizer 读预训练语料时产出 0 条文本,静默训出空词表
get_texts() 只解析 data.get('conversations'),但主线预训练数据
pretrain_t2t(_mini).jsonl 的每行是 {"text": ...}(README「数据集下载」一节)。
把 DATA_PATH 指向预训练语料时,生成器一条文本都不产出,BpeTrainer 仅基于
initial_alphabet 训练,得到一个没有任何 merge 的词表,全程不报错。

复现(改 DATA_PATH 为任意 pretrain_t2t*.jsonl,或直接调用):

    from train_tokenizer import get_texts
    sum(1 for _ in get_texts('../dataset/pretrain_t2t_mini.jsonl'))
    # 修复前: 0
    # 修复后: 1270238

改动:
- get_texts 同时兼容 {"text": ...} 与 {"conversations": [...]} 两种格式
- 产出 0 条时 raise ValueError,而不是让调用方拿到一个空词表
- 把硬编码的 `if i >= 10000: break` 提为模块级 MAX_LINES(默认 0 = 全量)。
  原先这一行也会让 SFT 语料只用前 10000 行,且无从关闭;
  另外它按「行号」计数而非「有效文本条数」,遇到空内容或解析失败的行会提前耗尽配额。

验证:用 pretrain_t2t 的前 3000 篇跑 train_tokenizer(vocab_size=2000),
得到 vocab=2000 / merges=1708;修复前同样输入得到 0 条 merge。
两种格式各 20000 行的合成数据上,产出条数均为 20000(修复前分别是 0 和 10000)。
2026-09-20 10:33:51 +08:00
jingyaogong 7a9137d2e9 [update] trim verbose ddp comments 2026-09-15 14:53:11 +08:00
basil-k-aji-dev 37ac206e9a [perf] skip the per-forward RoPE buffer broadcast in the RL trainers
Follow-up to the review on #854.

DDP re-broadcasts every registered buffer from rank 0 on each forward. The only
buffers here are freqs_cos / freqs_sin, which each rank computes deterministically
from config and never mutates from data, so the broadcast moves identical bytes
every step for nothing.

Verified with a two-rank CPU/Gloo run: with broadcast_buffers=False the
gradients stay identical across ranks and so do the buffers.

Also document the critic's tied-embedding assumption. CriticModel.forward never
calls lm_head, which is only safe under DDP because tie_word_embeddings (default
True) makes lm_head.weight the same Parameter as embed_tokens.weight. Untied, it
becomes a genuinely unused parameter and DDP raises.
2026-09-14 22:22:00 +05:30
jingyaogong 21ec325dba [update] simplify safe math eval 2026-09-14 23:55:32 +08:00
jingyaogong cdf0a93e02
Merge pull request #847 from a0917-cell/fix/safe-math-eval
[fix] 用 AST 求值器替换工具里的 eval(),并修复 Windows 上工具调用全部静默失败
2026-09-14 23:34:28 +08:00
basil-k-aji-dev 9c088dd3a5 [fix] route RL trainer forward through DDP so gradients all-reduce
train_grpo.py, train_ppo.py and train_agent.py wrap the policy in
DistributedDataParallel but run the loss-bearing forward through
.module, bypassing the wrapper. DDP arms its gradient all-reduce hooks
inside DistributedDataParallel.forward(), so calling .module directly
means backward() performs no all-reduce: every rank steps on purely
local gradients and the replicas silently diverge. Only rank 0 is
saved, so multi-GPU RL training quietly degrades to single-GPU
training on 1/N of the data with no error.

The supervised trainers are unaffected; they already call the wrapped
module. no_grad uses of .module (rollout generation, checkpoint
saving) are left untouched, where unwrapping is correct.

Single-GPU behaviour is unchanged: with no process group, model is the
bare module and these calls are identical to before.
2026-09-14 14:54:07 +05:30
jingyaogong a3c7b01cc0 [fix] keep agent rollout token-aligned #850 2026-09-10 11:44:05 +08:00
tkgcc 0f6803e551 [fix] replace tool eval() with an AST math evaluator
execute_tool() relied on signal.SIGALRM, which does not exist on Windows.
The AttributeError was swallowed by a bare except, so every tool call
silently returned None and the model always observed
{"error": "tool not found"} (issue #846).

calculate_math also ran eval() on model-generated text. Two of the three
call sites (scripts/eval_toolcall.py, scripts/web_demo.py) passed no
globals at all, leaving full builtins reachable from sampled output.

safe_math_eval() in trainer_utils.py parses the expression with ast and
walks it, allowing only arithmetic operators and a math whitelist, with
caps on expression length and exponent size. It cannot loop forever, so
the signal-based timeout is no longer needed and is removed. Both sqrt(x)
and math.sqrt(x) spellings keep working.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 07:53:33 +08:00
neil.ge 9cb07dd1ec perf: enable fused AdamW in pretrain training
Same fused AdamW optimization as the full SFT script, using the
existing device_type variable so the CPU-only path is unaffected.

Co-authored-by: TRAE CLI <traecli@bytedance.com>
2026-09-05 19:16:51 +08:00
neil.ge 859c8ee2a3 perf: enable fused AdamW in full SFT training
Use PyTorch's fused AdamW implementation to reduce optimizer kernel
launch overhead and speed up the training step on CUDA devices.
Guard with device check so the CPU-only fallback path is unaffected.

Co-authored-by: TRAE CLI <traecli@bytedance.com>
2026-09-05 18:37:04 +08:00
jingyaogong 6fc918beb6 [update] remove expert args 2026-09-04 22:16:38 +08:00
Justin Guese fc585a9bf9 [update] 把随机种子暴露到命令行
trainer 里的种子此前硬编码为 42(setup_seed(42 + rank) 与每轮的
setup_seed(42 + epoch)),要跑多种子实验只能改源码。新增 --seed,
默认 42,与改动前完全一致。
2026-09-03 15:36:14 +07:00
Justin Guese c3199c7240 [update] 把 num_experts / num_experts_per_tok 暴露到命令行
此前要改专家数只能去编辑 model_minimind.py。三个入口
(train_pretrain / train_full_sft / eval_llm)的默认值与 MiniMindConfig
一致(4 / 1),默认行为不变;RL 与 agent 相关的 trainer 不动。
2026-09-03 15:13:29 +07:00
jingyaogong 89d674b8a5 [refactor] PPO cleanup 2026-07-23 11:11:05 +08:00
jingyaogong 2d4c385b0f [fix] PPO rollout mode
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-23 11:05:51 +08:00
FloatFrank 1191fc8e9f [fix] PPO: align mb_resp_logp with old_resp_logp under autocast
Move log_softmax for mb_resp_logp inside autocast_ctx so it is upcast
to fp32, matching the rollout path (compute_per_token_logps runs under
no_grad+autocast). Previously log_softmax ran outside autocast on
fp16/bf16 logits, introducing a ~1e-2 systematic bias between
mb_resp_logp and old_resp_logp, so ratio != 1 and KL != 0 even before
any weight update. Under sparse rule-based rewards (e.g. math PPO)
this bias destabilises training.

Also add:
- --rollout_eval_mode (default 1): switch actor to eval during rollout
  to disable dropout and keep old/new logp consistent.
- --debug_log_ratio: optional diagnostic printing |mb-old| on the first
  minibatch to verify ratio ~= 1.
2026-07-21 18:51:42 +08:00
jingyaogong 3f1a7cc25b [fix] ddp exit hang 2026-06-01 17:50:39 +08:00
jingyaogong 4497610ec0 [fix] issue#771 2026-05-19 17:40:03 +08:00
jingyaogong 802c15b2b4 [feat] reduce RL memory 2026-05-06 15:07:28 +08:00
TKiteRunner 10776417aa fix: resolve CUDA OOM in train_grpo.py on GPUs with <=8GB VRAM 2026-05-06 14:14:15 +08:00
jingyaogong bdee223036 [fix] inference bug 2026-05-03 20:48:48 +08:00
jingyaogong 773e451b11 [fix] bugs 2026-04-27 19:16:08 +08:00
jingyaogong 6361510016 [fix] rollout bugs 2026-04-27 17:54:09 +08:00
jingyaogong 5416a44471 [fix] bugs 2026-04-21 13:03:34 +08:00
jingyaogong e796b8028a [fix] lora compile 2026-04-10 00:01:21 +08:00
jingyaogong 5351424bf0 [fix] lora moe 2026-04-09 16:36:48 +08:00
jingyaogong aa3e6affa1 [update] add a comment 2026-04-09 15:09:58 +08:00
jingyaogong b8b3d35257 [update] change default seq_len 2026-03-26 10:09:06 +08:00
jingyaogong 101d7df2da [update] minimind-3 2026-03-25 23:57:45 +08:00
readlnh cf4b49a348 [fix] align log/save last-step check and ETA with 1-indexed step 2026-03-24 02:01:40 +01:00
readlnh d25500d363 [fix] gradient accumulation step alignment 2026-03-24 01:45:04 +01:00
jingyaogong 11a44340ba [update] save interval 2026-01-30 20:30:50 +08:00
jingyaogong fea69cf338 [fix] data skip 2026-01-18 16:56:29 +08:00
jingyaogong f7ffdf1fdb [update] shuffle data 2026-01-18 16:39:34 +08:00
jingyaogong c090b69c4d [update] align loss 2026-01-15 00:56:32 +08:00
jingyaogong e119db8478 [fix] compile unpack 2026-01-14 20:13:32 +08:00
jingyaogong 81d24a4f16 [feat] add compile 2026-01-14 14:42:30 +08:00
jingyaogong df89069362 [update] params log 2026-01-07 23:08:45 +08:00
jingyaogong 07364c3fbe [update] rename train tokenizer 2026-01-06 01:17:33 +08:00
jingyaogong 4e73f34823 [update] rename reason 2026-01-05 23:12:29 +08:00
jingyaogong 42a4e8c86a [fix] dist cleanup 2026-01-02 22:25:55 +08:00
jingyaogong 9d898576ac [update] aux loss 2026-01-01 22:41:46 +08:00
jingyaogong c65335b56f [fix] experts unused 2025-12-31 21:47:04 +08:00
jingyaogong bc8fd82166 [fix] layers set 8 2025-12-31 21:06:37 +08:00
jingyaogong 5dd4df7e18 [fix] moe unused 2025-12-31 21:00:06 +08:00
jingyaogong 9236260a4a [feat] get params 2025-12-31 20:46:59 +08:00
jingyaogong 288a1d7212 [feat] get params 2025-12-31 20:44:34 +08:00
jingyaogong 6242980917 [feat] update lr 2025-12-31 10:27:09 +08:00
jingyaogong 7eae14f3ce [feat] remove empty_cache 2025-12-27 07:14:36 +08:00