/fold-cp:learn_context [scope: inference|training|data|all] [optional path to model code]from fold-cp
Explores a custom co-folding model to understand its inference/training workflows, data format, and featurization pipeline, then maps components onto the Boltz-CP reference. Produces docs/current_code_structure.md for downstream skills.
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.
Every other fold-cp skill reads docs/current_code_structure.md. This skill
produces it. The user's model is almost never shaped like the Boltz serial code,
so do not assume Boltz layouts — trace the actual code from its entry points
and record what you find.
The deliverable answers one question: which parts of this model can reuse an existing Boltz-CP component, and which need new work?
The reference implementation and its docs are the ground truth for all mapping.
Resolve BOLTZ_CP_REPO in this order, then record the absolute path:
$BOLTZ_CP_REPO env var, if set.fd -t d -d 6 'boltz' ~ 2>/dev/null or look for a dir containing
src/boltz/distributed/ (the CP package).The skills' primary CP reference is bundled in this plugin:
${CLAUDE_PLUGIN_ROOT}/reference/cp_tech_guide.md — per-module CP algorithms, I/O
shapes, placements, collectives, complexity (11 sections; see its Table of Contents).
Always present — no need to locate it.The reference repo provides the distributed code to mirror
($BOLTZ_CP_REPO/src/boltz/distributed/); the governing CP rules are this plugin's
hooks/RULES.md (injected at SessionStart), not a file in the reference repo.
Substrate-boundary scan (do once, up front). Grep the reference's distributed tree
for imports of its OWN non-distributed package, e.g.
grep -rE "from boltz\.(model|data|main)" $BOLTZ_CP_REPO/src/boltz/distributed. This
splits it into the app-agnostic substrate (manager, comm, DTensor op-layers — files
with no such imports, vendorable as-is by a namespace rewrite) and the app-coupled
files (CP layers that import their serial twin — these get rewired to YOUR serial model,
not vendored). Recording this boundary now prevents rediscovering it per-module later
(it directly seeds the reuse/adapt/new column of §4).
If none can be found, ask the user for the repo location before continuing — the mapping cannot be done without it.
$ARGUMENTS (inference, training, data, all, or a
path). Default all.AskUserQuestion
for anything you cannot determine from the code (see Step 6). Prefer answering
from the code first; ask only what tracing cannot resolve.Find the inference entry point and follow the call chain to model.forward.
Look for: a CLI (argparse/click/typer), a predict/infer/sample
function, a Lightning predict_step, or a notebook. Record:
forward → output writing.Reference comparison: Boltz inference enters at
$BOLTZ_CP_REPO/src/boltz/distributed/main.py (cli, predict) →
predict.py (run_predict).
Find the training entry point and identify the framework — this changes how CP wraps the model:
LightningModule (training_step, configure_optimizers),
a Trainer, a LightningDataModule, a custom Strategy. Boltz-CP uses a custom
DTensor strategy — see $BOLTZ_CP_REPO/src/boltz/distributed/lightning_strategy.py
and train.py (train, _create_dist_manager, _create_distributed_model,
_create_distributed_data_module).deepspeed.initialize, ZeRO config JSON, engine.backward/step.torchrun / custom loop: an explicit dist.init_process_group + manual
optimizer loop.Record: entry file + function, framework + version, optimizer/scheduler, EMA, checkpoint format and save/load paths, and how the device/process group is created today (if at all).
This is the highest-value section. Trace dataset → featurizer → collate →
dataloader → datamodule → the dict that reaches forward. For every feature
the model consumes, record a row: name, tensor shape, dtype, and axis
semantics — which axis is tokens (N), atoms (N_atoms), MSA depth (S),
ensemble (E), or a pair axis [N, N, …]. Axis semantics drive every sharding
decision and padding rule downstream, so resolve N_tokens == N_atoms
ambiguities explicitly (ask if the code is silent).
Note local-vs-global index features and mask/padding conventions — these must stay consistent between data and model (Rule on index/mask consistency).
Identify the model's major blocks and match each to a Boltz-CP component using the tech guide. Typical correspondences (confirm against the actual code, names will differ):
Produce a mapping table: serial block → candidate CP file(s) (2D and 1D) → tech
guide § → "reuse as-is / adapt / new". Flag any block with no CP counterpart
as new work for dtensor_modules.
Then propagate the data-feature sharding requirements to consumers (the Rule-4 contract) — do not
leave §3 and §5 unlinked. §3 gives each feature its placement; §5 gives each module. Cross-link them:
for every module, list the §3 data features it consumes and the placement each must arrive
at; and annotate every §3 feature with the modules that consume it. This data-feature→consumer
placement contract is the single sharding requirement that all consuming CP modules and the
synthetic test data/featurizer must honor — deriving it once here prevents each module port from
re-reconciling the same seam later (a shared feature like MSA, consumed by OPM + PWA + the MSA module,
is the classic case: propagate (Shard(0)=depth, Shard(1)=tokens) once instead of three times). Record
it as §4.5 of the deliverable (the placement-contract table in template.md).
Use AskUserQuestion only for what tracing cannot settle. High-value questions:
cp>1; get a one-time at-own-risk confirmation (proceed-1D / switch-to-2D / abort); and
record the acknowledgement in §0 of the deliverable. Default to 2D.docs/current_code_structure.md from
template.md — fill every section; leave explicit
TODO(learn_context): <question> markers for unresolved gaps rather than
guessing..fold-cp/config.json to arm the PreToolUse guard (Rules 2 & 16):
{
"enforce_serial_protection": true,
"serial_paths": ["<glob>", "..."],
"enforce_test_timeout": true,
"distributed_test_markers": ["tests/distributed"]
}
docs/current_code_structure.md exists, every template section is filled or
TODO-marked, and it records: BOLTZ_CP_REPO path, inference + training
workflows, framework, the data-feature inventory table, the serial→CP module
map, designated serial paths, and target CP topology.build_infra if infra is unverified, else
shard_data_feats).What SKILL.md sets; muted values are Claude Code's defaults
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