/fold-cp:build_infra [--local | --slurm] [requested world size]from fold-cp
Probes local GPU hardware and software stack for distributed PyTorch development, runs collective smoke tests, and maps GPU count to testable CP topologies. Generates SLURM submission template when no GPUs are available.
Ships in fold-cp. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
CP code cannot be developed or trusted without multi-GPU execution. This skill
proves the environment can run the collectives CP depends on, and decides which CP
topologies are testable here. Run the shipped scripts; do not hand-wave the
checks. All scripts live in scripts/ under this skill
(${CLAUDE_SKILL_DIR}/scripts).
nvidia-smi -L # count + model
nvidia-smi --query-gpu=index,memory.total,memory.used --format=csv
nvidia-smi topo -m # NVLink / PCIe topology
Note which GPUs are free (other users may occupy a shared node — respect
manage_gpu hygiene if available: never use a GPU you did not claim).
| Free GPUs | 2D-CP (supported) | 1D-CP (experimental) | Integration |
|---|---|---|---|
| >=8 | yes — cp0=cp1=2 (+ dp>=2) | yes — cp up to 8 | full end-to-end |
| 4–7 | yes — cp0=cp1=2 | yes | limited |
| 3 | no (needs perfect square >=4) | yes — cp=3 (also covers non-power-of-two) | no |
| 2 | no | yes — cp=2 (minimum) | no |
| 0–1 | no | no | escalate to SLURM (Step 5) |
2D-CP requires size_cp a perfect square (cp0=cp1); the smallest is 4. 2D is the supported,
default topology. 1D-CP runs at any cp>=1 (cp=3 also exercises non-power-of-two sharding), but
1D-CP is EXPERIMENTAL — known pending bugs, unestablished inference-set / training-curve parity, and
paths gated at cp>1 (e.g. confidence).
1D-CP gate (Rule 25). Whenever 1D is the chosen topology — the user asked for it, or the box has <4 free GPUs / cannot form a perfect-square mesh so only 1D is feasible — before recording it in
cp_infra.md: (a) warn the user plainly that 1D is experimental with pending bugs; (b) pause for a one-time at-own-riskAskUserQuestion(proceed with 1D at my own risk / switch to 2D — get ≥4 GPUs for a square mesh / abort); (c) record the acknowledgement incp_infra.md. Prefer 2D whenever the hardware allows it. This sign-off is required even when a caller runs in--automaticmode.
Record the chosen config(s).
python "${CLAUDE_SKILL_DIR}/scripts/probe_env.py"
It reports Python / PyTorch / CUDA / NCCL versions, torch.cuda.is_available(),
per-GPU compute capability and memory, free disk space, the NVIDIA driver
version, and a self-consistency verdict (see the next section), plus a
recommended CP-config JSON derived from the live GPU count. If PyTorch lacks a CUDA
backend, or versions are incompatible with the target model, stop and surface it to
the user. (Point the disk check at your real work dir with
FOLD_CP_WORKDIR=<path>; it defaults to the cwd.)
Resolve the ONE environment that satisfies BOTH constraints: a torch built for the
GPUs' arch (e.g. sm_120/Blackwell needs a recent CUDA) AND the target model importable
in it. The interpreter may not be on PATH (pixi/conda) and the model may not be
pip-installed — find the env where both import torch (right arch) and
python -c "import <model_pkg>" succeed, and record its absolute interpreter path
in docs/cp_infra.md. Also probe the multi-rank launch prerequisites and bake them
into the recorded recipe:
PYTHONPATH=<repo root> when the model is not pip-installed — mp.spawn (spawn
start-method) workers don't inherit the parent's cwd, so they hit ModuleNotFoundError
without it.fold-cp's skills are model-agnostic: they do not prescribe a fixed GPU SKU or count, because a custom model may ship kernels that only run on certain GPUs (custom CUDA/Triton, an arch-gated attention) — unknowable ahead of time. So the requirement is not "have an H100"; it is a self-consistent stack. Treat this as a high-level guide, not a hard gate — the real gates are the smoke tests (Step 4).
probe_env.py gives the authoritative signal — torch.cuda.is_available()
is True only when driver + CUDA-build + GPU-arch agree — and reports the NVIDIA driver
vs the CUDA build so a mismatch is legible. The two halves probe_env can't settle on its
own: model import (Step 3 — python -c "import <model_pkg>" in the chosen interpreter)
and DTensor / device_mesh support (Step 4 smoke tests). The one hard software floor is
that the runtime supports torch.distributed.tensor DTensor + init_device_mesh — which is
exactly what Step 4 proves.probe_env.py reports free/total
and warns under the threshold; it is a recommendation, not a hard stop./fold-cp:dtensor_modules (the O(N/cp) / O(N²/(cp0·cp1)) backward budget)
and are measured by /fold-cp:mem_profile; training vs inference differ only by fwd vs
fwd+bwd+step, captured by /fold-cp:benchmark on the same mesh. Record the SKU you actually
ran on in cp_infra.md as provenance — do not prescribe one.These self-launch with mp.spawn (no torchrun needed) and must pass before any
CP work. Always timeout-wrap and tee the logs (Rule 16):
WS=<world size from Step 2>
timeout 120 python "${CLAUDE_SKILL_DIR}/scripts/test_collectives.py" --world-size $WS |& tee /tmp/$USER/cp_collectives.log
timeout 120 python "${CLAUDE_SKILL_DIR}/scripts/test_dtensor_smoke.py" --world-size $WS |& tee /tmp/$USER/cp_dtensor.log
test_collectives.py — verifies batch_isend_irecv (ring P2P), all_gather,
all_reduce, and reduce_scatter against analytic expected values on every
rank. A hang here means NCCL/IB misconfiguration — diagnose before proceeding.test_dtensor_smoke.py — builds a DeviceMesh, distribute_tensor, checks
to_local() shapes and a full_tensor() round-trip, and (when WS is a perfect
square) a 2D square-tile placement. This proves the DTensor substrate works here.If a test hangs to the timeout, treat it as a hard failure (likely a deadlock or
transport problem), capture NCCL_DEBUG=INFO output, and resolve before moving on.
If Step 2 yields 0–1 GPUs, CP cannot be tested locally. Then:
scripts/slurm_probe.sbatch with those
values — it requests one node + N GPUs and runs the Step 3–4 probes under
srun. Submit with sbatch, then poll squeue/sacct and read the captured
log. Do not assume success — read the log.docs/cp_infra.md so downstream skills reuse it for every multi-rank run.Write docs/cp_infra.md with: the GPU inventory, the chosen testable CP config(s)
and world_size, software versions, the resource prerequisites (free disk vs the
~150 GB recommendation, NVIDIA driver vs torch's CUDA build, and the
self-consistency verdict from the section above), smoke-test results (paths to the
tee'd logs), and the canonical launch command (local mp.spawn/torchrun or the
SLURM recipe). Downstream skills read this file to know how to launch tests and
benchmarks.
Distributed CP runs hang silently without a few guards — bake them into the launch
recipe in docs/cp_infra.md:
init_process_group (separate NCCL/cuda vs Gloo/cpu
timedeltas) so a deadlock fails fast instead of hanging the session (also Rule 16).TORCH_NCCL_ASYNC_ERROR_HANDLING=1 set before init_process_group, so a rank
that errors tears the group down instead of leaving peers blocked.MASTER_PORT propagation: pick an OS-assigned free port with
SO_REUSEADDR on rank 0 and broadcast it; concurrent worktrees/CI that hardcode a port
collide and rebind-race.PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True at the memory ceiling to fight
fragmentation-driven cudaMalloc retries / spurious OOMs.docs/cp_infra.md exists and names the testable topology + world size and the
exact launch recipe.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
distributed-testing, gpu-inventory, pytorch-collectives, slurm
npx claudepluginhub nvidia-bionemo/boltz-cp --plugin fold-cp11 skills in this plugin
/benchmarkBenchmark a CP inference or training workflow to find the maximum token count that fits at a given CP size and to record end-to-end walltime. Sweeps input size (tokens N, atoms, MSA depth S) over real or synthesized data, ramps N until OOM to report the max, times fwd (inference) or fwd+bwd+step (training) with warmup and median-of-repeats, captures peak memory, and writes a results table to docs/cp_benchmark.md. Use once a CP workflow runs end-to-end, to quantify the memory headroom CP buys and the walltime cost.
/cpize_model_workflowOrchestrate the END-TO-END integration of context parallelism into a custom co-folding / structure-prediction model: turn the whole effort into a prioritized, dependency-sorted worklist, then drive it phase by phase — map the model (learn_context), verify infra (build_infra), shard data features (shard_data_feats), port modules (dtensor_modules, fanned out via dispatch_work), prove correctness (test), wire the trainer/predictor (dist_lifecycle), and finally profile memory and compute (mem_profile, nsys_profile) and benchmark. Use as the front door when the user wants to "CP-ify my model" as a whole program of work — it prioritizes, sequences, and gates the long task list and delegates each task to the right fold-cp skill. Not for a single module (use dtensor_modules + test directly).
/dispatch_workOrchestrate a team of agents to integrate many CP modules and tests in parallel. Builds the work-list from the module map, derives a data-flow dependency graph, topologically sorts it into GPU-slot-bounded waves, and spawns a coder+reviewer pair per work item. Reviewers enforce serial-as-ground-truth, no-vacuous-tests, and the fold-cp hard rules; coupled up/down-stream items cross-review each other's input/output placement contracts before finalizing. Use when the scope is several CP modules and their tests at once — not for a single module (use dtensor_modules + test directly for that).
/dist_lifecycleStand up the distributed-model lifecycle for a CP training/inference run: device placement before DTensor wrapping, the all-trainable-params-are-DTensors invariant (with placeholder/freeze for unimplemented modules), checkpoint save (DTensor → plain) and load (realign via the live state_dict template + redistribute optimizer state to parameter placements), resume RNG seed offset, and DTensor-safe EMA. Use after dtensor_modules + build_infra, when wiring the ported CP modules into a real trainer/predictor (Lightning or custom) and you need checkpoints, resume, or EMA to work — the gap between "modules pass parity" and "training runs and resumes".
/dtensor_modulesImplement DTensor-based context-parallel model modules that mirror a serial reference. Maps each serial layer/module to its Boltz-CP counterpart with exact input/output shapes, placements, collectives, and backward memory budget; writes the CP implementation following the autograd.Function conventions (explicit collectives, no implicit DTensor ops, promote_types, explicit from_local shape/stride, attribute-name + registration-order mirroring); and verifies it against the serial forward+backward via the test skill. Use when porting a custom model's trunk / attention / triangle / OPM / diffusion / confidence / loss modules to CP.
/learn_contextExplore a custom co-folding / structure-prediction model to understand its inference and training workflows, entry points, training framework (PyTorch Lightning vs DeepSpeed), data-feature format, and featurization pipeline — then map those components onto the existing Boltz-CP context-parallel reference so downstream CP integration reuses what already exists. Produces docs/current_code_structure.md. Use FIRST, before any other fold-cp skill, or whenever that doc is missing/stale. Runs interactively (Q&A with the user) or autonomously on request.
Other plugins' skills for the same job