scatterbrain-sm-experimental / configuration_scatterbrain.py
ToastyPigeon's picture
Upload folder using huggingface_hub
9711198 verified
# Configuration for Scatterbrain - a single MoE layer looped multiple times
#
# Based on Qwen3MoeConfig
from transformers.configuration_utils import PretrainedConfig
class ScatterbrainConfig(PretrainedConfig):
r"""
Configuration class for Scatterbrain - a model that loops a single MoE layer multiple times.
Args:
vocab_size (`int`, *optional*, defaults to 151936):
Vocabulary size of the model.
hidden_size (`int`, *optional*, defaults to 2048):
Dimension of the hidden representations.
intermediate_size (`int`, *optional*, defaults to 6144):
Dimension of the MLP intermediate representations (for dense layers).
moe_intermediate_size (`int`, *optional*, defaults to 768):
Dimension of the MLP intermediate representations for each expert.
num_hidden_layers (`int`, *optional*, defaults to 1):
Number of physical decoder layers. For Scatterbrain this is always 1.
num_loop_iterations (`int`, *optional*, defaults to 30):
Number of times to loop through the single layer.
num_attention_heads (`int`, *optional*, defaults to 32):
Number of attention heads for each attention layer.
num_key_value_heads (`int`, *optional*, defaults to 4):
Number of key_value heads for Grouped Query Attention.
head_dim (`int`, *optional*, defaults to 128):
Dimension of each attention head.
hidden_act (`str`, *optional*, defaults to `"silu"`):
Activation function in the MLP.
max_position_embeddings (`int`, *optional*, defaults to 262144):
Maximum sequence length.
initializer_range (`float`, *optional*, defaults to 0.02):
Standard deviation for weight initialization.
rms_norm_eps (`float`, *optional*, defaults to 1e-6):
Epsilon for RMS normalization.
use_cache (`bool`, *optional*, defaults to `True`):
Whether to use KV cache.
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
Whether to tie input and output embeddings.
rope_theta (`float`, *optional*, defaults to 10000000.0):
Base period for rotary embeddings.
attention_dropout (`float`, *optional*, defaults to 0.0):
Dropout ratio for attention weights.
num_experts (`int`, *optional*, defaults to 128):
Number of experts in the MoE layer.
num_experts_per_tok (`int`, *optional*, defaults to 8):
Number of experts activated per token.
norm_topk_prob (`bool`, *optional*, defaults to `True`):
Whether to normalize top-k routing probabilities.
router_aux_loss_coef (`float`, *optional*, defaults to 0.001):
Coefficient for router auxiliary loss.
"""
model_type = "scatterbrain"
keys_to_ignore_at_inference = ["past_key_values"]
def __init__(
self,
vocab_size=151936,
hidden_size=2048,
intermediate_size=6144,
moe_intermediate_size=768,
num_hidden_layers=1,
num_loop_iterations=30,
num_attention_heads=32,
num_key_value_heads=4,
head_dim=128,
hidden_act="silu",
max_position_embeddings=262144,
initializer_range=0.02,
rms_norm_eps=1e-6,
use_cache=True,
tie_word_embeddings=False,
rope_theta=10000000.0,
rope_scaling=None,
attention_dropout=0.0,
attention_bias=False,
num_experts=128,
num_experts_per_tok=8,
norm_topk_prob=True,
output_router_logits=False,
router_aux_loss_coef=0.001,
decoder_sparse_step=1,
mlp_only_layers=None,
sliding_window=None,
use_sliding_window=False,
max_window_layers=48,
pad_token_id=None,
bos_token_id=151643,
eos_token_id=151645,
**kwargs,
):
self.vocab_size = vocab_size
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.moe_intermediate_size = moe_intermediate_size
self.num_hidden_layers = num_hidden_layers
self.num_loop_iterations = num_loop_iterations
self.num_attention_heads = num_attention_heads
self.num_key_value_heads = num_key_value_heads
self.head_dim = head_dim
self.hidden_act = hidden_act
self.max_position_embeddings = max_position_embeddings
self.initializer_range = initializer_range
self.rms_norm_eps = rms_norm_eps
self.use_cache = use_cache
self.rope_theta = rope_theta
self.rope_scaling = rope_scaling
self.attention_dropout = attention_dropout
self.attention_bias = attention_bias
self.num_experts = num_experts
self.num_experts_per_tok = num_experts_per_tok
self.norm_topk_prob = norm_topk_prob
self.output_router_logits = output_router_logits
self.router_aux_loss_coef = router_aux_loss_coef
self.decoder_sparse_step = decoder_sparse_step
self.mlp_only_layers = mlp_only_layers if mlp_only_layers is not None else []
self.sliding_window = sliding_window
self.use_sliding_window = use_sliding_window
self.max_window_layers = max_window_layers
super().__init__(
pad_token_id=pad_token_id,
bos_token_id=bos_token_id,
eos_token_id=eos_token_id,
tie_word_embeddings=tie_word_embeddings,
**kwargs,
)