Skip to content

Configuration reference

TimberConfig describes the architecture of a model. It is saved as config.json with the weights. Each sub-configuration is a dataclass, so unknown option names raise an error and every default is visible in the code.

timber.configuration_timber

Configuration of the TIMBER models (architecture only).

TimberConfig is a PretrainedConfig: it is what config.json stores and what from_pretrained rebuilds. It is made of nested dataclasses, one per module:

  • TokenizerConfig (patching, channel and time embeddings),
  • ContextualizerConfig (paper module C),
  • EncoderConfig (paper module E; None for the no-encoder ablation),
  • a list of DecoderConfig (pretraining objectives, paper module D),
  • HeadConfig (finetuning head, paper module H; None for pretraining).

The architecture defaults are those of the TIMBER paper (TACO pretraining, forecasting_1); the data-shaped defaults (num_channels, patch_length) are placeholders to set for your data. Optimisation settings (learning rates, epochs, ...) are not part of this configuration; they belong to the training code.

Every sub-configuration validates itself in __post_init__; cross-module rules are checked by TimberConfig.validate. Unknown keys raise an error.

TimberConfig

Bases: PretrainedConfig

Configuration of the TIMBER models.

Parameters:

Name Type Description Default
tokenizer TokenizerConfig | dict | None

TokenizerConfig (or dict).

None
contextualizer ContextualizerConfig | dict | None

ContextualizerConfig (or dict).

None
encoder EncoderConfig | dict | None | Literal[TOKEN]

EncoderConfig (or dict), or None for the no-encoder ablation.

_DEFAULT
decoders list[DecoderConfig | dict] | None

Pretraining objectives, a list of DecoderConfig (or dicts). Empty for a plain finetuning model.

None
head HeadConfig | dict | None

HeadConfig (or dict), or None for pretraining.

None
patch_mask_ratio float

Fraction of patches hidden from the encoder (0: no masking).

0.7
config_version int

Version of this configuration schema (for later migrations).

CONFIG_VERSION
**kwargs Any

Standard PretrainedConfig arguments.

{}

Example::

config = TimberConfig(tokenizer={"num_channels": 64, "patch_length": 16})  # TACO pretraining
finetuning = TimberConfig(decoders=[], head={"task": "regression", "num_outputs": 3}, patch_mask_ratio=0.0)
patch_dim property
patch_dim: int

Channels of the contextualised patches (input of the encoder).

forecast_offset property
forecast_offset: int

Sample offset of the forecasting targets (see forecast_offset).

objectives property
objectives: list[str]

The pretraining objectives built from decoders.

from_dict classmethod
from_dict(config_dict: dict[str, Any], **kwargs: Any)

Build from a dict (config.json) and apply overrides, then validate the result.

validate
validate() -> None

Check the rules that involve several modules.

to_dict
to_dict() -> dict[str, Any]

The configuration as a nested dictionary (the content of config.json).

architecture_dict
architecture_dict() -> dict[str, Any]

The model options only (nested dicts), without the transformers bookkeeping fields.

TimberConfig(**config.architecture_dict()) rebuilds an equivalent configuration.

to_diff_dict
to_diff_dict() -> dict[str, Any]

Like the base class, but always write the full model configuration (readable config.json).

TokenizerConfig dataclass

Patching and position embeddings.

Attributes:

Name Type Description
patch_length int

Samples per patch.

patch_stride int | None

Step between patch starts (None: patch_length, no overlap).

num_channels int

Number of channels with a channel embedding (channel indices are in [0, num_channels)).

channel_embedding_dim int

Channels of the channel embedding.

trainable_channel_embedding bool

Train the channel embedding.

time_embedding_type TimeEmbeddingType | None

None, "patch" (index of the patch in the window) or "timestep" (absolute timestep of the patch start).

num_time_frequencies int

Fourier bands of the time embedding (it has 2 * k + 1 channels).

time_resolution int

Fourier resolution; with "timestep" also the number of timesteps covered.

stride property
stride: int

