configuration_rwkv.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2023 The OpenAI Team Authors and HuggingFace Inc. team.
  2. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """RWKV configuration"""
  16. from huggingface_hub.dataclasses import strict
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...utils import auto_docstring
  19. @auto_docstring(checkpoint="RWKV/rwkv-4-169m-pile")
  20. @strict
  21. class RwkvConfig(PreTrainedConfig):
  22. r"""
  23. context_length (`int`, *optional*, defaults to 1024):
  24. The maximum sequence length that this model can be used with in a single forward (using it in RNN mode
  25. lets use any sequence length).
  26. attention_hidden_size (`int`, *optional*):
  27. Dimensionality of the attention hidden states. Will default to `hidden_size` if unset.
  28. rescale_every (`int`, *optional*, defaults to 6):
  29. At inference, the hidden states (and weights of the corresponding output layers) are divided by 2 every
  30. `rescale_every` layer. If set to 0 or a negative number, no rescale is done.
  31. Example:
  32. ```python
  33. >>> from transformers import RwkvConfig, RwkvModel
  34. >>> # Initializing a Rwkv configuration
  35. >>> configuration = RwkvConfig()
  36. >>> # Initializing a model (with random weights) from the configuration
  37. >>> model = RwkvModel(configuration)
  38. >>> # Accessing the model configuration
  39. >>> configuration = model.config
  40. ```"""
  41. model_type = "rwkv"
  42. attribute_map = {"max_position_embeddings": "context_length"}
  43. vocab_size: int = 50277
  44. context_length: int = 1024
  45. hidden_size: int = 4096
  46. num_hidden_layers: int = 32
  47. attention_hidden_size: int | None = None
  48. intermediate_size: int | None = None
  49. layer_norm_epsilon: float = 1e-5
  50. bos_token_id: int | None = 0
  51. eos_token_id: int | list[int] | None = 0
  52. rescale_every: int = 6
  53. tie_word_embeddings: bool = False
  54. use_cache: bool = True
  55. def __post_init__(self, **kwargs):
  56. self.attention_hidden_size = (
  57. self.attention_hidden_size if self.attention_hidden_size is not None else self.hidden_size
  58. )
  59. self.intermediate_size = self.intermediate_size if self.intermediate_size is not None else 4 * self.hidden_size
  60. super().__post_init__(**kwargs)
  61. __all__ = ["RwkvConfig"]