Models

This page’s code cells are executed live by Quarto every time the docs are built. q.model collects ML model utilities in two kinds of submodules:

Submodule What it is
q.model.torch framework adapter: PyTorch helpers (model summaries via torchinfo today)
q.model.selection framework-agnostic, leakage-aware CV splitters for time series (planned)

Framework-specific adapters each get their own submodule (q.model.torch today; others only once actually needed), while framework-agnostic helpers sit as flat siblings.

PyTorch model summaries: q.model.torch.summary

A thin wrapper over torchinfo: a Keras-style layer-by-layer summary with output shapes, parameter counts, and estimated memory usage — handy for sanity-checking an architecture before training. Pass input_size=(batch, ...) or a real batch via input_data=:

import torch.nn as nn

import qrt as q

net = nn.Sequential(
    nn.Linear(10, 64),
    nn.ReLU(),
    nn.Linear(64, 32),
    nn.ReLU(),
    nn.Linear(32, 1),
)
q.model.torch.summary(net, input_size=(32, 10))
==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
Sequential                               [32, 1]                   --
├─Linear: 1-1                            [32, 64]                  704
├─ReLU: 1-2                              [32, 64]                  --
├─Linear: 1-3                            [32, 32]                  2,080
├─ReLU: 1-4                              [32, 32]                  --
├─Linear: 1-5                            [32, 1]                   33
==========================================================================================
Total params: 2,817
Trainable params: 2,817
Non-trainable params: 0
Total mult-adds (Units.MEGABYTES): 0.09
==========================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 0.02
Params size (MB): 0.01
Estimated Total Size (MB): 0.04
==========================================================================================

Model selection (planned): q.model.selection

Leakage-aware cross-validation splitters for time-series data — walk-forward (expanding-window) splits, purged K-fold, and embargo periods — named after scikit-learn’s model_selection:

for train_idx, test_idx in q.model.selection.timeseries_split(X, n_splits=5, embargo="5D"):
    ...

timeseries_split is a placeholder today; follow progress on the Roadmap.

Back to top