configuration_cohere.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2024 Cohere team. All rights reserved.
  2. #
  3. # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
  4. # and OPT implementations in this library. It has been modified from its
  5. # original forms to accommodate minor architectural differences compared
  6. # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. """Cohere model configuration"""
  20. from huggingface_hub.dataclasses import strict
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...modeling_rope_utils import RopeParameters
  23. from ...utils import auto_docstring
  24. @auto_docstring(checkpoint="CohereForAI/c4ai-command-r-v01")
  25. @strict
  26. class CohereConfig(PreTrainedConfig):
  27. r"""
  28. logit_scale (`float`, *optional*, defaults to 0.0625):
  29. The scaling factor for the output logits.
  30. ```python
  31. >>> from transformers import CohereModel, CohereConfig
  32. >>> # Initializing a Cohere model configuration
  33. >>> configuration = CohereConfig()
  34. >>> # Initializing a model from the Cohere configuration
  35. >>> model = CohereModel(configuration) # doctest: +SKIP
  36. >>> # Accessing the model configuration
  37. >>> configuration = model.config # doctest: +SKIP
  38. ```
  39. """
  40. model_type = "cohere"
  41. keys_to_ignore_at_inference = ["past_key_values"]
  42. default_theta = 500000.0
  43. base_model_tp_plan = {
  44. "layers.*.self_attn.q_proj": "colwise",
  45. "layers.*.self_attn.k_proj": "colwise",
  46. "layers.*.self_attn.v_proj": "colwise",
  47. "layers.*.self_attn.o_proj": "rowwise",
  48. "layers.*.mlp.gate_proj": "colwise",
  49. "layers.*.mlp.up_proj": "colwise",
  50. "layers.*.mlp.down_proj": "rowwise",
  51. }
  52. base_model_pp_plan = {
  53. "embed_tokens": (["input_ids"], ["inputs_embeds"]),
  54. "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
  55. "norm": (["hidden_states"], ["hidden_states"]),
  56. }
  57. vocab_size: int = 256000
  58. hidden_size: int = 8192
  59. intermediate_size: int = 22528
  60. logit_scale: float | None = 0.0625
  61. num_hidden_layers: int = 40
  62. num_attention_heads: int = 64
  63. num_key_value_heads: int | None = None
  64. hidden_act: str = "silu"
  65. max_position_embeddings: int = 8192
  66. initializer_range: float = 0.02
  67. layer_norm_eps: float | None = 1e-5
  68. use_cache: bool = True
  69. pad_token_id: int | None = 0
  70. bos_token_id: int | None = 5
  71. eos_token_id: int | list[int] | None = 255001
  72. tie_word_embeddings: bool = True
  73. rope_parameters: RopeParameters | dict | None = None
  74. attention_bias: bool = False
  75. attention_dropout: float | int | None = 0.0
  76. use_qk_norm: bool | None = False
  77. def __post_init__(self, **kwargs):
  78. if self.num_key_value_heads is None:
  79. self.num_key_value_heads = self.num_attention_heads
  80. super().__post_init__(**kwargs)
  81. __all__ = ["CohereConfig"]