configuration_lfm2.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright 2025 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from huggingface_hub.dataclasses import strict
  15. from ...configuration_utils import PreTrainedConfig
  16. from ...modeling_rope_utils import RopeParameters
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="LiquidAI/LFM2-1.2B")
  19. @strict
  20. class Lfm2Config(PreTrainedConfig):
  21. r"""
  22. conv_bias (`bool`, *optional*, defaults to `False`):
  23. Whether to use bias in the conv layers.
  24. conv_L_cache (`int`, *optional*, defaults to 3):
  25. L_cache dim in the conv layers.
  26. block_multiple_of (`int`, *optional*, defaults to 256):
  27. Multiple for the `intermediate_size`.
  28. block_ffn_dim_multiplier (`float`, *optional*, defaults to 1.0):
  29. Multiplier for the `intermediate_size`.
  30. block_auto_adjust_ff_dim (`bool`, *optional*, defaults to `True`):
  31. Whether to adjust the dim of the `intermediate_size`.
  32. full_attn_idxs (`Optional`, *optional*):
  33. Index of the layers which use attention.
  34. ```python
  35. >>> from transformers import Lfm2Model, Lfm2Config
  36. >>> # Initializing a LFM2 model
  37. >>> configuration = Lfm2Config()
  38. >>> # Initializing a model from the LFM2-1.2B style configuration
  39. >>> model = Lfm2Model(configuration)
  40. >>> # Accessing the model configuration
  41. >>> configuration = model.config
  42. ```
  43. """
  44. model_type = "lfm2"
  45. keys_to_ignore_at_inference = ["past_key_values"]
  46. default_theta = 1000000.0
  47. vocab_size: int = 65536
  48. hidden_size: int = 2560
  49. intermediate_size: int = 12288
  50. num_hidden_layers: int = 32
  51. num_attention_heads: int = 32
  52. num_key_value_heads: int = 8
  53. max_position_embeddings: int = 128_000
  54. initializer_range: float = 0.02
  55. norm_eps: float = 0.00001
  56. use_cache: bool = True
  57. pad_token_id: int | None = 0
  58. bos_token_id: int | None = 1
  59. eos_token_id: int | list[int] | None = 2
  60. tie_word_embeddings: bool = True
  61. rope_parameters: RopeParameters | dict | None = None
  62. conv_bias: bool = False
  63. conv_L_cache: int = 3
  64. block_multiple_of: int = 256
  65. block_ffn_dim_multiplier: float | int = 1.0
  66. block_auto_adjust_ff_dim: bool = True
  67. full_attn_idxs: list[int] | None = None
  68. layer_types: list[str] | None = None
  69. def __post_init__(self, **kwargs):
  70. if self.layer_types is None:
  71. self.full_attn_idxs = (
  72. self.full_attn_idxs if self.full_attn_idxs is not None else list(range(self.num_hidden_layers))
  73. )
  74. self.layer_types = [
  75. "full_attention" if i in self.full_attn_idxs else "conv" for i in range(self.num_hidden_layers)
  76. ]
  77. self.tie_word_embeddings = kwargs.pop("tie_embedding", self.tie_word_embeddings)
  78. self.intermediate_size = kwargs.pop("block_ff_dim", self.intermediate_size)
  79. super().__post_init__(**kwargs)
  80. __all__ = ["Lfm2Config"]