Document the simplified batching model - #1504
Conversation
📖 Docs PreviewPreview of the documentation for this PR: 🔗 https://smokeshow.helpmanual.io/05555t0d066w526l3a6c/ Built from aca0d66 |
There was a problem hiding this comment.
Pull request overview
This PR updates TorchIO’s documentation to describe the redesigned batching/transform execution model (factories, prototypes, exact per-element histories, replay/mapping), and adds a small benchmark script to measure core batching operations on CPU/CUDA.
Changes:
- Added a new “Write a custom transform” how-to with executable examples for batched tensors, metadata, subject-wise mapping, and exact replay.
- Updated core conceptual docs and migration guidance to reflect schema requirements, exact per-element histories, and annotation limitations in spatial transforms.
- Added an architecture overview (
batching-redesign.md) and a reproducible batching benchmark script (benchmarks/batching.py).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| zensical.toml | Adds the new custom-transform how-to page to the docs navigation. |
| docs/how-to/custom-transform.md | New how-to page with custom-transform patterns and replay/mapping examples. |
| docs/get-started/migration.md | Migration guidance updated for schemas, annotations, mapping, and exact replay. |
| docs/concepts/transforms.md | Documents exact replay via apply_with_params() and exact per-element batch histories. |
| docs/concepts/data-model.md | Documents prototypes/factories and per-element histories in the data model. |
| benchmarks/batching.py | Adds a CPU/CUDA batching benchmark script. |
| batching-redesign.md | Adds an architecture/decision overview for the batching redesign. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bde5bcd to
dc67be7
Compare
79d9233 to
54357dd
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
benchmarks/batching.py:67
- The benchmark wraps the transform call in an extra
copy.deepcopy(batch), butTransformalready deep-copies the input whencopy=True(the default). This double-copy can dominate the measured time and make the results less representative.
"vectorized transform": _measure(
lambda: transform(copy.deepcopy(batch)),
_ITERATIONS,
),
benchmarks/batching.py:41
- Calling
torch.cuda.synchronize()whenever CUDA is available can initialize CUDA during the CPU benchmark and skew timings. Consider synchronizing only if CUDA has already been initialized (i.e., you're actually benchmarking CUDA work).
if torch.cuda.is_available():
torch.cuda.synchronize()
benchmarks/batching.py:46
- Same as above: synchronizing whenever CUDA is available can introduce overhead into CPU benchmarks. Guarding on
torch.cuda.is_initialized()avoids triggering CUDA initialization on CPU-only runs.
if torch.cuda.is_available():
torch.cuda.synchronize()
dc67be7 to
4ff3671
Compare
54357dd to
23062a1
Compare
23062a1 to
1efca63
Compare
4ff3671 to
1936a5a
Compare
1efca63 to
cdf6953
Compare
1936a5a to
813693a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
benchmarks/batching.py:82
- In the CUDA run, the "metadata-only" operation doesn’t perform any CUDA work (it builds a batch of Python ints), but
_measure(..., device)will still calltorch.cuda.synchronize(). That adds unrelated sync overhead to the timing and can skew the reported CUDA numbers for this row.
Pass a CPU device here (since synchronization is the only device-dependent behavior) so the measurement reflects just the metadata-only batching cost.
"metadata-only": _measure(
lambda: tio.SubjectsBatch.from_subjects(metadata_subjects),
_ITERATIONS,
device,
),
c5f8d49 to
77a7350
Compare
ff302d9 to
abae6f0
Compare
abae6f0 to
25c51fb
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
99ae9a8 to
1c8b785
Compare
25c51fb to
edeb7a2
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
[Generated by a coding agent]
What
Document the simplified batching model and add a reproducible CPU/CUDA batching benchmark.
Why
The public model changes from optional templates and shared batch traces to factory construction, private prototypes, and exact per-element histories. Users and transform authors need executable guidance, and performance claims need a repeatable measurement tool.
How
batching-redesign.mdarchitecture overviewbenchmarks/batching.pyfor construction, unbatching, transforms, inversion, and metadata-only batchesValidation
Replacement stack