Getting Started¶
This guide gives you the shortest reliable path to a working foreblocks training loop, then points you to the right extras and guides when you want preprocessing, search, or richer tooling.
If you want the broader map first, start from Overview.
Install¶
| Workflow | Extra |
|---|---|
| Plotting helpers | pip install "foreblocks[plotting]" |
| Preprocessing / scientific | pip install "foreblocks[preprocessing]" |
| DARTS training + search | pip install "foreblocks[darts]" |
| DARTS analyzer (pandas/seaborn) | pip install "foreblocks[darts-analysis]" |
| MLTracker API + TUI | pip install "foreblocks[mltracker]" |
| Everything | pip install "foreblocks[all]" |
Training pipeline at a glance¶
flowchart LR
A[Raw data\narray] --> B[create_dataloaders]
B --> C[ForecastingModel]
C --> D[Trainer.train]
D --> E[ModelEvaluator]
E --> F[metrics / plots]
Minimal training example¶
import numpy as np
import torch
import torch.nn as nn
from foreblocks import (
ForecastingModel,
ModelEvaluator,
Trainer,
TrainingConfig,
create_dataloaders,
)
seq_len = 24
horizon = 6
n_features = 4
rng = np.random.default_rng(0)
X_train = rng.normal(size=(64, seq_len, n_features)).astype("float32")
y_train = rng.normal(size=(64, horizon)).astype("float32")
X_val = rng.normal(size=(16, seq_len, n_features)).astype("float32")
y_val = rng.normal(size=(16, horizon)).astype("float32")
train_loader, val_loader = create_dataloaders(
X_train, y_train, X_val, y_val, batch_size=16
)
head = nn.Sequential(
nn.Flatten(),
nn.Linear(seq_len * n_features, 64),
nn.GELU(),
nn.Linear(64, horizon),
)
model = ForecastingModel(
head=head,
forecasting_strategy="direct",
model_type="head_only",
target_len=horizon,
)
trainer = Trainer(
model,
config=TrainingConfig(num_epochs=5, batch_size=16, patience=3, use_amp=False),
auto_track=False, # (1)
)
history = trainer.train(train_loader, val_loader)
evaluator = ModelEvaluator(trainer)
metrics = evaluator.compute_metrics(torch.tensor(X_val), torch.tensor(y_val))
print("final_train_loss:", history.train_losses[-1])
print("metrics:", metrics)
- Disable MLTracker during smoke tests. Remove this line to enable experiment tracking.
What this validates
- Your
foreblocksimport path is correct - Dataloaders are shaped correctly
- The trainer loop runs without error
- Evaluation works on held-out data
Shape expectations¶
| Tensor | Shape |
|---|---|
X |
[N, T, F] — samples × input timesteps × features |
y |
any shape matching your head's output |
| Tensor | Shape |
|---|---|
X |
[N, T, F] |
y |
[N, H, D] — samples × horizon × output channels |
Decoder-based models have stricter dimension contracts — read the Custom Blocks guide before customising.
Starting from raw series¶
When your starting point is a [T, D] array, use TimeSeriesHandler instead of building windows manually:
import numpy as np
from foreblocks import TimeSeriesHandler
raw = np.random.randn(240, 3) # 240 timesteps, 3 channels
pre = TimeSeriesHandler(
window_size=24,
horizon=6,
normalize=True,
generate_time_features=False,
verbose=False,
)
X, y, processed, time_feat = pre.fit_transform(raw)
DARTS architecture search¶
If the baseline path works and you want to search architectures instead of hand-picking them:
Then continue with:
Where to go next¶
- Raw series preprocessing → Preprocessor Guide
- Model composition and injection points → Custom Blocks Guide
- Transformer backbones → Transformer Guide
- Expert routing → MoE Guide
- SSM / Mamba-style blocks → Hybrid Mamba Guide
- Post-hoc prediction intervals → Uncertainty Quantification
- Evaluation and cross-validation → Evaluation & Metrics
- Import errors or shape mismatches → Troubleshooting
Notes¶
Trainerinitialises MLTracker automatically. Passauto_track=Falseduring local smoke tests.TrainingConfigincludes conformal options, but you do not need them for the basic path above.TimeSeriesDatasetis also available if you want to build PyTorch dataloaders manually.- The direct strategy is the best first step. Move to seq2seq, transformer, or DARTS workflows once the baseline loop is already running.