/fold-cp:shard_data_feats [1d | 2d] [feature group: atom | token | msa | pair | all]from fold-cp
Implements distributed data-feature sharding for context-parallel models: assigns DTensor placements to features, builds placement dictionaries, implements atom-feature pack/pad/scatter, and creates DTensor Dataset/DataLoader/DataModule with parity tests.
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 model's distributed forward reads each feature at a specific placement; the data pipeline must produce it at exactly that placement, or the CP boundary mismatches (shape error at best, silent wrong-sharding at worst). This skill builds that producer side. Placement tables, the file map, and the padding/index rules are in reference.md; read it before implementing.
docs/current_code_structure.md §3 (data-feature inventory) exists. If not, run
/fold-cp:learn_context first.docs/cp_infra.md names the target topology (1d/2d) and world_size. If
not, run /fold-cp:build_infra.$BOLTZ_CP_REPO is known; tech guide §1 Data Feature Sharding is the
reference for this skill.For each row of the feature inventory, assign a placement from the tables in reference.md, driven by axis semantics (tokens / atoms / MSA depth / ensemble / pair), not by guessing from shape. The CP sub-mesh placement (without DP) is:
(cp0, cp1): token/atom/single [N,…] → (Shard(0), Replicate());
pair [N,N,…] → (Shard(0), Shard(1)); ensemble [E,N,…] → (Shard(1), Replicate()).(cp,): single/token/atom/pair-first-N → (Shard(0),); MSA [S,N,…] →
(Shard(1),); replicated scalars → (Replicate(),).DP is prepended later by the collate step — do not bake it into per-feature placements. Record the final placement back into the inventory table.
Co-shard coupled axes — placement of the second axis is not free. A feature with
two token-like axes must place those axes consistently with the algorithm that
consumes it, or distributed gather/scatter reads off-rank data: pair [N, N, …]
(token×token) → 2D (Shard(0), Shard(1)) (the square tile), 1D (Shard(0),); and an
atom→token [N_atoms, N] feature must have its atom axis and the token axis it indexes
co-sharded (same cp axis) or co-replicated, never sharded independently. See the
"Co-sharding multi-semantic-axis features" section in reference.md and
dtensor_modules/module_map.md.
Create a dict mapping the user's feature names to their placement tuples,
mirroring $BOLTZ_CP_REPO/src/boltz/distributed/data/module/placements.py
(and placements_1d.py). This dict is the single source of truth shared by the
data pipeline and the model forward — the same names, the same placements. Keep a
FEATURE_AXIS_SEMANTICS registry alongside it (per axis: "tokens", "atoms",
"msa", None) so padding logic never has to guess when N_tokens == N_atoms.
Atom features map to tokens and shard in parallel with N. Mirror
featurizer.py:pad_and_scatter_atom_features_dtensor and pack_atom_features:
pack per-token atom windows, pad the atom axis to a multiple of the mesh size,
and scatter to the owning rank with indices that stay consistent with the token
sharding. See reference.md "Atom scatter & index remap".
Why pad at all: torch.distributed collectives/P2P need identical per-rank buffer
shapes (see the fold-cp hard rules), so the sharded axis must divide evenly across
the mesh, and every axis sharing its semantics must match the same padded length.
N % cp != 0, pad the sharded axis to the next
multiple of cp before distribution, and mark the pad positions invalid in the
propagated mask.N. Drive this from the FEATURE_AXIS_SEMANTICS registry, never from
raw shape comparison. Mirror trainingv2_1d.py:_prepare_features_for_distribution.distribute_features + broadcast_feature_tensors_metadata patterns from
data/utils.py: rank 0 (or the serial fetcher) produces features, metadata is
broadcast so all ranks build matching DTensor.from_local with explicit
shape/stride/placements (Rule 9 — never let it infer).CollateDTensor (2D) / CollateDTensor1D (1D) analogue
mapped onto your mesh (map_subgroup_mesh_to_cpu / map_mesh_to_cpu_1d).Mirror the Boltz data modules for both workflows:
data/module/inferencev2.py (inferencev2_1d.py).data/module/trainingv2.py (trainingv2_1d.py).Adapt the user's existing Dataset/DataLoader/DataModule (or Lightning
LightningDataModule) to emit DTensor batches at the locked placements. Preserve
the serial dataset as ground truth (Rule 2) — wrap or subclass, don't rewrite it.
Wire cross-rank fetch-error propagation (_error_propagation.py) so a failed
serial fetch on one rank raises on all ranks instead of deadlocking.
Before testing, audit (see reference.md checklist): local-vs-global
index semantics agree between data and model; mask polarity is consistent; pad
positions are masked; atom-to-token indices remap correctly after repad
(remap_atom_indices_repad).
Hand off to /fold-cp:test to build the data parity test (mirror
tests/distributed/data/): assemble the DTensor features with full_tensor() and
assert equality to the serial features; assert sharding is active when cp_size > 1 (local
shape < global on the sharded axis; cp=1 ⇒ local == global); assert masks/pads and cross-axis
padding are correct;
include the non-power-of-two cp boundary case.
0..N/cp−1 vs global 0..N−1), not just the primary
token/pair/atom features./tmp/$USER/.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
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.
/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).
/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.
Other plugins' skills for the same job