configuration_codegen.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright 2022 Salesforce authors, The EleutherAI, and HuggingFace Teams. 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. """CodeGen model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="Salesforce/codegen-2B-mono")
  19. @strict
  20. class CodeGenConfig(PreTrainedConfig):
  21. r"""
  22. n_ctx (`int`, *optional*, defaults to 2048):
  23. This attribute is used in `CodeGenModel.__init__` without any real effect.
  24. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  25. rotary_dim (`int`, *optional*, defaults to 64):
  26. Number of dimensions in the embedding that Rotary Position Embedding is applied to.
  27. n_inner (`int`, *optional*):
  28. Dimensionality of the inner feed-forward layers. `None` will set it to 4 times n_embd
  29. Example:
  30. ```python
  31. >>> from transformers import CodeGenConfig, CodeGenModel
  32. >>> # Initializing a CodeGen 6B configuration
  33. >>> configuration = CodeGenConfig()
  34. >>> # Initializing a model (with random weights) from the configuration
  35. >>> model = CodeGenModel(configuration)
  36. >>> # Accessing the model configuration
  37. >>> configuration = model.config
  38. ```"""
  39. model_type = "codegen"
  40. attribute_map = {
  41. "max_position_embeddings": "n_positions",
  42. "hidden_size": "n_embd",
  43. "num_attention_heads": "n_head",
  44. "num_hidden_layers": "n_layer",
  45. }
  46. vocab_size: int = 50400
  47. n_positions: int = 2048
  48. n_ctx: int = 2048
  49. n_embd: int = 4096
  50. n_layer: int = 28
  51. n_head: int = 16
  52. rotary_dim: int = 64
  53. n_inner: int | None = None
  54. activation_function: str = "gelu_new"
  55. resid_pdrop: float | int = 0.0
  56. embd_pdrop: float | int = 0.0
  57. attn_pdrop: float | int = 0.0
  58. layer_norm_epsilon: float = 1e-5
  59. initializer_range: float = 0.02
  60. use_cache: bool = True
  61. bos_token_id: int | None = 50256
  62. eos_token_id: int | list[int] | None = 50256
  63. tie_word_embeddings: bool = False
  64. __all__ = ["CodeGenConfig"]