/fold-cp:dtensor_modules [module name] [1d | 2d]from fold-cp
Implements 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.
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.
The serial module is the mathematical specification. The CP version must produce numerically equivalent forward+backward while holding only its O(N/cp) (single) or O(N²/(cp0·cp1)) (pair) shard. The serial→CP dictionary with all I/O placements, collectives, and backward budgets is in module_map.md — look up the target there first.
docs/current_code_structure.md §4 (module map) names the target's serial
block and its CP-candidate status (reuse / adapt / new).docs/cp_infra.md gives the topology (1d/2d) and world_size./fold-cp:shard_data_feats at known placements.In module_map.md find the target's row: serial file, 2D/1D CP
file, tech guide §, input placements, output placements, collectives,
and backward memory budget. If the target is in the substrate-primitive
catalog, prefer composing it from those utilities over writing a new
autograd.Function.
A reference CP layer = an app-agnostic ALGORITHM + a reference-SPECIFIC placement
contract; reconcile the contract before reusing it. The Boltz file's ring / skew /
gather algorithm is reusable, but the axes it shards vs replicates are Boltz's data
contract and may differ from your model's (e.g. Boltz shards MSA-depth S where your
model replicates it; a different window-edge convention). Blindly vendoring the core
imports fine but fails parity. So: check the reference core's placement contract
against YOUR data placements (from shard_data_feats / current_code_structure.md §3)
first; if they match, reuse it; if they differ, reuse the algorithm but re-derive the
collective schedule for your contract. Algorithm-reuse and contract-match are
orthogonal — a row marked "reuse" can still need a contract re-derivation.
Read the serial module (the user's, and the Boltz serial twin if it maps cleanly). Record:
feats dict
(masks, atom→token indices, bias tensors, ensemble indices). Each such field has
a required placement; cross-check it against the data-feature inventory
(current_code_structure.md §3) and the placement dictionary from
shard_data_feats. An undocumented feature input at the wrong placement is the
most common CP integration bug.elementwise_op,
sharded_op, shardwise_op, …) — each checks placements at its boundary;
flexible and auditable. Canonical: modules/encoders.py:_atom_encoder.autograd.Function — to_local() once, plain
PyTorch math, explicit collectives, one from_local(). Canonical:
loss/distogram.py.Forward:
device_mesh; assert even sharding for every Shard (collectives
need equal per-rank buffer shapes — Rule 8); reject unhandled Partial. Do not read
ctx.needs_input_grad in forward (use tensor.requires_grad).@torch.amp.custom_fwd(device_type="cuda") / custom_bwd, then audit the
dtype path end-to-end against the app's precision semantics (Rule 19): operands cast
to the compute dtype before math, every communicated buffer pinned to one dtype across
ranks (a per-rank/autocast-dependent dtype deadlocks send/recv), and no unintended
up/down-cast (correctness-silent but a transient peak-memory hazard — see mem_profile).torch.promote_types(dtype, torch.float32), never .float().DTensor.from_local(..., shape=<global>, stride=<global via update_exhaustive_strides>, placements=<...>) — never let it infer (Rule 9).Backward:
_all_reduce_grad_gteqfp32).Module wiring:
__init__ registration order exactly,
so named_parameters()/state_dict() line up in parity tests.zeros_like, reshape, repeat_interleave, squeeze) — use dtensor_zeros,
to_local()/from_local(), or the substrate utilities. Elementwise .to(dtype)
is safe.loss/distogram.py).Insert the module into the model's distributed forward mirroring the serial order.
Confirm the producer→consumer placement contract with each neighbor: the
upstream module's output placement must equal this module's input placement
(Rule 4). If you are porting several coupled modules, this reconciliation is the
job /fold-cp:dispatch_work enforces between paired agents.
Hand to /fold-cp:test at the right level:
autograd.Function vs its serial twin;Dataset/DataLoader/DataModule that reuses the production
distributor; tests subset the feature set), not ad-hoc per-feature randint, so the test
also exercises the featurizer→module seam (Rule 4) — see /fold-cp:test Step 2.2;Always serial fwd+bwd as ground truth, explicit random grad_output, fp64, and
the anti-vacuous checks. Pin each new operator with its own parity test before
moving downstream.
docs/current_code_structure.md §4 updated to "done", and
any newly-resolved feature-input placements written back to §3.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
11 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.
/build_infraProbe and establish the distributed test infrastructure for CP development. Inventories local GPUs (count, model, memory, NVLink topology), checks the software stack (Python, PyTorch+CUDA, NCCL, torch.distributed), and runs shipped smoke tests for batch_isend_irecv P2P, all_gather, all_reduce, reduce_scatter, and a DTensor round-trip. Maps the GPU count to which CP topologies are testable (2D needs >=4 GPUs, 1D needs >=2 ideally 3, full integration wants 8). When no local GPUs are available, generates a SLURM submission template and guides the user to provide cluster access. Records docs/cp_infra.md. Use after learn_context, before shard_data_feats / dtensor_modules / test.
/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).
npx claudepluginhub nvidia-bionemo/boltz-cp --plugin fold-cpOther plugins' skills for the same job