composer.core.types
This is our reference for common types used throughout our library.
Tensor Types
- class composer.core.types.Tensor
Alias for
torch.Tensor
- class composer.core.types.Tensors
Commonly used to represent e.g. a set of inputs, where it is unclear whether each input has its own tensor, or if all the inputs are concatenated in a single tensor.
Type:
torch.Tensor
, tuple oftorch.Tensor
s, or list oftorch.Tensor
s
Batch Types
A batch of data can be represented in several formats, depending on the application.
- class composer.core.types.Batch
Union type covering the most common representations of batches.
Type:
BatchPair
,BatchDict
, ortorch.Tensor
- class composer.core.types.BatchPair
Commonly used in computer vision tasks. The object is assumed to contain exactly two elements, where the first represents inputs and the second represents targets.
Type: List of
Tensors
- class composer.core.types.BatchDict
Commonly used in natural language processing tasks.
Type: str to
Tensor
dict
We provide helper functions to cast batches in situations where the batch type is known.
- composer.core.types.as_batch_dict(batch: composer.core.types.Batch) composer.core.types.BatchDict [source]
- composer.core.types.as_batch_pair(batch: composer.core.types.Batch) composer.core.types.BatchPair [source]
Dataset and Data Loader Types
- class composer.core.types.DataLoader(*args, **kwargs)[source]
Protocol for custom DataLoaders compatible with
torch.utils.data.DataLoader
.- num_workers
How many subprocesses to use for data loading.
0
means that the data will be loaded in the main process.- Type
- pin_memory
If
True
, the data loader will copy Tensors into CUDA pinned memory before returning them.- Type
- drop_last
If
len(dataset)
is not evenly divisible bybatch_size
, whether the last batch is dropped (if True) or truncated (if False).- Type
- sampler
The dataloader sampler.
- Type
- prefetch_factor
Number of samples loaded in advance by each worker.
2
means there will be a total of 2 *num_workers
samples prefetched across all workers.- Type
Trainer Types
- class composer.core.types.Metrics
Union type covering common formats for representing metrics.
Type:
Metric
orMetricCollection
- class composer.core.types.Optimizer[source]
Alias for
torch.optim.Optimizer
- class composer.core.types.Optimizers
Union type for indeterminate amounts of optimizers.
- class composer.core.types.Scheduler
Alias for
torch.optim.lr_scheduler._LRScheduler
- class composer.core.types.Schedulers
Union type for indeterminate amounts of schedulers.
- class composer.core.types.Scaler
Alias for
torch.cuda.amp.grad_scaler.GradScaler
- class composer.core.types.Model
Alias for
torch.nn.Module
Miscellaneous Types
- class composer.core.types.ModelParameters
Type alias for model parameters used to initialize optimizers.
Type: List of
torch.Tensor
or list of str totorch.Tensor
dicts
- class composer.core.types.JSON
JSON data.
- class composer.core.types.Precision(value)[source]
Enum class for the numerical precision to be used by the model.
- AMP
Use
torch.cuda.amp
. Only compatible with GPUs.
- FP32
Use 32-bit floating-point precision. Compatible with CPUs and GPUs.
- class composer.core.types.TPrefetchFn
Type alias for prefetch functions used for initializing dataloaders.
- class composer.core.types.Serializable(*args, **kwargs)[source]
Interface for serialization; used by checkpointing.
- load_state_dict(state: composer.core.types.StateDict) None [source]
Restores the state of the object.
- Parameters
state (StateDict) – The state of the object, as previously returned by
state_dict()
- state_dict() composer.core.types.StateDict [source]
Returns a dictionary representing the internal state.
The returned dictionary must be pickale-able via
torch.save()
.- Returns
StateDict – The state of the object
- class composer.core.types.StateDict
Class for representing serialized data.
Type: dict with str keys.