configuration_nemotron.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  2. # Copyright (c) 2024, 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. """Nemotron model configuration"""
  16. from huggingface_hub.dataclasses import strict
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...modeling_rope_utils import RopeParameters
  19. from ...utils import auto_docstring
  20. @auto_docstring(checkpoint="thhaus/nemotron3-8b")
  21. @strict
  22. class NemotronConfig(PreTrainedConfig):
  23. r"""
  24. Example:
  25. ```python
  26. >>> from transformers import NemotronModel, NemotronConfig
  27. >>> # Initializing a Nemotron nemotron-15b style configuration
  28. >>> configuration = NemotronConfig()
  29. >>> # Initializing a model from the nemotron-15b style configuration
  30. >>> model = NemotronModel(configuration)
  31. >>> # Accessing the model configuration
  32. >>> configuration = model.config
  33. ```"""
  34. model_type = "nemotron"
  35. keys_to_ignore_at_inference = ["past_key_values"]
  36. vocab_size: int = 256000
  37. hidden_size: int = 6144
  38. intermediate_size: int = 24576
  39. num_hidden_layers: int = 32
  40. num_attention_heads: int = 48
  41. head_dim: int | None = None
  42. num_key_value_heads: int | None = None
  43. hidden_act: str = "relu2"
  44. max_position_embeddings: int = 4096
  45. initializer_range: float = 0.0134
  46. norm_eps: float = 1e-5
  47. use_cache: bool = True
  48. pad_token_id: int | None = None
  49. bos_token_id: int | None = 2
  50. eos_token_id: int | list[int] | None = 3
  51. tie_word_embeddings: bool = False
  52. rope_parameters: RopeParameters | dict | None = None
  53. attention_bias: bool = False
  54. attention_dropout: float | int = 0.0
  55. mlp_bias: bool = False
  56. def __post_init__(self, **kwargs):
  57. self.head_dim = self.head_dim if self.head_dim is not None else self.hidden_size // self.num_attention_heads
  58. kwargs.setdefault("partial_rotary_factor", 0.5) # assign default for BC
  59. super().__post_init__(**kwargs)
  60. __all__ = ["NemotronConfig"]