Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2025 Google LLC and HuggingFace Inc. team.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""TimesFM model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class TimesFmConfig(PretrainedConfig):25 r"""26 This is the configuration class to store the configuration of a [`TimesFmModelForPrediction`] or a [`TFTimesFmModel`]. It is used to27 instantiate a TimesFM model according to the specified arguments, defining the model architecture. Instantiating a28 configuration with the defaults will yield a similar configuration to that of the TimesFM29 [google/timesfm-2.0-500m-pytorch](https://huggingface.co/google/timesfm-2.0-500m-pytorch) architecture.30 31 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the32 documentation from [`PretrainedConfig`] for more information.33 34 Arguments:35 patch_length (`int`, *optional*, defaults to 32):36 The length of one patch in the input sequence.37 context_length (`int`, *optional*, defaults to 512):38 The length of the input context.39 horizon_length (`int`, *optional*, defaults to 128):40 The length of the prediction horizon.41 freq_size (`int`, *optional*, defaults to 3):42 The number of frequency embeddings.43 num_hidden_layers (`int`, *optional*, defaults to 50):44 Number of Transformer layers.45 hidden_size (`int`, *optional*, defaults to 1280):46 Size of the hidden layers in the feed-forward networks.47 intermediate_size (`int`, *optional*, defaults to 1280):48 Dimension of the MLP representations.49 head_dim (`int`, *optional*, defaults to 80):50 Size of the key, query, value projections per attention head. The `inner_dim` of the projection layer will51 be defined as `num_attention_heads * head_dim`.52 num_attention_heads (`int`, *optional*, defaults to 16):53 Number of attention heads for each attention layer in the Transformer encoder.54 tolerance (`float`, *optional*, defaults to 1e-06):55 The tolerance for the quantile loss.56 rms_norm_eps (`float`, *optional*, defaults to 1e-06):57 The epsilon used by the RMS normalization layers.58 quantiles (`list[float]`, *optional*, defaults to `[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]`):59 The quantiles to predict.60 pad_val (`float`, *optional*, defaults to 1123581321.0):61 The value used to pad the predictions.62 attention_dropout (`float`, *optional*, defaults to 0.0):63 The dropout probability for the attention scores.64 use_positional_embedding (`bool`, *optional*, defaults to `False`):65 Whether to add positional embeddings.66 initializer_range (`float`, *optional*, defaults to 0.02):67 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.68 min_timescale (`int`, *optional*, defaults to 1):69 The start of the geometric positional index. Determines the periodicity of70 the added signal.71 max_timescale (`int`, *optional*, defaults to 10000):72 The end of the geometric positional index. Determines the frequency of the73 added signal.74 """75 76 model_type = "timesfm"77 keys_to_ignore_at_inference = []78 is_encoder_decoder = False79 80 def __init__(81 self,82 patch_length: int = 32,83 context_length: int = 512,84 horizon_length: int = 128,85 freq_size: int = 3,86 num_hidden_layers: int = 50,87 hidden_size: int = 1280,88 intermediate_size: int = 1280,89 head_dim: int = 80,90 num_attention_heads: int = 16,91 tolerance: float = 1e-6,92 rms_norm_eps: float = 1e-6,93 quantiles: list[float] = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],94 pad_val: float = 1123581321.0,95 attention_dropout: float = 0.0,96 use_positional_embedding: bool = False,97 initializer_range: float = 0.02,98 min_timescale: int = 1,99 max_timescale: int = 10_000,100 **kwargs,101 ):102 self.patch_length = patch_length103 self.context_length = context_length104 self.horizon_length = horizon_length105 self.quantiles = quantiles106 self.pad_val = pad_val107 self.freq_size = freq_size108 self.hidden_size = hidden_size109 self.intermediate_size = intermediate_size110 self.head_dim = head_dim111 self.num_hidden_layers = num_hidden_layers112 self.num_attention_heads = num_attention_heads113 self.tolerance = tolerance114 self.rms_norm_eps = rms_norm_eps115 self.attention_dropout = attention_dropout116 self.use_positional_embedding = use_positional_embedding117 self.initializer_range = initializer_range118 self.min_timescale = min_timescale119 self.max_timescale = max_timescale120 121 super().__init__(122 is_encoder_decoder=self.is_encoder_decoder,123 **kwargs,124 )125 126 127__all__ = ["TimesFmConfig"]128 