Hop between patches: patch_stride, or patch_length when it is None.

time_embedding_dim property
time_embedding_dim: int

Width of the time embedding: 2 * num_time_frequencies + 1, or 0 without it.

position_dim property
position_dim: int

Channels of a patch position embedding (channel + time).

forecast_offset property
forecast_offset: int

Extra shift of forecasting targets for overlapping patches.

module_kwargs
module_kwargs() -> dict[str, Any]

Keyword arguments of PatchTokenizer.

ContextualizerConfig dataclass

Factorised spatial / temporal attention over patches (paper module C).

Attributes:

Name Type Description
hidden_dim int

Channels of the layers.

output_dim int | None

Channels of the output projection (None: no projection, hidden_dim channels).

num_layers int

Number of layers (0: patch embedding only, the "no contextualizer" ablation).

num_heads int

Attention heads.

ffn_ratio int

Feed-forward hidden size as a multiple of hidden_dim.

dropout float

Dropout on attention probabilities, feed-forward and residual branches.

attention_order AttentionOrder

"channel_time" (channels first) or "time_channel" (patches first).

is_causal bool

Causal attention over time (required by the forecasting objectives).

share_attention_weights bool

One attention module for both passes.

use_pre_norm bool

Pre-norm residual blocks (default: post-norm).

use_gradient_checkpointing bool

Recompute layers in the backward pass to save memory.

patch_dim property
patch_dim: int

Channels of the contextualised patches.

EncoderConfig dataclass

Perceiver IO encoder (paper module E).

Attributes:

Name Type Description
num_latents int

Latent tokens.

latent_dim int

Channels of the latents.

num_blocks int

Encoder blocks (each with its own cross-attention to the patches).

num_self_attention_layers int

Latent self-attention layers per block.

num_self_attention_heads, num_cross_attention_heads

Attention heads.

self_attention_widening_factor, cross_attention_widening_factor

MLP widening factors.

dropout float

Dropout on the attention probabilities.

use_cls_token bool

Append a trainable CLS token after the latents.

latent_dropout_ratio float

Probability to drop each latent token before every block (training only).

initializer_range float

Standard deviation of the CLS token initialisation.

use_gradient_checkpointing bool

Recompute blocks in the backward pass to save memory.

num_tokens property
num_tokens: int

Output tokens: latents plus the CLS token.

DecoderConfig dataclass

A pretraining objective and its cross-attention decoder (paper module D).

Attributes:

Name Type Description
objective str

"reconstruction" (masked patches from their positions) or "forecasting_<k>" (the patch k steps ahead from a contextualised patch; forecasting_1 is TACO).

loss_weight float

Weight of this objective in the total loss (0 skips it).

num_heads int

Cross-attention heads.

widening_factor int

MLP widening of the cross-attention layer.

dropout float

Dropout on the attention probabilities (for the no-encoder ablation: dropout before its linear projection).

is_forecasting property
is_forecasting: bool

Whether the objective is a forecasting objective (forecasting_<k>).

forecast_horizon property
forecast_horizon: int

The horizon k of a forecasting objective, or None for reconstruction.

HeadConfig dataclass

Finetuning head (paper module H).

Attributes:

Name Type Description
task Task

"regression" (Huber loss) or "classification" (cross-entropy).

num_outputs int

Regression targets, or number of classes.

pooling Pooling

"mean", "weighted_mean", "cls_token" or "attention" pooling of the latents.

fusion_stage FusionStage

Where the views of an entity are combined: "early" (pooled latents), "late" (predictions) or "loss" (one loss term per view).

projection_dim int | None

Optional Linear + GELU projection of the latents before pooling.

pooling_input_dropout float

Dropout on the latents before pooling.

num_hidden_layers, (widening_factor, dropout, use_input_norm)

MLP layout.

label_smoothing float

Label smoothing of the classification loss.

loss_weight float

Weight of the head loss (relevant when decoders are also trained).

latent_block int | None

Read the latents of this encoder block (1-based; None: last block).