configuration_diffllama.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright 2024 weak-kajuma and the HuggingFace Inc. team. All rights reserved.
  2. #
  3. # This code is based on Llama implementations in this library and Microsoft's
  4. # Differential Transformer implementations.
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """DiffLlama model configuration"""
  17. from huggingface_hub.dataclasses import strict
  18. from ...configuration_utils import PreTrainedConfig
  19. from ...modeling_rope_utils import RopeParameters
  20. from ...utils import auto_docstring
  21. @auto_docstring(checkpoint="kajuma/DiffLlama-0.3B-handcut")
  22. @strict
  23. class DiffLlamaConfig(PreTrainedConfig):
  24. r"""
  25. lambda_std_dev (`float`, *optional*, defaults to 0.1):
  26. The standard deviation for initialization of parameter lambda in attention layer.
  27. ```python
  28. >>> from transformers import DiffLlamaModel, DiffLlamaConfig
  29. >>> # Initializing a DiffLlama diffllama-7b style configuration
  30. >>> configuration = DiffLlamaConfig()
  31. >>> # Initializing a model from the diffllama-7b style configuration
  32. >>> model = DiffLlamaModel(configuration)
  33. >>> # Accessing the model configuration
  34. >>> configuration = model.config
  35. ```
  36. """
  37. model_type = "diffllama"
  38. keys_to_ignore_at_inference = ["past_key_values"]
  39. vocab_size: int = 32000
  40. hidden_size: int = 2048
  41. intermediate_size: int = 8192
  42. num_hidden_layers: int = 16
  43. num_attention_heads: int = 32
  44. num_key_value_heads: int | None = None
  45. hidden_act: str = "silu"
  46. max_position_embeddings: int = 2048
  47. initializer_range: float = 0.02
  48. rms_norm_eps: float = 1e-5
  49. use_cache: bool = True
  50. pad_token_id: int | None = None
  51. bos_token_id: int | None = 1
  52. eos_token_id: int | list[int] | None = 2
  53. tie_word_embeddings: bool = False
  54. rope_parameters: RopeParameters | dict | None = None
  55. attention_bias: bool = False
  56. attention_dropout: float | int | None = 0.0
  57. lambda_std_dev: float | None = 0.1
  58. head_dim: int | None = None
  59. def __post_init__(self, **kwargs):
  60. # for backward compatibility
  61. if self.num_key_value_heads is None:
  62. self.num_key_value_heads = self.num_attention_heads
  63. self.head_dim = self.head_dim if self.head_dim is not None else self.hidden_size // self.num_attention_heads
  64. super().__post_init__(**kwargs)
  65. __all__ = ["DiffLlamaConfig"]