/itwinai:integrating-a-use-casefrom itwinai
Adapts existing scientific PyTorch training code into an itwinai plugin: scaffolding, porting training loops, distributed HPC training, MLflow logging, Ray hyperparameter tuning, profiling, and scalability reports.
Ships in itwinai. 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.
Turn existing scientific training code into an installable itwinai plugin that runs distributed on HPC, logs to MLflow, tunes hyperparameters with Ray, and produces a scalability report.
This skill targets itwinai 0.5.0. Phase 0 checks the installed version against it.
Do not restart from Phase 0. Jump straight to what you need.
| You want to | Go to |
|---|---|
| Start from a training script | Phase 0 |
| Add logging | Phase 4, step 1 |
| Add distributed training | Phase 4, step 2 |
| Add profiling / GPU monitoring | Phase 4, step 3 |
| Add hyperparameter optimization | Phase 4, step 4 |
| Produce a scalability report | Phase 5 |
| Publish the trained model to the Model Hub | references/model-hub.md |
| Port to another HPC system | references/slurm.md |
| Something failed | references/troubleshooting.md |
references/troubleshooting.md and fix it. Never advance past a failing gate, and never
report a phase complete without running its gate command and seeing it pass. A gate the
machine cannot run is not a failing gate: stop there and say so, see Rule 2.Check version skew.
itwinai --version
If it differs from the version stated above, say so plainly and recommend the user refresh this
plugin (/plugin menu) before continuing. Then continue anyway, obeying Rule 3 more strictly.
Inventory the source code. Read the training script and write a short table recording where each of these lives, or "none":
| Concern | Where it is now |
|---|---|
| Model construction | |
| Optimizer / LR scheduler | |
| Loss function | |
| Training loop | |
| Validation loop | |
| Dataset and DataLoader | |
| Metrics | |
| Checkpointing | |
| Hyperparameters (argparse, constants, YAML) | |
| Entry point |
Choose the fork. This decides Phase 2 and nothing else:
nn.Module, the loss is one of itwinai's built-ins,
and the loop is a conventional forward/backward/step. You write no trainer at all: a
DataGetter supplies the data and the stock itwinai.torch.trainer.TorchTrainer runs it.
This is the default. Choose it unless something below forces the other branch.TorchTrainer subclass. Required when the loss is not in
TrainingConfiguration's allowed set, the optimizer or scheduler is constructed in a non-standard
way, the training step is unusual (multiple optimizers, custom backward, physics residuals,
rollouts), or batches need per-batch transformation.Gate 0: the inventory table is filled in and the fork is chosen and justified in one sentence.
Read references/scaffolding.md.
Create the plugin repository from itwinai-plugin-template, choose the package name, and fix
pyproject.toml.
Gate 1:
uv pip install -e .
python -c "import itwinai.plugins.<name>; print('ok')"
Read references/porting-training-code.md, then the branch you chose in Phase 0.
Move the science under src/itwinai/plugins/<name>/. Keep the original script around until
Phase 3's gate passes, so you can diff behaviour against it.
Gate 2: the import above still succeeds, and no module defines a class whose name collides with an itwinai class it also imports. Check the second half, do not eyeball it:
python -c "import itwinai.plugins.<name>; print('ok')"
grep -rhoE "^class [A-Za-z_][A-Za-z_0-9]*" src/itwinai/plugins/<name>/ | sort -u
grep -rhoE "from itwinai[A-Za-z_.0-9]* import .*" src/itwinai/plugins/<name>/ | sort -u
No name from the first list may appear in the second. An overlap means your class shadows the
itwinai class of the same name in that module: rename yours after the science (FNOTrainer).
Read references/pipeline-config.md.
Write config.yaml: a Pipeline with steps, hyperparameters at the top, ${} interpolation to
avoid repeating them.
Gate 3 - the first rung that actually trains. Use a truncated dataset and one epoch:
itwinai exec-pipeline --config-name config +pipe_key=training_pipeline epochs=1
Run it with no launcher, so itwinai falls back to NonDistributedStrategy. The loss must move.
Compare it against a one-epoch run of the original script; they should be in the same range.
Do these in order. They form a dependency chain, not a menu. generate-scalability-report
reads its data out of MLflow, so profiling without logging, or a scaling test without either,
produces an empty report and no error message.
references/logging.md. Add LoggersCollection with ConsoleLogger and
MLFlowLogger. Re-run Gate 3 and confirm metrics appear under mllogs/mlflow.references/distributed.md, then references/slurm.md. Add the
slurm_config block to config.yaml and submit a single-node, multi-GPU job.references/profiling-and-scalability.md. Enable measure_epoch_time and
measure_gpu_data.references/hpo.md. Add the ray_* blocks and a search space. Leave strategy
alone; itwinai swaps in the Ray strategy by itself when it detects a Ray cluster.Gate 4: a single-node multi-GPU SLURM job completes, and MLflow contains a run with epoch times and GPU utilisation recorded.
No GPU node or no SLURM? sinfo or sbatch --version failing is the signal. Then Phase 3
is the end of the road here, by Rule 2: step 1 of this phase is still verifiable through Gate 3,
steps 2 to 4 are not. Report the plugin as working up to Gate 3, list Gate 4 as not run and
why, and offer to write the remaining config as unverified for someone with cluster access.
Publishing the model is not part of this chain and needs no cluster: it reads checkpoints,
not MLflow. Only when the user asks, read references/model-hub.md.
Only on explicit request. This consumes real allocation and may outlive the session.
Read references/profiling-and-scalability.md. Set mode: scaling-test and scalability_nodes,
submit, wait for every job, then:
itwinai generate-scalability-report
Gate 5: the plots exist and are non-empty. Empty plots mean the chain in Phase 4 was broken - go back to step 1, do not reinterpret the plots.
The gates above, as one list. Rungs 1-3 run anywhere. Rung 4 needs a GPU node and SLURM, rung 5 needs several nodes and is opt-in; where they cannot run, stop and say so (Rule 2).
itwinai sanity-check --torch passesTorchTrainer and override the narrowest method that covers the difference: the base class
is what keeps distributed training, logging and profiling working.references/distributed.md (opens in a new tab)references/hpo.md (opens in a new tab)references/logging.md (opens in a new tab)references/model-hub.md (opens in a new tab)references/pipeline-config.md (opens in a new tab)references/porting-training-code.md (opens in a new tab)references/profiling-and-scalability.md (opens in a new tab)references/scaffolding.md (opens in a new tab)references/slurm.md (opens in a new tab)references/troubleshooting.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub intertwin-eu/itwinai --plugin itwinaiOther plugins' skills for the same job