Torch¶
torch ¶
Collection-backed PyTorch adapters (presigned item cursor).
CatalogBatchStreamParams
dataclass
¶
Replayable definition of one catalog.iter_batches stream (adapter bridge).
Source code in src/miura/adapters/catalog/batch_stream.py
with_epoch_shuffle ¶
New stream spec for one training epoch (new iter_batches session).
Source code in src/miura/adapters/catalog/batch_stream.py
BatchStreamStats
dataclass
¶
Observability for one or more catalog batch stream consumptions.
Source code in src/miura/adapters/catalog/torch.py
DatasetSource
dataclass
¶
Adapter-plane union: collection-backed or catalog-backed dataset reads.
Factories (normative — two only):
- :meth:
from_collection - :meth:
from_catalog_asset
Does not replace AsyncCollection, CatalogAssetRef, or recipe results.
Source code in src/miura/adapters/dataset_source.py
from_collection
classmethod
¶
from_collection(collection: Any, *, select: 'ItemSelect | Mapping[str, Any] | None' = None, path: str | None = '/') -> 'DatasetSource'
Build a collection-backed source (Parquet items via ItemSource).
Source code in src/miura/adapters/dataset_source.py
from_catalog_asset
classmethod
¶
from_catalog_asset(asset_ref: 'CatalogAssetRef | CatalogAssetSnapshotRef | CatalogAsset', *, columns: Sequence[str] | None = None, catalog_batch_size: int = 4096, shard_world_size: int = 1) -> 'DatasetSource'
Build a catalog-backed source (catalog.iter_batches stream).
Source code in src/miura/adapters/dataset_source.py
catalog_stream_params ¶
Build :class:CatalogBatchStreamParams for torch/pandas/dask catalog backends.
Source code in src/miura/adapters/dataset_source.py
TorchExecutionOptions
dataclass
¶
Additive extension seam for execution backends.
decode controls Parquet→tensor materialization for :func:to_torch_dataloader
when no per-sample transform is set: vectorized builds batches from Arrow
columns; row keeps the row-wise to_pylist path.
:func:to_torch_iterable_dataset always uses row-wise samples regardless of decode.
Source code in src/miura/adapters/torch/_options.py
catalog_batch_stream_for_epoch ¶
catalog_batch_stream_for_epoch(asset_ref: 'CatalogAssetRef | CatalogAssetSnapshotRef | CatalogAsset', epoch: int, *, columns: Sequence[str] | None = None, catalog_batch_size: int = 4096, shuffle_enabled: bool = True, shard: CatalogReadShard | None = None) -> CatalogBatchStreamParams
Build a per-epoch catalog batch stream spec (explicit epoch → new stream).
Source code in src/miura/adapters/catalog/batch_stream.py
async_iter_catalog_torch_samples
async
¶
async_iter_catalog_torch_samples(catalog: 'CatalogAPI', stream: CatalogBatchStreamParams, *, sample_format: SampleFormat = 'dict', feature_columns: list[str] | None = None, target_column: str | None = None, transform: Callable | None = None, row_preprocess: Callable[[dict[str, Any]], dict[str, Any]] | None = None, limit: int | None = None, batch_size: int = 32, execution_options: TorchExecutionOptions | None = None, stats: BatchStreamStats | None = None) -> AsyncIterator[Any]
Async iterator over torch samples from a catalog batch stream.
Caller-owned CatalogAPI — no background thread and no adapter-spawned
AsyncNexus. Demonstrated in archive/examples/nexus/catalog_torch_train.py
(Layer 2 / power-user); prefer to_torch_dataloader (example 07) for training UX.
Each full pass opens a new catalog.iter_batches stream (same per-epoch
contract as the sync DataLoader bridge).
With decode='vectorized', each yielded value is one micro-batch (same as
to_torch_dataloader(..., batch_size=N)).
Source code in src/miura/adapters/catalog/torch.py
load_catalog_record_batches
async
¶
load_catalog_record_batches(catalog: 'CatalogAPI', *, asset_ref: Any = None, columns: list[str] | None = None, batch_size: int = 4096, **kwargs: Any) -> list[pa.RecordBatch]
Prefetch an entire catalog batch stream (tests / smoke / debug only).
Source code in src/miura/adapters/catalog/torch.py
to_torch_dataloader_from_catalog_batch_stream ¶
to_torch_dataloader_from_catalog_batch_stream(stream: CatalogBatchStreamParams, *, sample_format: SampleFormat = 'dict', feature_columns: list[str] | None = None, target_column: str | None = None, transform: Callable | None = None, row_preprocess: Callable[[dict[str, Any]], dict[str, Any]] | None = None, limit: int | None = None, batch_size: int = 32, num_workers: int = 0, execution_options: TorchExecutionOptions | None = None, queue_size: int = 4, stats: BatchStreamStats | None = None, **dataloader_kwargs: Any) -> Any
Build a streaming DataLoader over a catalog batch stream (sync interop).
Each full pass over the loader starts a new catalog.iter_batches stream
via a background thread that spawns its own AsyncNexus. Use
:func:catalog_batch_stream_for_epoch or
:meth:CatalogBatchStreamParams.with_epoch_shuffle for per-epoch streams.
For async training with a caller-owned client, see
:func:async_iter_catalog_torch_samples in
archive/examples/nexus/catalog_torch_train.py (Layer 2 / power-user).
row_preprocess + decode='row' is for string fixtures / custom transforms;
numeric catalog columns should use TorchExecutionOptions(decode='vectorized').
Source code in src/miura/adapters/catalog/torch.py
to_torch_dataloader_from_prefetched_batches ¶
to_torch_dataloader_from_prefetched_batches(record_batches: Sequence[RecordBatch], *, sample_format: SampleFormat = 'dict', feature_columns: list[str] | None = None, target_column: str | None = None, transform: Callable | None = None, row_preprocess: Callable[[dict[str, Any]], dict[str, Any]] | None = None, limit: int | None = None, batch_size: int = 32, num_workers: int = 0, execution_options: TorchExecutionOptions | None = None, stats: BatchStreamStats | None = None, **dataloader_kwargs: Any) -> Any
Build a DataLoader from prefetched batches (tests / tiny fixtures only).
Source code in src/miura/adapters/catalog/torch.py
to_torch_iterable_dataset ¶
to_torch_iterable_dataset(collection: Any, *, sample_format: SampleFormat = 'dict', feature_columns: list[str] | None = None, target_column: str | None = None, transform: Callable | None = None, limit: int | None = None, execution_options: TorchExecutionOptions | None = None, select: 'ItemSelect | Mapping[str, Any] | None' = None, path: str | None = '/', shuffle: bool = False, client_shuffle_buffer: int | None = None, shuffle_seed: int | None = None) -> Any
Build a torch IterableDataset over Parquet items in a Nexus collection.
Server-side filtering: pass select and/or path to enumerate
only matching items via AsyncCollection.iter_items. Defaults preserve
whole-collection traversal.
When shuffle=True, applies a bounded client-side shuffle buffer
(default :data:DEFAULT_CLIENT_SHUFFLE_BUFFER). This is not catalog CRS
epoch shuffle.
Source code in src/miura/adapters/torch/adapter.py
to_torch_dataloader ¶
to_torch_dataloader(source: Any, *, sample_format='dict', feature_columns=None, target_column=None, transform=None, row_preprocess=None, limit=None, batch_size=32, shuffle=False, num_workers=0, execution_options=None, queue_size=4, stats=None, select=None, path='/', client_shuffle_buffer=None, shuffle_seed=None, **dataloader_kwargs)
Build a torch DataLoader from a Nexus collection of Parquet items.
Pass select=ItemSelect(split="train") for split-filtered training.
shuffle=True uses a client-side buffer on the collection path.
For catalog assets (Flight / CRS epoch shuffle), use
:func:miura.adapters.catalog.torch.to_torch_dataloader.