一键导入
explain-architecture
Walk through KempnerForge's subsystems in the order a forward pass encounters them. Starting point for anyone new to the codebase.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Walk through KempnerForge's subsystems in the order a forward pass encounters them. Starting point for anyone new to the codebase.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | explain-architecture |
| description | Walk through KempnerForge's subsystems in the order a forward pass encounters them. Starting point for anyone new to the codebase. |
This skill is read-only. It does not run anything.
Run:
uv run python scripts/check_env.py
Baseline only (uv, repo layout). If the exit code is non-zero, fix the baseline first, otherwise file paths below may not resolve.
Top-level package: kempnerforge/ Subsystems: config, model, distributed, data, training, checkpoint, resilience, metrics, profiling Entry point: scripts/train.py (does NOT use torchrun internally; caller launches it) Config system: kempnerforge/config/{schema,job,data,eval,optimizer}.py with registry.py for pluggable components Model stack: embedding -> transformer.py (blocks of attention + mlp/moe) -> norm -> output projection Parallelism layers: FSDP2 (distributed/parallel.py), TP (distributed/tensor_parallel.py), PP (distributed/pipeline_parallel.py), EP (distributed/expert_parallel.py) Data path: dataset.py (MemoryMapped | HF | Mixture) -> sampler.py (DistributedSampler) -> dataloader.py (StatefulDataLoader) Checkpoint: checkpoint/manager.py orchestrates DCP save/load, state.py owns state dict layout, async_save.py handles non-blocking writes Resilience: resilience/ (signal handlers, NaN detection, NCCL health) Metrics: metrics/tracker.py dispatches to backends (wandb, tensorboard), mfu.py computes MFU, memory.py tracks peak memory
Walk the user through the path a single forward+backward pass takes. Use the outline below and follow up only on the subsystems they ask about.
scripts/train.py calls load_config(toml_path, cli_args) from kempnerforge/config/.--section.key=value CLI overrides.JobConfig is the top-level container. Inspect the sections: ModelConfig, TrainConfig, OptimizerConfig, SchedulerConfig, DistributedConfig, DataConfig, CheckpointConfig, MetricsConfig.kempnerforge/config/registry.py via @register_* decorators. Read the registry to see what names are valid for each component.kempnerforge/distributed/setup.py::init_distributed() reads MASTER_ADDR / MASTER_PORT (or SLURM env vars) and calls torch.distributed.init_process_group.DeviceMesh from distributed/parallel.py gives the training loop a multi-dimensional view (DP x TP x PP) that each subsystem queries.scripts/slurm/multinode.sh) sets env vars; this function only consumes them.kempnerforge/model/transformer.py::Transformer composes: embedding -> N blocks (TransformerBlock) -> final norm -> output projection.TransformerBlock has an Attention (model/attention.py, SDPA-based GQA with RoPE from position.py) and an MLP (model/mlp.py SwiGLU, or model/moe.py for mixture of experts with a router from router.py).distributed/parallel.py applies fully_shard() (FSDP2) per block. If TP or PP is enabled, they compose via parallelize_module and DeviceMesh.kempnerforge/data/dataset.py holds three dataset types: MemoryMappedDataset (pre-tokenized .npy, fastest), HuggingFaceDataset / StreamingHuggingFaceDataset (HF Hub), MixtureDataset (weighted combination of sub-datasets with phase scheduling).data/sampler.py::DistributedSampler partitions indices across data-parallel ranks. set_skip(n) supports exact resume from mid-epoch.data/dataloader.py::StatefulDataLoader wraps the torch DataLoader and tracks enough state (epoch, batch index, sampler skip) to restore the exact batch after checkpoint load.kempnerforge/training/optimizer.py builds the optimizer (AdamW fused, Lion, Muon, schedule-free) from [optimizer] config via the registry.training/scheduler.py builds the LR scheduler. Registered names: cosine, linear, wsd, constant, rex, none.training/grad.py owns gradient utilities: clipping, accumulation (maybe_no_sync context manager for FSDP), NaN detection hooks.scripts/train.py runs the loop directly (no framework wrapper). Each step: forward, loss (training/loss.py), backward, optional gradient accumulation, optimizer step, scheduler step, metrics log, checkpoint if interval hit.model/transformer.py::get_moe_aux_loss), which train.py adds to the main loss before backward().kempnerforge/checkpoint/manager.py::CheckpointManager orchestrates save and load. Uses torch.distributed.checkpoint (DCP), which automatically handles FSDP sharded state and reshards on load.checkpoint/state.py defines what goes in the state dict: model, optimizer, scheduler, dataloader position, RNG state.checkpoint/async_save.py wraps dcp.async_save so training continues while writes are in flight.latest symlink in checkpoint.dir, falling back to the highest step_N directory.kempnerforge/metrics/tracker.py::MetricsTracker collects per-step scalars with optional EMA smoothing, then dispatches to enabled backends (wandb, tensorboard).metrics/mfu.py computes model FLOPs utilization from the model config and measured step time.metrics/memory.py tracks peak GPU memory, with an optional snapshot export for pytorch.org/memory_viz.resilience/ owns signal handlers (SIGTERM/SIGUSR1 for SLURM preemption), NaN action policies, and GPU/NCCL liveness probes that run every N steps.None. This skill is informational. Ask the user which subsystem they want to dig into, then point them at the specific files and classes listed above.
scripts/train.py, not inside a Trainer class. Deliberately flat, easy to read top to bottom. Do not try to find a class Trainer.fully_shard() (composable), NOT FullyShardedDataParallel (the v1 class). Old tutorials do not apply.scripts/train.py takes the TOML path as a positional arg, not via --config. CLI overrides are --section.key=value, double dash./kempnerforge:component-gaps — ask-it-what-is-built-vs-planned for each subsystem./kempnerforge:add-optimizer — concrete walkthrough of the training/optimizer.py + registry pattern.Run `uv sync` and the four CI gate checks (ruff check, ruff format, pyright, pytest unit). First command after cloning. Auto-handles non-CUDA hosts via `--no-sources`.
Add a new optimizer to KempnerForge. Covers implementation, registry hook, config fields, tests, and a preset TOML.
First-run setup. Detect SLURM account/partition/QoS from env and write configs/cluster/local.toml so every other skill can preflight.
Per-subsystem status report. What is implemented, what is tested, what is planned but unwired, and known limitations.
Submit a training job via sbatch. Wraps singlenode.sh for one node and multinode.sh for multiple. Injects account, partition, QoS, and time overrides from local.toml.
End-to-end one-GPU sanity check. Runs a short training loop to confirm torch, CUDA, NCCL, uv, and the dataloader all work before committing to longer runs.