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;Nonefor the no-encoder ablation),- a list of
DecoderConfig(pretraining objectives, paper module D), HeadConfig(finetuning head, paper module H;Nonefor 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
|
|
None
|
contextualizer
|
ContextualizerConfig | dict | None
|
|
None
|
encoder
|
EncoderConfig | dict | None | Literal[TOKEN]
|
|
_DEFAULT
|
decoders
|
list[DecoderConfig | dict] | None
|
Pretraining objectives, a list of |
None
|
head
|
HeadConfig | dict | None
|
|
None
|
patch_mask_ratio
|
float
|
Fraction of patches hidden from the encoder ( |
0.7
|
config_version
|
int
|
Version of this configuration schema (for later migrations). |
CONFIG_VERSION
|
**kwargs
|
Any
|
Standard |
{}
|
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)
forecast_offset
property
¶
forecast_offset: int
Sample offset of the forecasting targets (see forecast_offset).
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.
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 ( |
num_channels |
int
|
Number of channels with a channel embedding (channel indices are in |
channel_embedding_dim |
int
|
Channels of the channel embedding. |
trainable_channel_embedding |
bool
|
Train the channel embedding. |
time_embedding_type |
TimeEmbeddingType | None
|
|
num_time_frequencies |
int
|
Fourier bands of the time embedding (it has |
time_resolution |
int
|
Fourier resolution; with |
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 ( |
num_layers |
int
|
Number of layers ( |
num_heads |
int
|
Attention heads. |
ffn_ratio |
int
|
Feed-forward hidden size as a multiple of |
dropout |
float
|
Dropout on attention probabilities, feed-forward and residual branches. |
attention_order |
AttentionOrder
|
|
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. |
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. |
DecoderConfig
dataclass
¶
A pretraining objective and its cross-attention decoder (paper module D).
Attributes:
| Name | Type | Description |
|---|---|---|
objective |
str
|
|
loss_weight |
float
|
Weight of this objective in the total loss ( |
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). |
HeadConfig
dataclass
¶
Finetuning head (paper module H).
Attributes:
| Name | Type | Description |
|---|---|---|
task |
Task
|
|
num_outputs |
int
|
Regression targets, or number of classes. |
pooling |
Pooling
|
|
fusion_stage |
FusionStage
|
Where the views of an entity are combined: |
projection_dim |
int | None
|
Optional |
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; |