Repository navigation
refactor(cookbook): configure examples directly in Python - #428
Merged
kevssim merged 3 commits intoDec 2, 2026
Merged
Conversation
Replace the retired twinkle.cli parser with recipe-local settings and keep the shell launchers focused on process setup.
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues cause default recipes to fail during import or model configuration and allow the documented RSI launch to execute generated commands on the training host instead of the requested sandbox.
3 open issues
What changed in this PR
Moves cookbook configuration into Python scripts, removing dependencies on the deleted twinkle.cli module while keeping shell scripts responsible for launching examples.
Changes:
- Replaces CLI arguments with editable Python settings across training and sampling recipes.
- Simplifies launchers and makes many script paths independent of the working directory.
- Updates AgentEnv, OpenEnv, and RSI configuration instructions.
| File | Description |
|---|---|
| cookbook/transformers/spectral_hybrid_lora.sh | Simplifies training launch. |
| cookbook/transformers/spectral_hybrid_lora.py | Inlines allocation and training settings. |
| cookbook/transformers/sp_fsdp_dense.sh | Removes training flags. |
| cookbook/transformers/sp_fsdp_dense.py | Inlines sequence-parallel settings. |
| cookbook/transformers/fsdp2.sh | Simplifies torchrun launch. |
| cookbook/transformers/fsdp2.py | Inlines training and checkpoint settings. |
| cookbook/transformers/ep_fsdp2_lora_qwen3_5_moe.sh | Removes training flags. |
| cookbook/transformers/ep_fsdp2_lora_qwen3_5_moe.py | Inlines expert-parallel LoRA settings. |
| cookbook/transformers/ep_fsdp2_lora_deepseek_v4.py | Inlines settings; derives parallel sizes from WORLD_SIZE. |
| cookbook/transformers/ep_fsdp2_lora_deepseek_v4_multinode.sh | Retains cluster setup and launch. |
| cookbook/sample/sample.py | Inlines model and adapter settings. |
| cookbook/sample/emb_sample.py | Removes CLI dependency; imports os. |
| cookbook/rsi/run.sh | Exports sandbox and agent settings. |
| cookbook/rsi/rsi_grpo.py | Replaces CLI configuration with constants and environment settings. |
| cookbook/rsi/agentic/rsi_agent.yaml | Updates configuration names in comments only. |
| cookbook/rsi/agentic/README.md | Documents revised agent launch. |
| cookbook/rl/ppo/ppo.sh | Simplifies PPO launch. |
| cookbook/rl/ppo/ppo.py | Inlines PPO hyperparameters. |
| cookbook/rl/multi_turn/multi_turn_grpo.py | Inlines multi-turn training settings. |
| cookbook/rl/grpo/short_math_grpo.sh | Simplifies short-math launch. |
| cookbook/rl/grpo/short_math_grpo.py | Inlines short-math settings. |
| cookbook/rl/grpo/short_math_grpo_routing_replay.sh | Removes routing-replay flags. |
| cookbook/rl/grpo/short_math_grpo_routing_replay.py | Inlines replay and parallelism settings. |
| cookbook/rl/grpo/short_math_grpo_multi_lora.sh | Simplifies multi-adapter launch. |
| cookbook/rl/grpo/short_math_grpo_multi_lora.py | Inlines training and adapter-sync settings. |
| cookbook/rl/grpo/short_math_grpo_moe.sh | Simplifies MoE launch. |
| cookbook/rl/grpo/short_math_grpo_moe.py | Inlines MoE training settings. |
| cookbook/rl/grpo/mbpp_grpo.py | Inlines MBPP training settings. |
| cookbook/rl/grpo/kodcode_grpo.py | Inlines KodCode training settings. |
| cookbook/rl/grpo/grpo.sh | Simplifies GRPO launch. |
| cookbook/rl/grpo/grpo.py | Inlines GRPO settings. |
| cookbook/rl/grpo/grpo_sampling_replay.sh | Removes sampling-replay flags. |
| cookbook/rl/grpo/grpo_sampling_replay.py | Inlines settings and updates validation message. |
| cookbook/rl/grpo/grpo_mm.sh | Simplifies multimodal GRPO launch. |
| cookbook/rl/grpo/grpo_mm.py | Inlines multimodal training settings. |
| cookbook/rl/grpo/group_admission.sh | Updates launch and smoke-test guidance. |
| cookbook/rl/grpo/group_admission.py | Inlines group-admission settings. |
| cookbook/rl/gkd/gkd_on_policy.sh | Simplifies on-policy distillation launch. |
| cookbook/rl/gkd/gkd_on_policy.py | Inlines student, teacher, and loss settings. |
| cookbook/rl/gkd/gkd_off_policy.sh | Simplifies off-policy distillation launch. |
| cookbook/rl/gkd/gkd_off_policy.py | Inlines distillation settings. |
| cookbook/rl/envs/train.py | Centralizes backend-independent training settings. |
| cookbook/rl/envs/run_openenv.sh | Keeps connection setup; removes training flags. |
| cookbook/rl/envs/run_agentenv.sh | Keeps connection setup; removes training flags. |
| cookbook/rl/envs/README.md | Documents Python configuration and smoke tests. |
| cookbook/rl/dpo/dpo_multi_lora.sh | Simplifies multi-adapter DPO launch. |
| cookbook/rl/dpo/dpo_multi_lora.py | Inlines DPO, device, and sample settings. |
| cookbook/rl/dpo/dpo_lora.sh | Simplifies LoRA DPO launch. |
| cookbook/rl/dpo/dpo_lora.py | Inlines settings; scales mesh with device count. |
| cookbook/rl/dpo/dpo_full.sh | Simplifies full-parameter DPO launch. |
| cookbook/rl/dpo/dpo_full.py | Inlines settings and parameterizes device meshes. |
| cookbook/mm/fsdp2.sh | Simplifies multimodal launch. |
| cookbook/mm/fsdp2.py | Inlines OCR training settings. |
| cookbook/mm/fsdp2_gemma4_mm.sh | Simplifies Gemma launch. |
| cookbook/mm/fsdp2_gemma4_mm.py | Inlines Gemma training settings. |
| cookbook/mm/fsdp2_gemma4_12b_mm.py | Inlines model, dataset, and mesh settings. |
| cookbook/megatron/tp.sh | Simplifies Megatron launch. |
| cookbook/megatron/tp.py | Inlines parallelism and checkpoint settings. |
| cookbook/megatron/tp_moe.sh | Removes MoE training flags. |
| cookbook/megatron/tp_moe.py | Inlines MoE parallelism and training settings. |
Review effort: Balanced
|
|
||
| # Cookbook configuration. | ||
| FSDP_SIZE = None | ||
| DP_SIZE = None |
Comment on lines
+202
to
+203
| SANDBOX_TEMPLATE = os.environ.get('SANDBOX_TEMPLATE', '') | ||
| SANDBOX_API_URL = os.environ.get('SANDBOX_API_URL', '') |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Default Gemma to a one-rank data mesh. Reject removed RSI flags before setup and document sandbox configuration through the environment.
kevssim
approved these changes
Dec 2, 2026
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
Twinkle 移除 twinkle.cli 后,部分 Cookbook 仍导入旧的参数解析器,启动时会报 ModuleNotFoundError。本 PR 将这些示例迁移到脚本内配置,让读者打开 Python 文件就能看到模型、数据集、并行度和训练参数。
以 FSDP2 为例,先在 cookbook/transformers/fsdp2.py 中编辑 MODEL_ID、DATASET_ID、FSDP_SIZE 和 DP_SIZE,然后运行:
sh cookbook/transformers/fsdp2.sh
调整卡数时,需同步调整启动脚本中的设备列表和 --nproc_per_node。
Experiment results
PR 提交 141fbd3 的 31 个 Python 文件和 26 个 Shell 脚本均通过语法检查,修改后的 Python 示例已移除对 twinkle.cli 的导入。
在 Ascend 910B4 上使用本地模型和数据,对同一迁移改动做了以下短程训练验证: