configuration_led.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2021 Iz Beltagy, Matthew E. Peters, Arman Cohan 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. """LED 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="allenai/led-base-16384")
  19. @strict
  20. class LEDConfig(PreTrainedConfig):
  21. r"""
  22. max_encoder_position_embeddings (`int`, *optional*, defaults to 16384):
  23. The maximum sequence length that the encoder might ever be used with.
  24. max_decoder_position_embeddings (`int`, *optional*, defaults to 16384):
  25. The maximum sequence length that the decoder might ever be used with.
  26. attention_window (`int` or `list[int]`, *optional*, defaults to 512):
  27. Size of an attention window around each token. If an `int`, use the same size for all layers. To specify a
  28. different window size for each layer, use a `list[int]` where `len(attention_window) == num_hidden_layers`.
  29. Example:
  30. ```python
  31. >>> from transformers import LEDModel, LEDConfig
  32. >>> # Initializing a LED allenai/led-base-16384 style configuration
  33. >>> configuration = LEDConfig()
  34. >>> # Initializing a model from the allenai/led-base-16384 style configuration
  35. >>> model = LEDModel(configuration)
  36. >>> # Accessing the model configuration
  37. >>> configuration = model.config
  38. ```"""
  39. model_type = "led"
  40. attribute_map = {
  41. "num_attention_heads": "encoder_attention_heads",
  42. "hidden_size": "d_model",
  43. "attention_probs_dropout_prob": "attention_dropout",
  44. "initializer_range": "init_std",
  45. "num_hidden_layers": "encoder_layers",
  46. }
  47. vocab_size: int = 50265
  48. max_encoder_position_embeddings: int = 16384
  49. max_decoder_position_embeddings: int = 1024
  50. encoder_layers: int = 12
  51. encoder_ffn_dim: int = 4096
  52. encoder_attention_heads: int = 16
  53. decoder_layers: int = 12
  54. decoder_ffn_dim: int = 4096
  55. decoder_attention_heads: int = 16
  56. encoder_layerdrop: float | int = 0.0
  57. decoder_layerdrop: float | int = 0.0
  58. use_cache: bool = True
  59. is_encoder_decoder: bool = True
  60. activation_function: str = "gelu"
  61. d_model: int = 1024
  62. dropout: float | int = 0.1
  63. attention_dropout: float | int = 0.0
  64. activation_dropout: float | int = 0.0
  65. init_std: float = 0.02
  66. decoder_start_token_id: int = 2
  67. classifier_dropout: float | int = 0.0
  68. pad_token_id: int | None = 1
  69. bos_token_id: int | None = 0
  70. eos_token_id: int | list[int] | None = 2
  71. attention_window: list[int] | int = 512
  72. tie_word_embeddings: bool = True
  73. __all__ = ["LEDConfig"]