configuration_opt.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2022 The Metaseq Authors and The HuggingFace Inc. 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. """OPT 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="facebook/opt-350m")
  19. @strict
  20. class OPTConfig(PreTrainedConfig):
  21. r"""
  22. do_layer_norm_before (`bool`, *optional*, defaults to `True`):
  23. Whether to perform layer normalization before the attention block.
  24. word_embed_proj_dim (`int`, *optional*):
  25. `word_embed_proj_dim` can be set to down-project word embeddings, *e.g.* `opt-350m`. Defaults to
  26. `hidden_size`.
  27. enable_bias (`bool`, *optional*, defaults to `True`):
  28. Whether or not if the linear layers in the attention blocks should use the bias term.
  29. layer_norm_elementwise_affine (`bool`, *optional*, defaults to `True`):
  30. Whether or not if the layer norms should have learnable parameters.
  31. Example:
  32. ```python
  33. >>> from transformers import OPTConfig, OPTModel
  34. >>> # Initializing a OPT facebook/opt-large style configuration
  35. >>> configuration = OPTConfig()
  36. >>> # Initializing a model (with random weights) from the facebook/opt-large style configuration
  37. >>> model = OPTModel(configuration)
  38. >>> # Accessing the model configuration
  39. >>> configuration = model.config
  40. ```"""
  41. model_type = "opt"
  42. keys_to_ignore_at_inference = ["past_key_values"]
  43. vocab_size: int = 50272
  44. hidden_size: int = 768
  45. num_hidden_layers: int = 12
  46. ffn_dim: int = 3072
  47. max_position_embeddings: int = 2048
  48. do_layer_norm_before: bool = True
  49. _remove_final_layer_norm: bool = False
  50. word_embed_proj_dim: int | None = None
  51. dropout: float | int = 0.1
  52. attention_dropout: float | int = 0.0
  53. num_attention_heads: int = 12
  54. activation_function: str = "relu"
  55. layerdrop: float | int = 0.0
  56. init_std: float = 0.02
  57. use_cache: bool = True
  58. pad_token_id: int | None = 1
  59. bos_token_id: int | None = 2
  60. eos_token_id: int | list[int] | None = 2
  61. enable_bias: bool = True
  62. layer_norm_elementwise_affine: bool = True
  63. tie_word_embeddings: bool = True
  64. def __post_init__(self, **kwargs):
  65. self.word_embed_proj_dim = (
  66. self.word_embed_proj_dim if self.word_embed_proj_dim is not None else self.hidden_size
  67. )
  68. super().__post_init__(**kwargs)
  69. __all__ = ["OPTConfig"]