| """Per-method typed Pydantic configurations for the MacroLens unified API. |
| |
| Each method class declares its own ``MethodConfig`` subclass with typed, |
| validated, default-bearing hyperparameters. The runner records |
| ``config.model_dump()`` into ``RunRecord.hyperparams`` for every result. |
| """ |
|
|
| from __future__ import annotations |
|
|
| from typing import Literal |
|
|
| import pydantic |
|
|
|
|
| class MethodConfig(pydantic.BaseModel): |
| """Base for all method configs. |
| |
| ``model_config = ConfigDict(extra="forbid")`` so unknown kwargs raise at |
| construction; methods can override to allow ``extra="allow"`` if they |
| intentionally pass through to a wrapped library. |
| """ |
|
|
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) |
|
|
|
|
| |
|
|
|
|
| class PersistenceConfig(MethodConfig): |
| |
| |
| |
| |
| close_feature_idx: int = 0 |
| |
| |
| horizon: int | None = None |
|
|
|
|
| class SectorMedianConfig(MethodConfig): |
| fallback_to_global: bool = True |
|
|
|
|
| class MetroMedianConfig(MethodConfig): |
| fallback_to_global: bool = True |
| metro_key: Literal["city_state", "state", "state_property_type"] = ( |
| "state_property_type" |
| ) |
|
|
|
|
| class HistoricalAnalogueConfig(MethodConfig): |
| fallback_to_global: bool = True |
|
|
|
|
| class LogSizeOLSConfig(MethodConfig): |
| use_log_assets: bool = True |
| sector_dummies: bool = True |
|
|
|
|
| |
|
|
|
|
| class LightGBMConfig(MethodConfig): |
| """LightGBM library defaults; only ``n_jobs`` is a system-level flag.""" |
|
|
| n_estimators: int = 100 |
| max_depth: int = -1 |
| learning_rate: float = 0.1 |
| subsample: float = 1.0 |
| colsample_bytree: float = 1.0 |
| n_jobs: int = 8 |
| verbosity: int = -1 |
| t6_text_handling: Literal["sector_industry_only"] = "sector_industry_only" |
|
|
|
|
| class RandomForestConfig(MethodConfig): |
| """sklearn RandomForestRegressor library defaults; ``n_jobs`` is system-level.""" |
|
|
| n_estimators: int = 100 |
| max_depth: int | None = None |
| min_samples_leaf: int = 1 |
| n_jobs: int = 8 |
| t6_text_handling: Literal["sector_industry_only"] = "sector_industry_only" |
|
|
|
|
| |
|
|
|
|
| class SequenceConfig(MethodConfig): |
| """Shared training-loop defaults aligned with each upstream paper's |
| reference script (DLinear / iTransformer / ModernTCN — all 3 papers |
| use train_epochs=10, batch_size=32, patience=3, no weight_decay).""" |
|
|
| epochs: int = 10 |
| batch_size: int = 32 |
| learning_rate: float = 1e-4 |
| patience: int = 3 |
| weight_decay: float = 0.0 |
| grad_clip: float = 1.0 |
| target_idx: int = 0 |
|
|
|
|
| class DLinearConfig(SequenceConfig): |
| """DLinear (Zeng et al. AAAI 2023; cure-lab/LTSF-Linear, ETTh1 ref).""" |
|
|
| moving_avg: int = 25 |
| learning_rate: float = 5e-3 |
|
|
|
|
| class ITransformerConfig(SequenceConfig): |
| """iTransformer (Liu et al. ICLR 2024; thuml/iTransformer, ETTh1 ref).""" |
|
|
| d_model: int = 128 |
| n_heads: int = 8 |
| e_layers: int = 2 |
| d_ff: int = 128 |
| dropout: float = 0.1 |
| factor: int = 1 |
| activation: str = "gelu" |
| learning_rate: float = 1e-4 |
|
|
|
|
| class ModernTCNConfig(SequenceConfig): |
| """ModernTCN (Donghao & Xue ICLR 2024; luodhhh/ModernTCN, ETTh1 ref).""" |
|
|
| patch_size: int = 16 |
| patch_stride: int = 8 |
| d_model: int = 64 |
| kernel_size: int = 25 |
| stem_ratio: int = 1 |
| downsample_ratio: int = 2 |
| ffn_ratio: int = 2 |
| num_blocks: tuple[int, ...] = (1,) |
| large_size: tuple[int, ...] = (51,) |
| small_size: tuple[int, ...] = (5,) |
| dropout: float = 0.1 |
| head_dropout: float = 0.1 |
| revin: bool = True |
| affine: bool = True |
| learning_rate: float = 1e-3 |
|
|
|
|
| |
|
|
|
|
| class TSFMConfig(MethodConfig): |
| """Shared base for Chronos2 / Moirai2 / TimesFM.""" |
|
|
| model_id: str = "" |
| device: Literal["auto", "cpu", "cuda"] = "auto" |
| batch_size: int = 32 |
| target_idx: int = 0 |
|
|
|
|
| class Chronos2Config(TSFMConfig): |
| model_id: str = "amazon/chronos-2" |
| num_samples: int = 20 |
|
|
|
|
| class Moirai2Config(TSFMConfig): |
| model_id: str = "Salesforce/moirai-2.0-R-small" |
|
|
|
|
| class TimesFMConfig(TSFMConfig): |
| model_id: str = "google/timesfm-1.0-200m-pytorch" |
| per_core_batch_size: int = 32 |
| granularity: Literal["daily", "weekly", "monthly"] = "daily" |
|
|
|
|
| |
|
|
|
|
| class LLMConfig(MethodConfig): |
| model_id: str = "" |
| tensor_parallel_size: int = 1 |
| max_model_len: int = 8192 |
| temperature: float = 0.0 |
| max_tokens: int = 256 |
| enable_thinking: bool = False |
| |
| |
| in_context_k: int = 0 |
| |
| |
| dry_run: bool = False |
|
|
|
|
| class LlamaScoutConfig(LLMConfig): |
| model_id: str = "meta-llama/Llama-4-Scout-17B-16E-Instruct" |
| tensor_parallel_size: int = 4 |
|
|
|
|
| class Gemma4Config(LLMConfig): |
| model_id: str = "google/gemma-4-31B-it" |
| tensor_parallel_size: int = 2 |
|
|
|
|
| class Qwen35Config(LLMConfig): |
| model_id: str = "Qwen/Qwen3.5-27B-FP8" |
| tensor_parallel_size: int = 1 |
|
|
|
|
| |
|
|
|
|
| class LLMTSConfig(MethodConfig): |
| model_id: str = "" |
| device: Literal["auto", "cpu", "cuda"] = "auto" |
| |
| |
| dry_run: bool = False |
|
|
|
|
| class ChatTimeConfig(LLMTSConfig): |
| model_id: str = "ChengsenWang/ChatTime-1-7B-Chat" |
| hist_len: int = 63 |
| pred_len: int = 21 |
|
|
|
|
| class TimeMQAConfig(LLMTSConfig): |
| model_id: str = "Time-MQA/Qwen-2.5-7B" |
| base_model_id: str = "Qwen/Qwen2.5-7B-Instruct" |
|
|
|
|
| |
|
|
|
|
| class LLMFineTunedConfig(LLMConfig): |
| lora_r: int = 16 |
| lora_alpha: int = 32 |
| epochs: int = 3 |
| learning_rate: float = 2e-4 |
|
|