Pipelines

Pipelines

Both training pipelines end to end: experiment launch, the curriculum-driven custom training loop with distributed execution and sliding-window validation, and the complete nnU-Net v2 lifecycle.

Custom Training Run: One Epoch A sequence diagram generated by Archify. resolve run config merged config init tracking run start training build datasets wrap with collator read .npy patch 7-key sample collated batch apply epoch weights updated weights forward pass logits + SDF + targets composite loss loss + logits backward + step step metrics next batch sliding-window eval eval dice save checkpoints run summary Setup Per-epoch training Validation Artefacts Run Script · run_experiment.py · Sequence participant Run Script run_experiment.py Hydra Config · configs/*.yaml · Sequence participant Hydra Config configs/*.yaml HF Trainer · train.py · Sequence participant HF Trainer train.py Dataset · PapyrusDataset · Sequence participant Dataset PapyrusDataset DataLoader · collate + pin · Sequence participant DataLoader collate + pin Dual-Head Net · binary + SDF · Sequence participant Dual-Head Net binary + SDF Loss Suite · losses + schedule · Sequence participant Loss Suite losses + schedule W&B Tracking · runs + metrics · Sequence participant W&B Tracking runs + metrics Run Outputs · checkpoints + logs · Sequence participant Run Outputs checkpoints + logs Legend request return async trace default message
The custom training loop for one epoch, from Hydra configuration resolution and experiment launch, through dataset and batch construction, the dual-head forward pass, the scheduled loss-weight curriculum, and sliding-window validation, to checkpoints and tracking.

1. The custom MONAI pipeline

X-ray CT scan of a sealed, carbonised Herculaneum scroll, its tightly wrapped papyrus sheet still rolled shut
The sealed, carbonised scroll as scanned — the raw object this pipeline consumes. Source: scrollprize.org/firstscroll.

This is the repository’s primary pipeline: a dual-head 3D network trained through a Hugging Face Trainer, driven by layered configuration, with a loss-weight curriculum applied every epoch. It is the pipeline to read first if you intend to change how the model learns.

1.1 Experiment launch and startup sequence

A run is identified by a pair: an approach (the subpackage under src/approach/) and an experiment (an YAML file under that approach’s configs/experiments/). Startup resolves those into one concrete configuration and then performs an ordered sequence of side effects before training begins:

StepWhat happens
1Parse the approach / experiment arguments and the distributed-launch environment.
2Load and compose the layered configuration into a single resolved object.
3Derive the output directory for this experiment and create it.
4Write the resolved configuration into the output tree so the run is reproducible.
5Configure the tracker (project, run name, offline or online mode).
6Build the training and held-out datasets, plus collation and augmentation.
7Instantiate the model architecture and the composed loss.
8Hand control to the Trainer, which runs the loop and the callbacks.

Because step 4 persists the resolved configuration next to the outputs, two experiments can be diffed from their output directories alone — no need to reconstruct which YAML overrides were in play. The output layout is described in Deployment.

1.2 Distributed training

Multi-GPU training is the default path rather than an advanced option. The entry point is expected to be launched under a distributed launcher, which supplies the rank and world size through the standard environment; the code reads those to decide sharding and to make logging and checkpointing rank-aware so only one process writes to disk or reports metrics. A single-device run is the degenerate case of the same code path.

1.3 The training loop

The loop itself is deliberately conventional — the design effort went into the data contract and the objective, not into reimplementing an optimiser. What is worth noting is the set of behaviours layered onto it:

BehaviourDetail
Batch collation A custom collator stacks the per-sample tensors into batches, preserving the auxiliary targets (label_fg, label_valid, distance_unsigned) that a generic collator would drop.
Loss-weight curriculum A callback recomputes the loss-component weights at the start of every epoch by interpolating each component between a start and end weight over a configured epoch range, then pushes the result into the loss object. This is how a loss term can be phased in after the model has learned something coarse.
Optimiser schedule A cosine schedule with warm-up and weight decay, over a fixed epoch budget.
Logging cadence Step-level logs condensed to periodic reports, with the tracking integration receiving richer per-epoch state including samples.
Checkpoint cadence Checkpoints are written at a configurable fraction of the run, so intermediate epochs are recoverable without waiting for the final model.
Mixed precision and gradient checkpointing Both are configurable rather than hardcoded, since the right trade-off depends on the GPU.

1.4 Why a loss-weight curriculum

The loss suite can contain terms that are only meaningful once the model produces a recognisable surface. A topological term evaluated on garbage output gives a gradient that points in an unhelpful direction, so the curriculum starts the objective simple and ramps complexity in. The schedule is a tool, not an opinion: a component with the same start and end weight is simply constant, and a component that starts at zero is introduced gradually.

1.5 Validation and progress metrics

Validation is a sliding-window pass over the held-out cases, using a region of interest matching the training patch size and a configured window overlap, with overlapping window predictions averaged to suppress seams. This is the same inference machinery used for standalone prediction, which means the number reported during training is the number the next stage will see.

Alongside the loss, the trainer computes per-sample statistics from the logits at each validation round and derives a small set of aggregate metrics. These are progress indicators computed from the validation tensors — they track the shape of the learning curve during a run. The authoritative competition score is computed separately from written prediction volumes, as described in Evaluation & Metrics.

2. The nnU-Net v2 pipeline

The second pipeline applies nnU-Net v2 to the same dataset. It is a first-class path, not a fallback: it provides a strong reference point and an independent implementation of the same task, which makes custom-pipeline gains interpretable.

nnU-Net v2 Lifecycle A lifecycle diagram generated by Archify. 01 / Pipeline 02 / Preparation + Quality gate 03 / Delivery Raw volumes · CT + labels · Pipeline Raw volumes CT + labels Convert dataset · nnU-Net layout · Pipeline Convert dataset nnU-Net layout Plan + preprocess · fingerprint · Pipeline Plan + preprocess fingerprint Train · ResEncUNet M · Pipeline Train ResEncUNet M Predict · multi-GPU · Pipeline Predict multi-GPU Preprocessing · cached once · Preparation Preprocessing cached once Converged? · checkpoint quality · Quality gate Converged? checkpoint quality Export + package · TIFF masks · Delivery Export + package TIFF masks stage 1 stage 2 launch cached epochs done yes assemble Legend start active state waiting decision terminal success
The nnU-Net v2 lifecycle as driven by this repository: dataset preparation, fingerprint-driven preprocessing, training, partitioned multi-GPU prediction, TIFF export and submission packaging.

2.1 Dataset preparation

nnU-Net expects a specific on-disk dataset layout with a JSON descriptor declaring modalities, labels and file endings. The repository’s driver translates its own data layout into that structure, generating the descriptor programmatically so label semantics stay in one place rather than being duplicated in a hand-written JSON file. A separate spacing sidecar carries voxel-size information, because the physical resolution is not encoded in the TIFF files themselves.

2.2 Fingerprint-driven preprocessing

Preprocessing is planned automatically. nnU-Net analyses the dataset to compute an intensity and geometry fingerprint, then derives the preprocessing pipeline and the network configuration from it. In this project that yields isotropic spacing, a median input volume close to 320 × 314 × 314 with 128 × 128 × 128 training patches, and a residual-encoder 3D U-Net plan — the plan used in practice is checked in as a reference under docs/.

The checked-in plans file docs/plans.json is an nnU-Net plans file rather than documentation. It is kept in the repository so the exact plan a reported result was produced with can be inspected without re-running fingerprinting, and it is referenced from Models & Losses and Deployment.

2.3 Training

Training runs through nnU-Net’s own trainer rather than the Hugging Face Trainer used by the custom pipeline. The driver wraps the framework’s commands, exposing dataset preparation, preprocessing, training, prediction and export as callable steps, and composes them into a full end-to-end pipeline that can also be run one stage at a time. Stage-at-a-time execution is what makes the pipeline practical to debug: preprocessing is a long-running step that should not be repeated because a training hyperparameter changed.

2.4 Partitioned multi-GPU inference

Inference over the whole test set is spread across devices rather than run on one. The inference driver launches one predictor subprocess per GPU, each restricted to a single visible device and given its own partition index and partition count. The split is over the case list rather than over space: every subprocess writes into the same predictions directory, and once they have all finished the driver converts the combined output.

inference driver
 ├─ GPU 0  nnUNetv2_predict  -part_id 0 -num_parts N   → case subset 0
 ├─ GPU 1  nnUNetv2_predict  -part_id 1 -num_parts N   → case subset 1
 └─ ...
 shared predictions directory  →  per-case label volumes  →  TIFF export

Because the framework expects a specific results-directory layout, the driver builds a symlinked structure pointing at the trained folds, so existing checkpoints can be used without moving or copying them. The wrapper also forces the channels-last-3D memory format, which is a meaningful throughput win for 3D convolutions on the target hardware.

2.5 Export and submission generation

Predicted volumes are converted back to TIFF for submission. The driver separates the conversion step from the generation step so a failed export can be retried without re-running inference. The inference code itself is also packaged and published as a Kaggle dataset, so the same prediction logic runs in the competition notebook environment; that packaging flow is covered in Deployment.

3. Choosing between the pipelines

If you want to…UseBecause
Test a new architecture or loss idea Custom pipeline Every component is a local, editable class with an explicit weight in configuration.
Get a strong result quickly nnU-Net pipeline Configuration is derived automatically from the dataset; little tuning is required.
Diagnose whether a gain is real Both A change that beats nnU-Net is attributable to modelling rather than training details.
Understand the topology failure mode Custom pipeline Distance supervision and topological loss terms give direct control over the trade-off.
Produce a submission under notebook constraints nnU-Net pipeline The inference code is already packaged and published for that environment.