modular_arcee.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright 2025 Arcee AI 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. """PyTorch Arcee model."""
  15. from huggingface_hub.dataclasses import strict
  16. from transformers.utils import auto_docstring, logging
  17. from ...modeling_rope_utils import RopeParameters
  18. from ..llama.configuration_llama import LlamaConfig
  19. from ..llama.modeling_llama import (
  20. LlamaForCausalLM,
  21. LlamaForQuestionAnswering,
  22. LlamaForSequenceClassification,
  23. LlamaForTokenClassification,
  24. )
  25. from ..nemotron.modeling_nemotron import NemotronMLP
  26. logger = logging.get_logger(__name__)
  27. @auto_docstring(checkpoint="arcee-ai/AFM-4.5B")
  28. @strict
  29. class ArceeConfig(LlamaConfig):
  30. r"""
  31. ```python
  32. >>> from transformers import ArceeModel, ArceeConfig
  33. >>> # Initializing an Arcee AFM-4.5B-Base style configuration
  34. >>> configuration = ArceeConfig()
  35. >>> # Initializing a model from the AFM-4.5B-Base style configuration
  36. >>> model = ArceeModel(configuration)
  37. >>> # Accessing the model configuration
  38. >>> configuration = model.config
  39. ```"""
  40. model_type = "arcee"
  41. base_model_tp_plan = {
  42. "layers.*.self_attn.q_proj": "colwise",
  43. "layers.*.self_attn.k_proj": "colwise",
  44. "layers.*.self_attn.v_proj": "colwise",
  45. "layers.*.self_attn.o_proj": "rowwise",
  46. "layers.*.mlp.up_proj": "colwise",
  47. "layers.*.mlp.down_proj": "rowwise",
  48. }
  49. vocab_size: int = 32000
  50. hidden_size: int = 2560
  51. intermediate_size: int = 18432
  52. num_hidden_layers: int = 32
  53. num_attention_heads: int = 32
  54. num_key_value_heads: int | None = None
  55. hidden_act: str = "relu2"
  56. max_position_embeddings: int = 4096
  57. initializer_range: float = 0.02
  58. rms_norm_eps: float = 1e-5
  59. use_cache: bool = True
  60. pad_token_id: int | None = None
  61. bos_token_id: int | None = 128000
  62. eos_token_id: int | list[int] | None = 128001
  63. tie_word_embeddings: bool = False
  64. rope_parameters: RopeParameters | dict | None = None
  65. attention_bias: bool = False
  66. attention_dropout: float | int = 0.0
  67. mlp_bias: bool = False
  68. head_dim: int | None = None
  69. pretraining_tp = AttributeError()
  70. class ArceeMLP(NemotronMLP):
  71. pass
  72. @auto_docstring(checkpoint="arcee-ai/AFM-4.5B")
  73. class ArceeForCausalLM(LlamaForCausalLM):
  74. pass
  75. @auto_docstring(checkpoint="arcee-ai/AFM-4.5B")
  76. class ArceeForSequenceClassification(LlamaForSequenceClassification):
  77. pass
  78. @auto_docstring(checkpoint="arcee-ai/AFM-4.5B")
  79. class ArceeForQuestionAnswering(LlamaForQuestionAnswering):
  80. pass
  81. @auto_docstring(checkpoint="arcee-ai/AFM-4.5B")
  82. class ArceeForTokenClassification(LlamaForTokenClassification):
  83. pass
  84. __all__ = [
  85. "ArceeConfig",
  86. "ArceeForCausalLM",
  87. "ArceeForQuestionAnswering",
  88. "ArceeForSequenceClassification",
  89. "ArceeForTokenClassification",
  90. "ArceeModel", # noqa: F822
  91. "ArceePreTrainedModel", # noqa: F822
  92. ]