patch-workflows
Design TorchIO patch-based training queues and dense patch inference loops with samplers, SubjectsLoader batches, PatchLocation metadata, and PatchAggregator.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- patch-workflows
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Design TorchIO patch-based training queues and dense patch inference loops with samplers, SubjectsLoader batches, PatchLocation metadata, and PatchAggregator.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md5.9 KB
- 参考文档references/troubleshooting.md5.7 KB
- 参考文档references/workflows.md5.6 KB
- 脚本scripts/patch_workflow_smoke.py8.5 KB
03 SKILL.md 正文
Patch Workflows
Use this sub-skill when an agent needs to train or infer on large 3D images by sampling patches instead of processing whole volumes. It covers GridSampler, UniformSampler, WeightedSampler, LabelSampler, Queue, SubjectsLoader, ImagesLoader, PatchLocation, and PatchAggregator.
Route by Goal
- Need dense whole-volume inference: use
GridSamplerplusPatchAggregator; see dense inference. - Need stochastic training patches: use
UniformSampler,WeightedSampler, orLabelSampler, optionally buffered byQueue; see training queues. - Need to choose sampler or batch access patterns: see API reference.
- Hit shape, overlap, probability map, or metadata errors: see troubleshooting.
- Want a runnable synthetic sanity check: run
python scripts/patch_workflow_smoke.py --help, thenpython scripts/patch_workflow_smoke.pyfrom this sub-skill directory.
Current API Reminders
- Construct in-memory images as
tio.ScalarImage(tensor)and labels astio.LabelMap(tensor); do not usesource=tensor. - Image tensors are 4D
(C, I, J, K)and loader batches are 5D(B, C, I, J, K). SubjectsLoaderreturns aSubjectsBatch: named images are accessed asbatch.t1.dataorbatch["t1"].data.- Patch locations are stored on individual patch subjects as
patch.patch_location; after batching, usebatch.metadata["patch_location"]. PatchAggregator.add_batch()expects model outputs shaped(B, C, I, J, K)and a list of onePatchLocationper batch item.
Minimal Dense Inference Pattern
sampler = tio.GridSampler(subject, patch_size=(64, 64, 64), patch_overlap=16)
loader = tio.SubjectsLoader(sampler, batch_size=4)
aggregator = tio.PatchAggregator(
spatial_shape=subject.spatial_shape,
overlap_mode="hann",
patch_overlap=16,
)
for batch in loader:
logits = model(batch.t1.data)
locations = batch.metadata["patch_location"]
aggregator.add_batch(logits, locations)
volume_logits = aggregator.get_output()
Minimal Training Queue Pattern
sampler = tio.UniformSampler(subjects[0], patch_size=(64, 64, 64))
queue = tio.Queue(
subjects,
patch_sampler=sampler,
max_length=300,
patches_per_volume=10,
num_workers=4,
transform=train_transform,
)
loader = tio.SubjectsLoader(queue, batch_size=16)
for batch in loader:
inputs = batch.t1.data
targets = batch.seg.data
loss = criterion(model(inputs), targets)
loss.backward()
Boundaries
- For creating
Subject,ScalarImage, andLabelMapobjects, use the parent data-model guidance. - For choosing augmentations or preprocessing transforms, use the transforms sub-skill.
- For command-line operations, use the CLI and I/O sub-skill.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).