Concepts
In PyTorchLabFlow, everything is a Component — from models and datasets to losses, optimizers, and custom blocks. This modular design enables users to configure, nest, and reuse components dynamically, simplifying the construction and maintenance of complex deep learning workflows.
Component
A Component is a reusable, self-contained code block that can represent any part of your ML workflow — a model, dataset, optimizer, loss function, metric, or even a custom processing step.
Each Component is defined by:
loc: A string specifying the Python import path of the component class.args: A dictionary of parameters to configure or initialize the component.
The key power of Components is infinite nesting: any component can accept other components inside its args. This enables deeply composable, declarative, and dynamically configurable systems.
Key Features
Dynamic Loading: Components are loaded at runtime using the
locpath.Flexible Composition: Nested components allow reusable and interchangeable blocks.
Argument Validation: Each component validates its required arguments before setup.
Single Interface: Everything behaves consistently through the same Component interface.
Core Behavior
All components inherit from the abstract base class Component, which provides core logic for:
check_args(args: dict): Validates required arguments.setup(args: dict): Triggers component initialization via the subclass’s_setup()method.
Specialized Component Types
Type |
Class |
Inherits From |
|---|---|---|
Model |
|
|
Dataset |
|
|
Loss |
|
|
Optimizer |
|
|
Metric |
|
|
Note
DataSet: Loads and optionally pre-processes data.Model: Wraps your PyTorch models with config-driven construction.Loss: Defines the loss function used for training.Optimizer: Standard PyTorch optimizers, wrapped for config-driven setup.Metric: Custom metrics for evaluation.
Example: Custom Model Component
class MyModel(Model):
def __init__(self):
super().__init__()
self.args = {"input_dim", "output_dim"}
def _setup(self, args):
self.linear = nn.Linear(args["input_dim"], args["output_dim"])
return self
Example: Nesting Components
{
"loc": "my_project.models.TransformerClassifier",
"args": {
"backbone": {
"loc": "my_project.models.TransformerEncoder",
"args": {
"dim": 256,
"depth": 6
}
},
"num_classes": 10
}
}
A deeper discussion on the flexibility, nesting power, and real-world use of Components is available in this Medium article: 👉 Introducing Component in PyTorchLabFlow
To explore all available methods and internals of the base class, visit the Component API
Pipeline
A Pipeline organizes an entire machine learning experiment as a composition of Components. It tracks and manages configuration, reproducibility, and structure.
Each pipeline is uniquely identified by an experiment ID (expid). It keeps all hyperparameters, model setup, data loading, and training behavior in a single, reusable definition.
Creating a New Experiment
# Create a new pipeline from scratch
P = PipeLine()
P.new(pplid='my_first_experiment', args=experiment_args)
You define your experiment structure by passing nested Components as the args.
To explore the full functionality of the PTLF.experiment.PipeLine, including experiment loading, checkpointing, and tracking, see the PipeLine API