Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- config.json +56 -0
- configuration_dragon.py +197 -0
- generation_config.json +8 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +627 -0
- modeling_dragon.py +1280 -0
- special_tokens_map.json +5 -0
- tokenizer.json +3 -0
- tokenizer_config.json +219 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"A_init_range": [
|
| 3 |
+
1,
|
| 4 |
+
16
|
| 5 |
+
],
|
| 6 |
+
"architectures": [
|
| 7 |
+
"DragonForCausalLM"
|
| 8 |
+
],
|
| 9 |
+
"attention_bias": false,
|
| 10 |
+
"attention_dropout": 0.0,
|
| 11 |
+
"auto_map": {
|
| 12 |
+
"AutoConfig": "configuration_dragon.DragonConfig",
|
| 13 |
+
"AutoModel": "modeling_dragon.DragonModel",
|
| 14 |
+
"AutoModelForCausalLM": "modeling_dragon.DragonForCausalLM"
|
| 15 |
+
},
|
| 16 |
+
"bos_token_id": 0,
|
| 17 |
+
"conv_kernel": 4,
|
| 18 |
+
"dtype": "bfloat16",
|
| 19 |
+
"eos_token_id": 0,
|
| 20 |
+
"eot_token_id": 0,
|
| 21 |
+
"expand_factor": 2,
|
| 22 |
+
"hidden_dropout": 0.0,
|
| 23 |
+
"hidden_size": 2048,
|
| 24 |
+
"initializer_range": 0.006,
|
| 25 |
+
"intermediate_size": 8192,
|
| 26 |
+
"layers_config": "lrlrdlrlrlrlrdlrlrlrlrdlrlrlrlrdlrlr",
|
| 27 |
+
"max_position_embeddings": 32768,
|
| 28 |
+
"mlp_bias": false,
|
| 29 |
+
"mlp_hidden_act": "relu2",
|
| 30 |
+
"model_type": "dragon",
|
| 31 |
+
"norm_epsilon": 1e-06,
|
| 32 |
+
"num_attention_heads": 32,
|
| 33 |
+
"num_hidden_layers": 36,
|
| 34 |
+
"num_key_value_heads": 16,
|
| 35 |
+
"num_logits_to_keep": 1,
|
| 36 |
+
"old_lns": true,
|
| 37 |
+
"pad_token_id": 0,
|
| 38 |
+
"qk_norm": true,
|
| 39 |
+
"residual_in_fp32": false,
|
| 40 |
+
"rope_theta": 163,
|
| 41 |
+
"scalable_softmax": true,
|
| 42 |
+
"sliding_window_size": 1024,
|
| 43 |
+
"slw_wsize": 32768,
|
| 44 |
+
"softcap_global_attn": 150.0,
|
| 45 |
+
"softcap_local_attn": 0.0,
|
| 46 |
+
"tie_word_embeddings": false,
|
| 47 |
+
"time_step_floor": 0.0001,
|
| 48 |
+
"time_step_max": 0.1,
|
| 49 |
+
"time_step_min": 0.001,
|
| 50 |
+
"transformers_version": "4.56.1",
|
| 51 |
+
"uscaling_tau": 0.2,
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
"""Dragon model configuration"""
|
| 3 |
+
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 7 |
+
from transformers.utils import logging
|
| 8 |
+
|
| 9 |
+
logger = logging.get_logger(__name__)
|
| 10 |
+
|
| 11 |
+
#@register_for_auto_class("AutoConfig")
|
| 12 |
+
class DragonConfig(PretrainedConfig):
|
| 13 |
+
r"""
|
| 14 |
+
This is the configuration class to store the configuration of a [`DragonModel`]. It is used to instantiate a
|
| 15 |
+
Dragon model according to the specified arguments, defining the model architecture.
|
| 16 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 17 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 18 |
+
Args:
|
| 19 |
+
vocab_size (`int`, *optional*, defaults to 151936):
|
| 20 |
+
Vocabulary size of the Dragon model. Defines the number of different tokens that can be represented by the
|
| 21 |
+
`inputs_ids` passed when calling [`DragonModel`]
|
| 22 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 23 |
+
Whether the model's input and output word embeddings should be tied. Note that this is only relevant if the
|
| 24 |
+
model has a output word embedding layer.
|
| 25 |
+
hidden_size (`int`, *optional*, defaults to 2048):
|
| 26 |
+
Dimension of the hidden representations.
|
| 27 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
| 28 |
+
Dimension of the MLP representations.
|
| 29 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 30 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 31 |
+
num_key_value_heads (`int`, *optional*, defaults to 8):
|
| 32 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 33 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 34 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used.
|
| 35 |
+
mlp_hidden_act (`str`, *optional*, defaults to "relu2"):
|
| 36 |
+
The non-linear activation function in the MLP layers.
|
| 37 |
+
attention_bias (`bool`, *optional*, defaults to `False`):
|
| 38 |
+
Whether to use bias in attention layers.
|
| 39 |
+
mlp_bias (`bool`, *optional*, defaults to `False`):
|
| 40 |
+
Whether to use bias in MLP layers.
|
| 41 |
+
use_bias (`bool`, *optional*, defaults to `False`):
|
| 42 |
+
Whether to use bias in the model.
|
| 43 |
+
initializer_range (`float`, *optional*, defaults to 0.006):
|
| 44 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 45 |
+
norm_epsilon (`float`, *optional*, defaults to 1e-5):
|
| 46 |
+
The epsilon used by the layer normalization layers.
|
| 47 |
+
residual_in_fp32 (`bool`, *optional*, defaults to `False`):
|
| 48 |
+
Whether or not residuals should be in `float32`. If set to `False` residuals will keep the same `dtype` as the rest of the model.
|
| 49 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 50 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 51 |
+
relevant if `config.is_decoder=True`.
|
| 52 |
+
num_logits_to_keep (`int` or `None`, *optional*, defaults to 1):
|
| 53 |
+
Number of prompt logits to calculate during generation. If `None`, all logits will be calculated. If an
|
| 54 |
+
integer value, only last `num_logits_to_keep` logits will be calculated.
|
| 55 |
+
pad_token_id (`int`, *optional*, defaults to 0):
|
| 56 |
+
The id of the padding token.
|
| 57 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 58 |
+
The id of the "beginning-of-sequence" token.
|
| 59 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
| 60 |
+
The id of the "end-of-sequence" token.
|
| 61 |
+
sliding_window_size (`int`, *optional*, defaults to 1024):
|
| 62 |
+
Sliding window attention window size.
|
| 63 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 64 |
+
The maximum sequence length that this model might ever be used with.
|
| 65 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 66 |
+
The dropout ratio for the attention probabilities.
|
| 67 |
+
hidden_dropout (`float`, *optional*, defaults to 0.0):
|
| 68 |
+
The dropout ratio for the hidden states.
|
| 69 |
+
use_mamba_kernels (`bool`, *optional*, defaults to `True`):
|
| 70 |
+
Flag indicating whether or not to use the fast mamba kernels. These are available only if `mamba-ssm` and
|
| 71 |
+
`causal-conv1d` are installed, and the mamba modules are running on a CUDA device.
|
| 72 |
+
mamba_d_conv (`int`, *optional*, defaults to 4):
|
| 73 |
+
The size of the mamba convolution kernel.
|
| 74 |
+
mamba_expand (`int`, *optional*, defaults to 2):
|
| 75 |
+
Expanding factor used to determine the mamba intermediate size.
|
| 76 |
+
mamba_hidden_act (`str`, *optional*, defaults to "silu"):
|
| 77 |
+
The non-linear activation function in the Mamba layers.
|
| 78 |
+
mamba_dt_min (`float`, *optional*, defaults to 0.001):
|
| 79 |
+
Minimum value for the time step in Mamba.
|
| 80 |
+
mamba_dt_max (`float`, *optional*, defaults to 0.1):
|
| 81 |
+
Maximum value for the time step in Mamba.
|
| 82 |
+
mamba_dt_limit (`tuple`, *optional*, defaults to (0.0, float("inf"))):
|
| 83 |
+
Limits for the time step in Mamba.
|
| 84 |
+
mamba_dt_init_floor (`float`, *optional*, defaults to 1e-4):
|
| 85 |
+
Floor value for time step initialization in Mamba.
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
model_type = "dragon"
|
| 89 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 90 |
+
|
| 91 |
+
def __init__(
|
| 92 |
+
self,
|
| 93 |
+
vocab_size=151936,
|
| 94 |
+
tie_word_embeddings=False,
|
| 95 |
+
max_position_embeddings=8192,
|
| 96 |
+
use_uscaling=True,
|
| 97 |
+
hidden_size=2048,
|
| 98 |
+
intermediate_size=8192,
|
| 99 |
+
expand_factor=2,
|
| 100 |
+
layers_config=4*"lrdlr",
|
| 101 |
+
num_attention_heads=32,
|
| 102 |
+
num_key_value_heads=8,
|
| 103 |
+
mlp_hidden_act="relu2",
|
| 104 |
+
attention_bias=False,
|
| 105 |
+
mlp_bias=False,
|
| 106 |
+
use_bias=False,
|
| 107 |
+
initializer_range=0.006,
|
| 108 |
+
softcap_local_attn=0.0,
|
| 109 |
+
softcap_global_attn=150.0,
|
| 110 |
+
norm_epsilon=1e-6,
|
| 111 |
+
residual_in_fp32=False,
|
| 112 |
+
use_cache=True,
|
| 113 |
+
num_logits_to_keep=1,
|
| 114 |
+
pad_token_id=0,
|
| 115 |
+
bos_token_id=1,
|
| 116 |
+
eos_token_id=2,
|
| 117 |
+
sliding_window_size=1024,
|
| 118 |
+
slw_wsize=-1,
|
| 119 |
+
rope_theta_local=163.,
|
| 120 |
+
uscaling_tau=0.2,
|
| 121 |
+
attention_dropout=0.,
|
| 122 |
+
hidden_dropout=0.,
|
| 123 |
+
gdn_d_conv=4,
|
| 124 |
+
gdn_dt_min=0.001,
|
| 125 |
+
gdn_dt_max=0.1,
|
| 126 |
+
gdn_dt_init_floor=1e-4,
|
| 127 |
+
gdn_A_init_range=(1, 16),
|
| 128 |
+
old_lns=False,
|
| 129 |
+
**kwargs,
|
| 130 |
+
):
|
| 131 |
+
|
| 132 |
+
self.rope_theta = rope_theta_local
|
| 133 |
+
self.qk_norm = True
|
| 134 |
+
self.softcap_local_attn=softcap_local_attn
|
| 135 |
+
self.softcap_global_attn=softcap_global_attn
|
| 136 |
+
self.use_uscaling = use_uscaling
|
| 137 |
+
self.uscaling_tau = uscaling_tau
|
| 138 |
+
self.scalable_softmax = True
|
| 139 |
+
|
| 140 |
+
self.vocab_size = vocab_size
|
| 141 |
+
self.tie_word_embeddings = tie_word_embeddings
|
| 142 |
+
self.hidden_size = hidden_size
|
| 143 |
+
self.intermediate_size = intermediate_size
|
| 144 |
+
self.expand_factor = expand_factor
|
| 145 |
+
self.layers_config = layers_config
|
| 146 |
+
self.num_hidden_layers = len(layers_config)
|
| 147 |
+
self.num_attention_heads = num_attention_heads
|
| 148 |
+
self.sliding_window_size = sliding_window_size
|
| 149 |
+
self.slw_wsize = slw_wsize
|
| 150 |
+
self.attention_dropout = attention_dropout
|
| 151 |
+
self.hidden_dropout = hidden_dropout
|
| 152 |
+
self.max_position_embeddings = max_position_embeddings
|
| 153 |
+
|
| 154 |
+
if num_key_value_heads is None:
|
| 155 |
+
num_key_value_heads = num_attention_heads
|
| 156 |
+
|
| 157 |
+
self.num_key_value_heads = num_key_value_heads
|
| 158 |
+
self.mlp_hidden_act = mlp_hidden_act
|
| 159 |
+
self.attention_bias = attention_bias
|
| 160 |
+
self.mlp_bias = mlp_bias
|
| 161 |
+
self.use_bias = use_bias
|
| 162 |
+
self.initializer_range = initializer_range
|
| 163 |
+
self.norm_epsilon = norm_epsilon
|
| 164 |
+
self.residual_in_fp32 = residual_in_fp32
|
| 165 |
+
|
| 166 |
+
self.use_cache = use_cache
|
| 167 |
+
self.num_logits_to_keep = num_logits_to_keep
|
| 168 |
+
|
| 169 |
+
self.conv_kernel = gdn_d_conv
|
| 170 |
+
self.time_step_min = gdn_dt_min
|
| 171 |
+
self.time_step_max = gdn_dt_max
|
| 172 |
+
self.time_step_floor = gdn_dt_init_floor
|
| 173 |
+
self.A_init_range = gdn_A_init_range
|
| 174 |
+
|
| 175 |
+
self.old_lns = old_lns
|
| 176 |
+
|
| 177 |
+
assert self.hidden_size % self.num_attention_heads == 0
|
| 178 |
+
assert self.num_attention_heads % self.num_key_value_heads == 0
|
| 179 |
+
assert self.num_attention_heads % 2 == 0, "Number of attention heads must be even for differential attention."
|
| 180 |
+
assert self.num_key_value_heads % 2 == 0, "Number of kv heads must be even for differential attention."
|
| 181 |
+
|
| 182 |
+
super().__init__(
|
| 183 |
+
pad_token_id=pad_token_id,
|
| 184 |
+
bos_token_id=bos_token_id,
|
| 185 |
+
eos_token_id=eos_token_id,
|
| 186 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 187 |
+
**kwargs,
|
| 188 |
+
)
|
| 189 |
+
# TODO: better way to handle those?
|
| 190 |
+
self.auto_map = dict(getattr(self, "auto_map", {}))
|
| 191 |
+
self.auto_map.setdefault("AutoConfig", "configuration_dragon.DragonConfig")
|
| 192 |
+
self.auto_map.setdefault("AutoModel", "modeling_dragon.DragonModel")
|
| 193 |
+
self.auto_map.setdefault("AutoModelForCausalLM", "modeling_dragon.DragonForCausalLM")
|
| 194 |
+
|
| 195 |
+
DragonConfig.register_for_auto_class("AutoConfig")
|
| 196 |
+
__all__ = ["DragonConfig"]
|
| 197 |
+
# todo : update docstrings
|
generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 0,
|
| 4 |
+
"eos_token_id": 0,
|
| 5 |
+
"eot_token_id": 0,
|
| 6 |
+
"pad_token_id": 0,
|
| 7 |
+
"transformers_version": "4.56.1"
|
| 8 |
+
}
|
model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:26dc76a87683ef4caf3539a44127b7f2545a4dd900827e42d7ea490fc960a44a
|
| 3 |
+
size 4992581544
|
model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256: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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_parameters": 3697865088,
|
| 4 |
+
"total_size": 7395730176
|
| 5 |
+
},
|
| 6 |
+
"weight_map": {
|
| 7 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 8 |
+
"model.embedding.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.final_norm.weight": "model-00002-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.0.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.0.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.0.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.0.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.0.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.0.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.0.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.0.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.0.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.0.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.0.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.0.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.0.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.1.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.1.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.1.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.1.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.1.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.1.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.1.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.1.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.1.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.1.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.1.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.1.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.1.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.1.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.1.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.1.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.10.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.10.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.10.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.10.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.10.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.10.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.10.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.10.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.10.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.10.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.10.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.10.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.10.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.10.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.10.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.10.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.11.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.11.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.11.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.11.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.11.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.11.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.11.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.11.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.11.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.11.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.11.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.11.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.11.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.11.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"model.layers.11.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.11.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"model.layers.11.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"model.layers.12.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"model.layers.12.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.12.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.12.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.12.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.12.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.12.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.12.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.12.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.12.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.12.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.12.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.12.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.12.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.12.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.12.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.13.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 93 |
+
"model.layers.13.attn.lambda_k1": "model-00001-of-00002.safetensors",
|
| 94 |
+
"model.layers.13.attn.lambda_k2": "model-00001-of-00002.safetensors",
|
| 95 |
+
"model.layers.13.attn.lambda_q1": "model-00001-of-00002.safetensors",
|
| 96 |
+
"model.layers.13.attn.lambda_q2": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.13.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 98 |
+
"model.layers.13.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 99 |
+
"model.layers.13.attn.softmax_scaler": "model-00001-of-00002.safetensors",
|
| 100 |
+
"model.layers.13.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 101 |
+
"model.layers.13.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 102 |
+
"model.layers.13.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 103 |
+
"model.layers.13.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 104 |
+
"model.layers.13.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 105 |
+
"model.layers.13.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 106 |
+
"model.layers.13.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 107 |
+
"model.layers.13.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 108 |
+
"model.layers.13.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 109 |
+
"model.layers.13.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 110 |
+
"model.layers.13.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 111 |
+
"model.layers.13.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 112 |
+
"model.layers.13.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 113 |
+
"model.layers.13.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 114 |
+
"model.layers.14.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 115 |
+
"model.layers.14.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 116 |
+
"model.layers.14.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 117 |
+
"model.layers.14.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 118 |
+
"model.layers.14.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 119 |
+
"model.layers.14.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 120 |
+
"model.layers.14.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 121 |
+
"model.layers.14.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 122 |
+
"model.layers.14.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 123 |
+
"model.layers.14.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 124 |
+
"model.layers.14.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 125 |
+
"model.layers.14.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 126 |
+
"model.layers.14.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 127 |
+
"model.layers.14.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 128 |
+
"model.layers.14.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 129 |
+
"model.layers.14.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 130 |
+
"model.layers.14.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 131 |
+
"model.layers.15.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 132 |
+
"model.layers.15.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 133 |
+
"model.layers.15.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 134 |
+
"model.layers.15.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 135 |
+
"model.layers.15.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 136 |
+
"model.layers.15.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 137 |
+
"model.layers.15.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 138 |
+
"model.layers.15.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 139 |
+
"model.layers.15.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 140 |
+
"model.layers.15.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 141 |
+
"model.layers.15.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 142 |
+
"model.layers.15.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 143 |
+
"model.layers.15.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 144 |
+
"model.layers.15.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 145 |
+
"model.layers.15.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 146 |
+
"model.layers.15.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.16.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.16.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.16.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.16.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.16.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 152 |
+
"model.layers.16.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 153 |
+
"model.layers.16.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 154 |
+
"model.layers.16.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 155 |
+
"model.layers.16.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 156 |
+
"model.layers.16.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 157 |
+
"model.layers.16.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 158 |
+
"model.layers.16.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 159 |
+
"model.layers.16.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 160 |
+
"model.layers.16.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 161 |
+
"model.layers.16.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 162 |
+
"model.layers.16.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 163 |
+
"model.layers.16.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 164 |
+
"model.layers.17.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 165 |
+
"model.layers.17.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 166 |
+
"model.layers.17.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 167 |
+
"model.layers.17.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 168 |
+
"model.layers.17.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 169 |
+
"model.layers.17.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 170 |
+
"model.layers.17.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 171 |
+
"model.layers.17.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 172 |
+
"model.layers.17.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 173 |
+
"model.layers.17.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 174 |
+
"model.layers.17.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 175 |
+
"model.layers.17.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 176 |
+
"model.layers.17.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 177 |
+
"model.layers.17.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 178 |
+
"model.layers.17.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 179 |
+
"model.layers.17.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 180 |
+
"model.layers.18.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 181 |
+
"model.layers.18.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 182 |
+
"model.layers.18.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 183 |
+
"model.layers.18.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 184 |
+
"model.layers.18.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 185 |
+
"model.layers.18.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 186 |
+
"model.layers.18.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 187 |
+
"model.layers.18.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 188 |
+
"model.layers.18.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 189 |
+
"model.layers.18.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 190 |
+
"model.layers.18.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 191 |
+
"model.layers.18.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 192 |
+
"model.layers.18.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 193 |
+
"model.layers.18.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 194 |
+
"model.layers.18.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 195 |
+
"model.layers.18.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 196 |
+
"model.layers.18.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 197 |
+
"model.layers.19.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 198 |
+
"model.layers.19.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 199 |
+
"model.layers.19.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 200 |
+
"model.layers.19.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 201 |
+
"model.layers.19.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 202 |
+
"model.layers.19.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 203 |
+
"model.layers.19.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 204 |
+
"model.layers.19.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 205 |
+
"model.layers.19.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 206 |
+
"model.layers.19.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 207 |
+
"model.layers.19.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 208 |
+
"model.layers.19.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 209 |
+
"model.layers.19.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 210 |
+
"model.layers.19.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 211 |
+
"model.layers.19.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 212 |
+
"model.layers.19.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 213 |
+
"model.layers.2.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 214 |
+
"model.layers.2.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 215 |
+
"model.layers.2.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 216 |
+
"model.layers.2.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 217 |
+
"model.layers.2.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 218 |
+
"model.layers.2.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 219 |
+
"model.layers.2.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 220 |
+
"model.layers.2.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 221 |
+
"model.layers.2.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 222 |
+
"model.layers.2.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 223 |
+
"model.layers.2.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 224 |
+
"model.layers.2.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 225 |
+
"model.layers.2.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 226 |
+
"model.layers.2.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 227 |
+
"model.layers.2.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 228 |
+
"model.layers.2.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 229 |
+
"model.layers.2.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 230 |
+
"model.layers.20.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 231 |
+
"model.layers.20.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 232 |
+
"model.layers.20.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 233 |
+
"model.layers.20.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 234 |
+
"model.layers.20.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 235 |
+
"model.layers.20.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 236 |
+
"model.layers.20.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 237 |
+
"model.layers.20.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 238 |
+
"model.layers.20.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 239 |
+
"model.layers.20.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 240 |
+
"model.layers.20.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 241 |
+
"model.layers.20.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 242 |
+
"model.layers.20.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 243 |
+
"model.layers.20.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 244 |
+
"model.layers.20.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 245 |
+
"model.layers.20.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 246 |
+
"model.layers.20.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 247 |
+
"model.layers.21.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 248 |
+
"model.layers.21.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 249 |
+
"model.layers.21.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 250 |
+
"model.layers.21.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 251 |
+
"model.layers.21.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 252 |
+
"model.layers.21.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 253 |
+
"model.layers.21.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 254 |
+
"model.layers.21.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 255 |
+
"model.layers.21.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 256 |
+
"model.layers.21.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 257 |
+
"model.layers.21.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 258 |
+
"model.layers.21.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 259 |
+
"model.layers.21.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 260 |
+
"model.layers.21.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 261 |
+
"model.layers.21.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 262 |
+
"model.layers.21.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 263 |
+
"model.layers.22.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 264 |
+
"model.layers.22.attn.lambda_k1": "model-00001-of-00002.safetensors",
|
| 265 |
+
"model.layers.22.attn.lambda_k2": "model-00001-of-00002.safetensors",
|
| 266 |
+
"model.layers.22.attn.lambda_q1": "model-00001-of-00002.safetensors",
|
| 267 |
+
"model.layers.22.attn.lambda_q2": "model-00001-of-00002.safetensors",
|
| 268 |
+
"model.layers.22.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 269 |
+
"model.layers.22.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 270 |
+
"model.layers.22.attn.softmax_scaler": "model-00001-of-00002.safetensors",
|
| 271 |
+
"model.layers.22.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 272 |
+
"model.layers.22.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 273 |
+
"model.layers.22.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 274 |
+
"model.layers.22.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 275 |
+
"model.layers.22.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 276 |
+
"model.layers.22.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 277 |
+
"model.layers.22.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 278 |
+
"model.layers.22.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 279 |
+
"model.layers.22.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 280 |
+
"model.layers.22.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 281 |
+
"model.layers.22.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 282 |
+
"model.layers.22.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 283 |
+
"model.layers.22.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 284 |
+
"model.layers.22.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 285 |
+
"model.layers.23.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 286 |
+
"model.layers.23.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 287 |
+
"model.layers.23.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 288 |
+
"model.layers.23.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 289 |
+
"model.layers.23.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 290 |
+
"model.layers.23.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 291 |
+
"model.layers.23.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 292 |
+
"model.layers.23.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 293 |
+
"model.layers.23.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 294 |
+
"model.layers.23.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 295 |
+
"model.layers.23.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 296 |
+
"model.layers.23.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 297 |
+
"model.layers.23.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 298 |
+
"model.layers.23.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 299 |
+
"model.layers.23.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 300 |
+
"model.layers.23.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 301 |
+
"model.layers.23.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 302 |
+
"model.layers.24.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 303 |
+
"model.layers.24.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 304 |
+
"model.layers.24.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 305 |
+
"model.layers.24.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 306 |
+
"model.layers.24.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 307 |
+
"model.layers.24.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 308 |
+
"model.layers.24.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 309 |
+
"model.layers.24.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 310 |
+
"model.layers.24.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 311 |
+
"model.layers.24.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 312 |
+
"model.layers.24.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 313 |
+
"model.layers.24.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 314 |
+
"model.layers.24.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 315 |
+
"model.layers.24.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 316 |
+
"model.layers.24.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 317 |
+
"model.layers.24.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 318 |
+
"model.layers.25.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 319 |
+
"model.layers.25.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 320 |
+
"model.layers.25.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 321 |
+
"model.layers.25.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 322 |
+
"model.layers.25.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 323 |
+
"model.layers.25.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 324 |
+
"model.layers.25.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 325 |
+
"model.layers.25.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 326 |
+
"model.layers.25.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 327 |
+
"model.layers.25.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 328 |
+
"model.layers.25.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 329 |
+
"model.layers.25.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 330 |
+
"model.layers.25.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 331 |
+
"model.layers.25.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 332 |
+
"model.layers.25.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 333 |
+
"model.layers.25.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 334 |
+
"model.layers.25.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 335 |
+
"model.layers.26.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 336 |
+
"model.layers.26.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 337 |
+
"model.layers.26.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 338 |
+
"model.layers.26.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 339 |
+
"model.layers.26.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 340 |
+
"model.layers.26.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 341 |
+
"model.layers.26.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 342 |
+
"model.layers.26.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 343 |
+
"model.layers.26.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 344 |
+
"model.layers.26.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 345 |
+
"model.layers.26.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 346 |
+
"model.layers.26.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 347 |
+
"model.layers.26.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 348 |
+
"model.layers.26.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 349 |
+
"model.layers.26.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 350 |
+
"model.layers.26.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 351 |
+
"model.layers.27.attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 352 |
+
"model.layers.27.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 353 |
+
"model.layers.27.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 354 |
+
"model.layers.27.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 355 |
+
"model.layers.27.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 356 |
+
"model.layers.27.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 357 |
+
"model.layers.27.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 358 |
+
"model.layers.27.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 359 |
+
"model.layers.27.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 360 |
+
"model.layers.27.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 361 |
+
"model.layers.27.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 362 |
+
"model.layers.27.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 363 |
+
"model.layers.27.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 364 |
+
"model.layers.27.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 365 |
+
"model.layers.27.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 366 |
+
"model.layers.27.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 367 |
+
"model.layers.27.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 368 |
+
"model.layers.28.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 369 |
+
"model.layers.28.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 370 |
+
"model.layers.28.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 371 |
+
"model.layers.28.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 372 |
+
"model.layers.28.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 373 |
+
"model.layers.28.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 374 |
+
"model.layers.28.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 375 |
+
"model.layers.28.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 376 |
+
"model.layers.28.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 377 |
+
"model.layers.28.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 378 |
+
"model.layers.28.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 379 |
+
"model.layers.28.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 380 |
+
"model.layers.28.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 381 |
+
"model.layers.28.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 382 |
+
"model.layers.28.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 383 |
+
"model.layers.28.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 384 |
+
"model.layers.29.attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 385 |
+
"model.layers.29.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 386 |
+
"model.layers.29.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 387 |
+
"model.layers.29.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 388 |
+
"model.layers.29.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 389 |
+
"model.layers.29.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 390 |
+
"model.layers.29.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 391 |
+
"model.layers.29.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 392 |
+
"model.layers.29.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 393 |
+
"model.layers.29.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 394 |
+
"model.layers.29.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 395 |
+
"model.layers.29.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 396 |
+
"model.layers.29.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 397 |
+
"model.layers.29.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 398 |
+
"model.layers.29.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 399 |
+
"model.layers.29.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 400 |
+
"model.layers.29.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 401 |
+
"model.layers.3.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 402 |
+
"model.layers.3.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 403 |
+
"model.layers.3.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 404 |
+
"model.layers.3.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 405 |
+
"model.layers.3.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 406 |
+
"model.layers.3.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 407 |
+
"model.layers.3.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 408 |
+
"model.layers.3.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 409 |
+
"model.layers.3.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 410 |
+
"model.layers.3.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 411 |
+
"model.layers.3.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 412 |
+
"model.layers.3.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 413 |
+
"model.layers.3.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 414 |
+
"model.layers.3.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 415 |
+
"model.layers.3.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 416 |
+
"model.layers.3.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 417 |
+
"model.layers.30.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 418 |
+
"model.layers.30.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 419 |
+
"model.layers.30.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 420 |
+
"model.layers.30.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 421 |
+
"model.layers.30.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 422 |
+
"model.layers.30.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 423 |
+
"model.layers.30.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 424 |
+
"model.layers.30.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 425 |
+
"model.layers.30.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 426 |
+
"model.layers.30.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 427 |
+
"model.layers.30.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 428 |
+
"model.layers.30.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 429 |
+
"model.layers.30.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 430 |
+
"model.layers.30.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 431 |
+
"model.layers.30.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 432 |
+
"model.layers.30.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 433 |
+
"model.layers.31.attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 434 |
+
"model.layers.31.attn.lambda_k1": "model-00002-of-00002.safetensors",
|
| 435 |
+
"model.layers.31.attn.lambda_k2": "model-00002-of-00002.safetensors",
|
| 436 |
+
"model.layers.31.attn.lambda_q1": "model-00002-of-00002.safetensors",
|
| 437 |
+
"model.layers.31.attn.lambda_q2": "model-00002-of-00002.safetensors",
|
| 438 |
+
"model.layers.31.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 439 |
+
"model.layers.31.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 440 |
+
"model.layers.31.attn.softmax_scaler": "model-00002-of-00002.safetensors",
|
| 441 |
+
"model.layers.31.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 442 |
+
"model.layers.31.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 443 |
+
"model.layers.31.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 444 |
+
"model.layers.31.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 445 |
+
"model.layers.31.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 446 |
+
"model.layers.31.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 447 |
+
"model.layers.31.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 448 |
+
"model.layers.31.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 449 |
+
"model.layers.31.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 450 |
+
"model.layers.31.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 451 |
+
"model.layers.31.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 452 |
+
"model.layers.31.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 453 |
+
"model.layers.31.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 454 |
+
"model.layers.31.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 455 |
+
"model.layers.32.attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 456 |
+
"model.layers.32.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 457 |
+
"model.layers.32.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 458 |
+
"model.layers.32.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 459 |
+
"model.layers.32.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 460 |
+
"model.layers.32.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 461 |
+
"model.layers.32.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 462 |
+
"model.layers.32.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 463 |
+
"model.layers.32.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 464 |
+
"model.layers.32.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 465 |
+
"model.layers.32.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 466 |
+
"model.layers.32.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 467 |
+
"model.layers.32.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 468 |
+
"model.layers.32.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 469 |
+
"model.layers.32.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 470 |
+
"model.layers.32.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 471 |
+
"model.layers.32.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 472 |
+
"model.layers.33.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 473 |
+
"model.layers.33.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 474 |
+
"model.layers.33.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 475 |
+
"model.layers.33.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 476 |
+
"model.layers.33.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 477 |
+
"model.layers.33.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 478 |
+
"model.layers.33.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 479 |
+
"model.layers.33.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 480 |
+
"model.layers.33.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 481 |
+
"model.layers.33.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 482 |
+
"model.layers.33.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 483 |
+
"model.layers.33.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 484 |
+
"model.layers.33.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 485 |
+
"model.layers.33.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 486 |
+
"model.layers.33.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 487 |
+
"model.layers.33.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 488 |
+
"model.layers.34.attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 489 |
+
"model.layers.34.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 490 |
+
"model.layers.34.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 491 |
+
"model.layers.34.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 492 |
+
"model.layers.34.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 493 |
+
"model.layers.34.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 494 |
+
"model.layers.34.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 495 |
+
"model.layers.34.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 496 |
+
"model.layers.34.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 497 |
+
"model.layers.34.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 498 |
+
"model.layers.34.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 499 |
+
"model.layers.34.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 500 |
+
"model.layers.34.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 501 |
+
"model.layers.34.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 502 |
+
"model.layers.34.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 503 |
+
"model.layers.34.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 504 |
+
"model.layers.34.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 505 |
+
"model.layers.35.attn.linear_qkv.weight": "model-00002-of-00002.safetensors",
|
| 506 |
+
"model.layers.35.attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 507 |
+
"model.layers.35.attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 508 |
+
"model.layers.35.input_norm.weight": "model-00002-of-00002.safetensors",
|
| 509 |
+
"model.layers.35.lin_attn.A_log": "model-00002-of-00002.safetensors",
|
| 510 |
+
"model.layers.35.lin_attn.dt_bias": "model-00002-of-00002.safetensors",
|
| 511 |
+
"model.layers.35.lin_attn.g_proj.weight": "model-00002-of-00002.safetensors",
|
| 512 |
+
"model.layers.35.lin_attn.in_proj.weight": "model-00002-of-00002.safetensors",
|
| 513 |
+
"model.layers.35.lin_attn.k_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 514 |
+
"model.layers.35.lin_attn.q_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 515 |
+
"model.layers.35.lin_attn.v_conv1d.weight": "model-00002-of-00002.safetensors",
|
| 516 |
+
"model.layers.35.lin_attn_group_norm.weight": "model-00002-of-00002.safetensors",
|
| 517 |
+
"model.layers.35.mixer_proj.weight": "model-00002-of-00002.safetensors",
|
| 518 |
+
"model.layers.35.mlp.fc_1.weight": "model-00002-of-00002.safetensors",
|
| 519 |
+
"model.layers.35.mlp.fc_2.weight": "model-00002-of-00002.safetensors",
|
| 520 |
+
"model.layers.35.postmixer_norm.weight": "model-00002-of-00002.safetensors",
|
| 521 |
+
"model.layers.4.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 522 |
+
"model.layers.4.attn.lambda_k1": "model-00001-of-00002.safetensors",
|
| 523 |
+
"model.layers.4.attn.lambda_k2": "model-00001-of-00002.safetensors",
|
| 524 |
+
"model.layers.4.attn.lambda_q1": "model-00001-of-00002.safetensors",
|
| 525 |
+
"model.layers.4.attn.lambda_q2": "model-00001-of-00002.safetensors",
|
| 526 |
+
"model.layers.4.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 527 |
+
"model.layers.4.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 528 |
+
"model.layers.4.attn.softmax_scaler": "model-00001-of-00002.safetensors",
|
| 529 |
+
"model.layers.4.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 530 |
+
"model.layers.4.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 531 |
+
"model.layers.4.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 532 |
+
"model.layers.4.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 533 |
+
"model.layers.4.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 534 |
+
"model.layers.4.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 535 |
+
"model.layers.4.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 536 |
+
"model.layers.4.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 537 |
+
"model.layers.4.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 538 |
+
"model.layers.4.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 539 |
+
"model.layers.4.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 540 |
+
"model.layers.4.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 541 |
+
"model.layers.4.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 542 |
+
"model.layers.4.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 543 |
+
"model.layers.5.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 544 |
+
"model.layers.5.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 545 |
+
"model.layers.5.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 546 |
+
"model.layers.5.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 547 |
+
"model.layers.5.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 548 |
+
"model.layers.5.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 549 |
+
"model.layers.5.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 550 |
+
"model.layers.5.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 551 |
+
"model.layers.5.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 552 |
+
"model.layers.5.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 553 |
+
"model.layers.5.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 554 |
+
"model.layers.5.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 555 |
+
"model.layers.5.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 556 |
+
"model.layers.5.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 557 |
+
"model.layers.5.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 558 |
+
"model.layers.5.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 559 |
+
"model.layers.5.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 560 |
+
"model.layers.6.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 561 |
+
"model.layers.6.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 562 |
+
"model.layers.6.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 563 |
+
"model.layers.6.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 564 |
+
"model.layers.6.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 565 |
+
"model.layers.6.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 566 |
+
"model.layers.6.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 567 |
+
"model.layers.6.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 568 |
+
"model.layers.6.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 569 |
+
"model.layers.6.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 570 |
+
"model.layers.6.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 571 |
+
"model.layers.6.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 572 |
+
"model.layers.6.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 573 |
+
"model.layers.6.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 574 |
+
"model.layers.6.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 575 |
+
"model.layers.6.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 576 |
+
"model.layers.7.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 577 |
+
"model.layers.7.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 578 |
+
"model.layers.7.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 579 |
+
"model.layers.7.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 580 |
+
"model.layers.7.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 581 |
+
"model.layers.7.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 582 |
+
"model.layers.7.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 583 |
+
"model.layers.7.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 584 |
+
"model.layers.7.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 585 |
+
"model.layers.7.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 586 |
+
"model.layers.7.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 587 |
+
"model.layers.7.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 588 |
+
"model.layers.7.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 589 |
+
"model.layers.7.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 590 |
+
"model.layers.7.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 591 |
+
"model.layers.7.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 592 |
+
"model.layers.7.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 593 |
+
"model.layers.8.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 594 |
+
"model.layers.8.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 595 |
+
"model.layers.8.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 596 |
+
"model.layers.8.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 597 |
+
"model.layers.8.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 598 |
+
"model.layers.8.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 599 |
+
"model.layers.8.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 600 |
+
"model.layers.8.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 601 |
+
"model.layers.8.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 602 |
+
"model.layers.8.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 603 |
+
"model.layers.8.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 604 |
+
"model.layers.8.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 605 |
+
"model.layers.8.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 606 |
+
"model.layers.8.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 607 |
+
"model.layers.8.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 608 |
+
"model.layers.8.postmixer_norm.weight": "model-00001-of-00002.safetensors",
|
| 609 |
+
"model.layers.9.attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 610 |
+
"model.layers.9.attn.linear_qkv.weight": "model-00001-of-00002.safetensors",
|
| 611 |
+
"model.layers.9.attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 612 |
+
"model.layers.9.attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 613 |
+
"model.layers.9.input_norm.weight": "model-00001-of-00002.safetensors",
|
| 614 |
+
"model.layers.9.lin_attn.A_log": "model-00001-of-00002.safetensors",
|
| 615 |
+
"model.layers.9.lin_attn.dt_bias": "model-00001-of-00002.safetensors",
|
| 616 |
+
"model.layers.9.lin_attn.g_proj.weight": "model-00001-of-00002.safetensors",
|
| 617 |
+
"model.layers.9.lin_attn.in_proj.weight": "model-00001-of-00002.safetensors",
|
| 618 |
+
"model.layers.9.lin_attn.k_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 619 |
+
"model.layers.9.lin_attn.q_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 620 |
+
"model.layers.9.lin_attn.v_conv1d.weight": "model-00001-of-00002.safetensors",
|
| 621 |
+
"model.layers.9.lin_attn_group_norm.weight": "model-00001-of-00002.safetensors",
|
| 622 |
+
"model.layers.9.mixer_proj.weight": "model-00001-of-00002.safetensors",
|
| 623 |
+
"model.layers.9.mlp.fc_1.weight": "model-00001-of-00002.safetensors",
|
| 624 |
+
"model.layers.9.mlp.fc_2.weight": "model-00001-of-00002.safetensors",
|
| 625 |
+
"model.layers.9.postmixer_norm.weight": "model-00001-of-00002.safetensors"
|
| 626 |
+
}
|
| 627 |
+
}
|
modeling_dragon.py
ADDED
|
@@ -0,0 +1,1280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
"""PyTorch Dragon model."""
|
| 3 |
+
|
| 4 |
+
from typing import Any, Dict, Optional, Tuple, Union
|
| 5 |
+
from dataclasses import dataclass
|
| 6 |
+
import inspect
|
| 7 |
+
|
| 8 |
+
import math
|
| 9 |
+
from einops import rearrange
|
| 10 |
+
import torch
|
| 11 |
+
import torch.nn.functional as F
|
| 12 |
+
from torch import nn
|
| 13 |
+
|
| 14 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 15 |
+
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 16 |
+
from transformers.cache_utils import DynamicCache
|
| 17 |
+
from transformers.generation import GenerationMixin
|
| 18 |
+
from transformers.utils import ModelOutput, logging
|
| 19 |
+
|
| 20 |
+
from .configuration_dragon import DragonConfig
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
ATTN_IMPL = "eager"
|
| 25 |
+
try:
|
| 26 |
+
from flash_attn import flash_attn_func # FA2
|
| 27 |
+
ATTN_IMPL = "fa2"
|
| 28 |
+
except ImportError:
|
| 29 |
+
try:
|
| 30 |
+
import flash_attn_interface # FA3
|
| 31 |
+
flash_attn_func = flash_attn_interface.flash_attn_func
|
| 32 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 33 |
+
if not _flash_supports_window_size:
|
| 34 |
+
raise ImportError("flash_attn_func does not support window_size parameter. Please update to more recent flash_attn version")
|
| 35 |
+
ATTN_IMPL = "fa3"
|
| 36 |
+
except ImportError:
|
| 37 |
+
logger.warning_once(
|
| 38 |
+
"Flash attention is not installed, using eager attention implementation. "
|
| 39 |
+
"For better performance, consider installing flash_attn."
|
| 40 |
+
)
|
| 41 |
+
print(f"Using attention implementation: {ATTN_IMPL}")
|
| 42 |
+
|
| 43 |
+
DIFF_ATTN_IMPL = None
|
| 44 |
+
try:
|
| 45 |
+
import flex_head_fa
|
| 46 |
+
DIFF_ATTN_IMPL = "flex_head"
|
| 47 |
+
except ImportError:
|
| 48 |
+
DIFF_ATTN_IMPL = ATTN_IMPL # if we don't have flex_head_fa, fallback to the best attention impl we have
|
| 49 |
+
print(f"Using differential attention implementation: {DIFF_ATTN_IMPL}")
|
| 50 |
+
|
| 51 |
+
# Gated DeltaNet
|
| 52 |
+
try:
|
| 53 |
+
from fla.ops.gated_delta_rule import chunk_gated_delta_rule, fused_recurrent_gated_delta_rule
|
| 54 |
+
except ImportError:
|
| 55 |
+
logger.warning_once("Falling back to Torch implementation for Gated DeltaNet as flash-linear-attention module was not found.")
|
| 56 |
+
chunk_gated_delta_rule, fused_recurrent_gated_delta_rule = None, None
|
| 57 |
+
|
| 58 |
+
# 1D short convolution
|
| 59 |
+
try:
|
| 60 |
+
from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
|
| 61 |
+
except ImportError:
|
| 62 |
+
logger.warning_once("Falling back to Torch implementation for the short convolution as causal-conv1d module was not found.")
|
| 63 |
+
causal_conv1d_fn, causal_conv1d_update = None, None
|
| 64 |
+
|
| 65 |
+
class DragonHeadWiseRMSNorm(nn.Module):
|
| 66 |
+
def __init__(self, n_heads, d_head, eps=1e-6):
|
| 67 |
+
super().__init__()
|
| 68 |
+
self.rms = nn.RMSNorm(d_head, eps=eps, elementwise_affine=False)
|
| 69 |
+
self.weight = nn.Parameter(torch.ones(n_heads, d_head))
|
| 70 |
+
|
| 71 |
+
def forward(self, hidden_states):
|
| 72 |
+
B, L, H, D = hidden_states.shape
|
| 73 |
+
y = self.rms(hidden_states) * self.weight.view(1, 1, H, D)
|
| 74 |
+
return y.view(B, L, H, D)
|
| 75 |
+
|
| 76 |
+
class DragonRMSNorm(nn.RMSNorm):
|
| 77 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 78 |
+
"""
|
| 79 |
+
DragonRMSNorm is equivalent to RMSNorm
|
| 80 |
+
"""
|
| 81 |
+
super().__init__(normalized_shape=hidden_size, eps=eps)
|
| 82 |
+
|
| 83 |
+
class _ScaleFB(torch.autograd.Function):
|
| 84 |
+
@staticmethod
|
| 85 |
+
def forward(ctx, x, alpha_fwd: torch.Tensor, alpha_bwd: torch.Tensor):
|
| 86 |
+
ctx.save_for_backward(alpha_bwd)
|
| 87 |
+
return x * alpha_fwd
|
| 88 |
+
|
| 89 |
+
@staticmethod
|
| 90 |
+
def backward(ctx, grad_output):
|
| 91 |
+
(alpha_bwd,) = ctx.saved_tensors
|
| 92 |
+
return grad_output * alpha_bwd, None, None
|
| 93 |
+
|
| 94 |
+
class _ScaledLinearFB(torch.autograd.Function):
|
| 95 |
+
@staticmethod
|
| 96 |
+
def forward(ctx, x, weight, bias, alpha_fwd, alpha_bwd_x, alpha_bwd_w):
|
| 97 |
+
ctx.save_for_backward(x, weight, bias)
|
| 98 |
+
ctx.alpha_bwd_x = alpha_bwd_x
|
| 99 |
+
ctx.alpha_bwd_w = alpha_bwd_w
|
| 100 |
+
return F.linear(x, weight, bias) * alpha_fwd
|
| 101 |
+
|
| 102 |
+
@staticmethod
|
| 103 |
+
def backward(ctx, grad_out):
|
| 104 |
+
x, weight, bias = ctx.saved_tensors
|
| 105 |
+
# -------- grads ----------
|
| 106 |
+
grad_x = torch.matmul(grad_out * ctx.alpha_bwd_x, weight)
|
| 107 |
+
|
| 108 |
+
go_flat = (grad_out * ctx.alpha_bwd_w).reshape(-1, grad_out.shape[-1])
|
| 109 |
+
x_flat = x.reshape(-1, x.shape[-1])
|
| 110 |
+
grad_weight = go_flat.t() @ x_flat
|
| 111 |
+
grad_bias = go_flat.sum(0) if bias is not None else None
|
| 112 |
+
|
| 113 |
+
return grad_x, grad_weight, grad_bias, None, None, None
|
| 114 |
+
|
| 115 |
+
class DragonLinear(nn.Linear):
|
| 116 |
+
"""Linear layer with different forward/backward scalings."""
|
| 117 |
+
def __init__(self, config: DragonConfig, in_features, out_features, bias=False, alpha_fwd=None, alpha_bwd=None):
|
| 118 |
+
super().__init__(in_features, out_features, bias)
|
| 119 |
+
|
| 120 |
+
if alpha_fwd is None:
|
| 121 |
+
alpha_fwd = 1.0 / math.sqrt(in_features)
|
| 122 |
+
|
| 123 |
+
if not config.use_uscaling:
|
| 124 |
+
alpha_fwd, alpha_bwd = 1, 1
|
| 125 |
+
|
| 126 |
+
self.register_buffer("alpha_fwd", torch.tensor(float(alpha_fwd)), persistent=False)
|
| 127 |
+
self.register_buffer("alpha_bwd", torch.tensor(float(alpha_bwd if alpha_bwd is not None else alpha_fwd)), persistent=False)
|
| 128 |
+
|
| 129 |
+
def forward(self, x):
|
| 130 |
+
return _ScaledLinearFB.apply(x, self.weight, self.bias, self.alpha_fwd, self.alpha_bwd, self.alpha_bwd)
|
| 131 |
+
|
| 132 |
+
# heavily adapted from flash-linear-attention
|
| 133 |
+
def prepare_lens(cu_seqlens: torch.LongTensor) -> torch.LongTensor:
|
| 134 |
+
return cu_seqlens[1:] - cu_seqlens[:-1]
|
| 135 |
+
|
| 136 |
+
def prepare_position_ids(cu_seqlens: torch.LongTensor) -> torch.LongTensor:
|
| 137 |
+
return torch.cat([
|
| 138 |
+
torch.arange(n, dtype=cu_seqlens.dtype, device=cu_seqlens.device)
|
| 139 |
+
for n in prepare_lens(cu_seqlens).unbind()
|
| 140 |
+
])
|
| 141 |
+
|
| 142 |
+
def prepare_sequence_ids(cu_seqlens: torch.LongTensor) -> torch.LongTensor:
|
| 143 |
+
return prepare_position_ids(cu_seqlens).eq(0).cumsum(0) - 1
|
| 144 |
+
|
| 145 |
+
class DragonConv1D(nn.Conv1d):
|
| 146 |
+
"""Wrapper around nn.Conv1d (for definition) and causal_conv1d (for forward)"""
|
| 147 |
+
def __init__(
|
| 148 |
+
self,
|
| 149 |
+
hidden_size: int,
|
| 150 |
+
kernel_size: int,
|
| 151 |
+
bias: bool = False,
|
| 152 |
+
device: Optional[torch.device] = None,
|
| 153 |
+
dtype: Optional[torch.dtype] = None,
|
| 154 |
+
):
|
| 155 |
+
super().__init__(
|
| 156 |
+
in_channels=hidden_size,
|
| 157 |
+
out_channels=hidden_size,
|
| 158 |
+
kernel_size=kernel_size,
|
| 159 |
+
groups=hidden_size,
|
| 160 |
+
bias=bias,
|
| 161 |
+
padding=kernel_size - 1,
|
| 162 |
+
device=device,
|
| 163 |
+
dtype=dtype,
|
| 164 |
+
)
|
| 165 |
+
self.hidden_size = hidden_size
|
| 166 |
+
|
| 167 |
+
def forward(
|
| 168 |
+
self,
|
| 169 |
+
x: torch.Tensor,
|
| 170 |
+
mask: Optional[torch.Tensor] = None,
|
| 171 |
+
cache: Optional[torch.Tensor] = None,
|
| 172 |
+
output_final_state: bool = False,
|
| 173 |
+
**kwargs,
|
| 174 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
| 175 |
+
"""
|
| 176 |
+
Args:
|
| 177 |
+
x (`torch.Tensor`):
|
| 178 |
+
Tensor of shape `[B, T, D]`.
|
| 179 |
+
If `seq_idx` is provided, `B` must be 1.
|
| 180 |
+
mask (`Optional[torch.Tensor]`):
|
| 181 |
+
Attention mask dealing with padded positions.
|
| 182 |
+
cache (`Optional[torch.Tensor]`):
|
| 183 |
+
Previous cache tensor of shape `[N, D, W]`, where `W` is the kernel size.
|
| 184 |
+
If provided, the cache is updated **inplace**.
|
| 185 |
+
output_final_state (Optional[bool]):
|
| 186 |
+
Whether to output the final state of shape `[N, D, W]`. Default: `False`.
|
| 187 |
+
|
| 188 |
+
Returns:
|
| 189 |
+
Tensor of shape `[B, T, D]`.
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
B, T, D, W = *x.shape, self.kernel_size[0]
|
| 193 |
+
N = B
|
| 194 |
+
if mask is not None:
|
| 195 |
+
x = x.mul_(mask.unsqueeze(-1))
|
| 196 |
+
if output_final_state and cache is None:
|
| 197 |
+
cache = x.new_zeros(N, D, W)
|
| 198 |
+
# during the decoding phase, we assume the batch is composed of sequences of length 1
|
| 199 |
+
if cache is not None and T == 1:
|
| 200 |
+
return self.step(x, cache)
|
| 201 |
+
|
| 202 |
+
if cache is not None:
|
| 203 |
+
cache[:, :, -min(W, T):].copy_(rearrange(x[..., -min(W, T):, :], 'n w d -> n d w'))
|
| 204 |
+
|
| 205 |
+
x = rearrange(x, 'b t d -> b d t')
|
| 206 |
+
if causal_conv1d_fn is not None:
|
| 207 |
+
# Sequence index for each token. Used for varlen.
|
| 208 |
+
# Suppose a batch consists of two sequences with lengths 3 and 4,
|
| 209 |
+
# seq_idx=[0, 0, 0, 1, 1, 1, 1] for this batch.
|
| 210 |
+
# NOTE: No need to provide this arg if `cu_seqlens` is passed.
|
| 211 |
+
# This arg is just for BC, and will be removed in the future.
|
| 212 |
+
# [B, T]
|
| 213 |
+
seq_idx = kwargs.get('seq_idx', None)
|
| 214 |
+
x = causal_conv1d_fn(
|
| 215 |
+
x=x.contiguous(),
|
| 216 |
+
weight=rearrange(self.weight, "d 1 w -> d w"),
|
| 217 |
+
bias=self.bias,
|
| 218 |
+
activation="silu",
|
| 219 |
+
seq_idx=seq_idx,
|
| 220 |
+
)
|
| 221 |
+
else:
|
| 222 |
+
x = self._conv_forward(x, self.weight, self.bias)[..., :x.shape[-1]]
|
| 223 |
+
x = F.silu(x)
|
| 224 |
+
return rearrange(x, "b d t -> b t d"), cache
|
| 225 |
+
|
| 226 |
+
def step(
|
| 227 |
+
self,
|
| 228 |
+
x: torch.Tensor,
|
| 229 |
+
cache: torch.Tensor,
|
| 230 |
+
cu_seqlens: Optional[torch.LongTensor] = None
|
| 231 |
+
):
|
| 232 |
+
shape = x.shape
|
| 233 |
+
x = x.squeeze(0) if cu_seqlens is not None else x.squeeze(1)
|
| 234 |
+
if causal_conv1d_update is not None:
|
| 235 |
+
x = causal_conv1d_update(
|
| 236 |
+
x=x,
|
| 237 |
+
conv_state=cache,
|
| 238 |
+
weight=rearrange(self.weight, "d 1 w -> d w"),
|
| 239 |
+
bias=self.bias,
|
| 240 |
+
activation="silu",
|
| 241 |
+
)
|
| 242 |
+
else:
|
| 243 |
+
# we follow the fast mode that updates the cache in-place
|
| 244 |
+
cache.copy_(cache.roll(shifts=-1, dims=-1))
|
| 245 |
+
cache[:, :, -1] = x
|
| 246 |
+
x = torch.sum(cache * rearrange(self.weight, "d 1 w -> d w"), dim=-1)
|
| 247 |
+
if self.bias is not None:
|
| 248 |
+
x = x + self.bias
|
| 249 |
+
x = F.silu(x)
|
| 250 |
+
return x.view(shape), cache
|
| 251 |
+
|
| 252 |
+
class HybridDragonAttentionDynamicCache(DynamicCache):
|
| 253 |
+
"""
|
| 254 |
+
A dynamic cache that handle both the attention cache (which has a seq_len dimension) and the GDN cache
|
| 255 |
+
(which has a constant shape regardless of seq_len).
|
| 256 |
+
This cache has two sets of lists of tensors: `key_cache` and `value_cache` for attention cache and `conv_states`
|
| 257 |
+
and `ssm_states` for GDN cache. The expected shape for each tensor is as follows:
|
| 258 |
+
For each layers, `key_cache` and `value_cache` have a shape of `(batch_size, num_heads, seq_len, head_dim)`,
|
| 259 |
+
if local attention produce k and v
|
| 260 |
+
while `conv_states` represents the convolution state and has a shape of `(batch_size, d_inner, d_conv)`,
|
| 261 |
+
and `ssm_states` represents the ssm state and has a shape of `(batch_size, d_inner, d_state)`.
|
| 262 |
+
"""
|
| 263 |
+
def __init__(self, config: DragonConfig, dtype=torch.bfloat16):
|
| 264 |
+
super().__init__()
|
| 265 |
+
self.config = config
|
| 266 |
+
self.dtype = dtype
|
| 267 |
+
self.q_conv_states = []
|
| 268 |
+
self.k_conv_states = []
|
| 269 |
+
self.v_conv_states = []
|
| 270 |
+
self.ssm_states = []
|
| 271 |
+
self._key_cache = {}
|
| 272 |
+
self._value_cache = {}
|
| 273 |
+
|
| 274 |
+
for idx, layer_type in enumerate(config.layers_config):
|
| 275 |
+
if layer_type in ['l', 'd']:
|
| 276 |
+
self._key_cache[idx] = None
|
| 277 |
+
self._value_cache[idx] = None
|
| 278 |
+
|
| 279 |
+
self.q_conv_states.append(None)
|
| 280 |
+
self.k_conv_states.append(None)
|
| 281 |
+
self.v_conv_states.append(None)
|
| 282 |
+
self.ssm_states.append(None)
|
| 283 |
+
|
| 284 |
+
self.window_size = config.sliding_window_size
|
| 285 |
+
self.layers_config = config.layers_config
|
| 286 |
+
self.past_length = [0 for _ in range(len(config.layers_config))]
|
| 287 |
+
|
| 288 |
+
def update(
|
| 289 |
+
self,
|
| 290 |
+
k: torch.Tensor, # (B, L, h, D)
|
| 291 |
+
v: torch.Tensor, # (B, L, h, D)
|
| 292 |
+
layer_idx: int,
|
| 293 |
+
):
|
| 294 |
+
added_len = k.size(1)
|
| 295 |
+
# grab cache
|
| 296 |
+
k_cache = self._key_cache[layer_idx]
|
| 297 |
+
v_cache = self._value_cache[layer_idx]
|
| 298 |
+
if k_cache is None:
|
| 299 |
+
k_cache = k
|
| 300 |
+
v_cache = v
|
| 301 |
+
else:
|
| 302 |
+
k_cache = torch.cat([k_cache, k], dim=1)
|
| 303 |
+
v_cache = torch.cat([v_cache, v], dim=1)
|
| 304 |
+
# save cache
|
| 305 |
+
self._key_cache[layer_idx] = k_cache
|
| 306 |
+
self._value_cache[layer_idx] = v_cache
|
| 307 |
+
# update cache length
|
| 308 |
+
self.past_length[layer_idx] += added_len
|
| 309 |
+
return k_cache, v_cache
|
| 310 |
+
|
| 311 |
+
def trim(self, layer_idx: int):
|
| 312 |
+
# discard old keys/values
|
| 313 |
+
window_size = min(self.window_size, self.config.slw_wsize) if self.config.slw_wsize > 0 else self.window_size
|
| 314 |
+
if self.layers_config[layer_idx] == 'l':
|
| 315 |
+
if self._key_cache[layer_idx].size(1) > window_size:
|
| 316 |
+
self._key_cache[layer_idx] = self._key_cache[layer_idx][:, -window_size:, ...].contiguous()
|
| 317 |
+
self._value_cache[layer_idx] = self._value_cache[layer_idx][:, -window_size:, ...].contiguous()
|
| 318 |
+
|
| 319 |
+
def update_ssm_cache(
|
| 320 |
+
self,
|
| 321 |
+
q_conv_states: torch.Tensor,
|
| 322 |
+
k_conv_states: torch.Tensor,
|
| 323 |
+
v_conv_states: torch.Tensor,
|
| 324 |
+
ssm_states: torch.Tensor,
|
| 325 |
+
layer_idx: int,
|
| 326 |
+
) -> None:
|
| 327 |
+
# Update the SSM cache
|
| 328 |
+
self.q_conv_states[layer_idx] = q_conv_states
|
| 329 |
+
self.k_conv_states[layer_idx] = k_conv_states
|
| 330 |
+
self.v_conv_states[layer_idx] = v_conv_states
|
| 331 |
+
self.ssm_states[layer_idx] = ssm_states
|
| 332 |
+
|
| 333 |
+
def get_ssm_cache(self, layer_idx: int) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 334 |
+
# Get the SSM cache for the specified layer
|
| 335 |
+
return (
|
| 336 |
+
self.q_conv_states[layer_idx],
|
| 337 |
+
self.k_conv_states[layer_idx],
|
| 338 |
+
self.v_conv_states[layer_idx],
|
| 339 |
+
self.ssm_states[layer_idx],
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
def get_total_seen(self, layer_idx: int) -> int:
|
| 343 |
+
return self.past_length[layer_idx]
|
| 344 |
+
|
| 345 |
+
def to_legacy_cache(self) -> Tuple[Tuple[torch.Tensor], Tuple[torch.Tensor]]:
|
| 346 |
+
raise NotImplementedError("HybridDragonAttentionDynamicCache does not have a legacy cache equivalent.")
|
| 347 |
+
|
| 348 |
+
@classmethod
|
| 349 |
+
def from_legacy_cache(cls, cache_params: Optional[Tuple[Tuple[torch.FloatTensor]]] = None) -> "DynamicCache":
|
| 350 |
+
raise NotImplementedError("HybridDragonAttentionDynamicCache does not have a legacy cache equivalent.")
|
| 351 |
+
|
| 352 |
+
class DragonRotaryEmbedding(torch.nn.Module):
|
| 353 |
+
def __init__(self, config: DragonConfig, head_dim: int):
|
| 354 |
+
super().__init__()
|
| 355 |
+
self.config = config
|
| 356 |
+
|
| 357 |
+
inv_freq = 1.0 / (config.rope_theta ** (torch.arange(0, head_dim, 2).float() / head_dim))
|
| 358 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 359 |
+
|
| 360 |
+
self.seq_len_cached = 0
|
| 361 |
+
self.cos_cached = None
|
| 362 |
+
self.sin_cached = None
|
| 363 |
+
|
| 364 |
+
def forward(self, x, position_ids):
|
| 365 |
+
max_pos = self.config.max_position_embeddings
|
| 366 |
+
if max_pos > self.seq_len_cached:
|
| 367 |
+
self.seq_len_cached = max(2 * max_pos, 16)
|
| 368 |
+
t = torch.arange(self.seq_len_cached, device=x.device, dtype=self.inv_freq.dtype)
|
| 369 |
+
freqs = torch.outer(t, self.inv_freq)
|
| 370 |
+
self.cos_cached = freqs.cos().to(torch.bfloat16)
|
| 371 |
+
self.sin_cached = freqs.sin().to(torch.bfloat16)
|
| 372 |
+
|
| 373 |
+
cos = self.cos_cached[position_ids] # (B, T, head_dim/2)
|
| 374 |
+
sin = self.sin_cached[position_ids]
|
| 375 |
+
cos = cos[..., None, :] # (B, T, 1, head_dim/2), broadcasts over heads
|
| 376 |
+
sin = sin[..., None, :]
|
| 377 |
+
|
| 378 |
+
return cos, sin
|
| 379 |
+
|
| 380 |
+
def apply_rotary_emb(x, cos, sin):
|
| 381 |
+
assert x.ndim == 4 # multihead attention
|
| 382 |
+
d = x.shape[3]//2 # head dim
|
| 383 |
+
x1 = x[..., :d]
|
| 384 |
+
x2 = x[..., d:]
|
| 385 |
+
y1 = x1 * cos + x2 * sin
|
| 386 |
+
y2 = x1 * (-sin) + x2 * cos
|
| 387 |
+
return torch.cat([y1, y2], 3).type_as(x)
|
| 388 |
+
|
| 389 |
+
# heavily adapated from Gemma3
|
| 390 |
+
def eager_attention_forward(
|
| 391 |
+
module: nn.Module, # TODO: remove module
|
| 392 |
+
query: torch.Tensor,
|
| 393 |
+
key: torch.Tensor,
|
| 394 |
+
value: torch.Tensor,
|
| 395 |
+
causal: bool = True,
|
| 396 |
+
window_size: Optional[Tuple[int, int]] = None,
|
| 397 |
+
softcap: Optional[float] = None,
|
| 398 |
+
softmax_scale: Optional[float] = None,
|
| 399 |
+
**kwargs,
|
| 400 |
+
) -> torch.Tensor:
|
| 401 |
+
if softmax_scale is None:
|
| 402 |
+
softmax_scale = module.head_dim**-0.5
|
| 403 |
+
|
| 404 |
+
query = query.transpose(1, 2) # (B, H, L, D)
|
| 405 |
+
key = key.transpose(1, 2) # (B, H, L, D)
|
| 406 |
+
value = value.transpose(1, 2) # (B, H, L, D)
|
| 407 |
+
|
| 408 |
+
key = key.repeat_interleave(module.num_heads // module.num_key_value_heads, dim=1)
|
| 409 |
+
value = value.repeat_interleave(module.num_heads // module.num_key_value_heads, dim=1)
|
| 410 |
+
|
| 411 |
+
attn_weights = torch.matmul(query, key.transpose(2, 3)) * softmax_scale
|
| 412 |
+
|
| 413 |
+
if softcap is not None:
|
| 414 |
+
attn_weights = torch.tanh(attn_weights / softcap) * softcap
|
| 415 |
+
|
| 416 |
+
if causal or (window_size is not None):
|
| 417 |
+
Lq = query.size(2)
|
| 418 |
+
Lk = key.size(2)
|
| 419 |
+
past = max(Lk - Lq, 0)
|
| 420 |
+
i = torch.arange(Lq, device=attn_weights.device).unsqueeze(1) + past # [Lq,1]
|
| 421 |
+
j = torch.arange(Lk, device=attn_weights.device).unsqueeze(0) # [1,Lk]
|
| 422 |
+
|
| 423 |
+
allowed = torch.ones((Lq, Lk), dtype=torch.bool, device=attn_weights.device)
|
| 424 |
+
if causal:
|
| 425 |
+
allowed &= (j <= i) # prevent attending to future positions
|
| 426 |
+
if window_size is not None:
|
| 427 |
+
w_left, w_right = window_size
|
| 428 |
+
# treat None as "no limit" on that side
|
| 429 |
+
if w_left is None:
|
| 430 |
+
w_left = Lk
|
| 431 |
+
if w_right is None:
|
| 432 |
+
w_right = Lk
|
| 433 |
+
allowed &= (j >= i - w_left) & (j <= i + w_right)
|
| 434 |
+
# broadcast [Lq,Lk] -> [B, H, Lq, Lk]
|
| 435 |
+
attn_weights = attn_weights.masked_fill(~allowed, float("-inf"))
|
| 436 |
+
|
| 437 |
+
# upcast attention to fp32
|
| 438 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 439 |
+
attn_output = torch.matmul(attn_weights, value)
|
| 440 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 441 |
+
return attn_output
|
| 442 |
+
|
| 443 |
+
def get_query_key_value_tensors(module: nn.Module, hidden_states: torch.Tensor):
|
| 444 |
+
"""
|
| 445 |
+
Derives `query`, `key` and `value` tensors from `hidden_states`.
|
| 446 |
+
"""
|
| 447 |
+
# (B, L, D) -> (B, L, ng * (np/ng + 2) * hn))
|
| 448 |
+
mixed_qkv = module.linear_qkv(hidden_states)
|
| 449 |
+
|
| 450 |
+
if getattr(module, "reuse_kv", False):
|
| 451 |
+
# reshape to [..., num_query_groups, heads_per_group * d]
|
| 452 |
+
q_dim = (module.num_heads // module.num_key_value_heads) * module.head_dim
|
| 453 |
+
new_shape = mixed_qkv.size()[:-1] + (module.num_key_value_heads, q_dim)
|
| 454 |
+
query = mixed_qkv.view(*new_shape)
|
| 455 |
+
# final shape (B, L, H, d)
|
| 456 |
+
query = query.reshape(query.size(0), query.size(1), -1, module.head_dim)
|
| 457 |
+
|
| 458 |
+
return query
|
| 459 |
+
|
| 460 |
+
# (B, L, hp) -> (B, L, ng, (np/ng + 2) * hn)
|
| 461 |
+
new_tensor_shape = mixed_qkv.size()[:-1] + (
|
| 462 |
+
module.num_key_value_heads,
|
| 463 |
+
(
|
| 464 |
+
(module.num_heads // module.num_key_value_heads + 2)
|
| 465 |
+
* module.head_dim
|
| 466 |
+
),
|
| 467 |
+
)
|
| 468 |
+
mixed_qkv = mixed_qkv.view(*new_tensor_shape)
|
| 469 |
+
|
| 470 |
+
split_arg_list = [
|
| 471 |
+
(
|
| 472 |
+
module.num_heads
|
| 473 |
+
// module.num_key_value_heads
|
| 474 |
+
* module.head_dim
|
| 475 |
+
),
|
| 476 |
+
module.head_dim,
|
| 477 |
+
module.head_dim,
|
| 478 |
+
]
|
| 479 |
+
|
| 480 |
+
# [B, L, ng, (np/ng + 2) * hn] -> [B, L, ng, np/ng * hn], [B, L, ng, hn], [B, L, ng, hn]
|
| 481 |
+
(query, key, value) = torch.split(mixed_qkv, split_arg_list, dim=3)
|
| 482 |
+
|
| 483 |
+
# [B, L, ng, np/ng * hn] -> [B, L, np, hn]
|
| 484 |
+
query = query.reshape(query.size(0), query.size(1), -1, module.head_dim)
|
| 485 |
+
|
| 486 |
+
return query, key, value
|
| 487 |
+
|
| 488 |
+
class DragonAttention(nn.Module):
|
| 489 |
+
"""
|
| 490 |
+
Multi-headed attention from 'Attention Is All You Need' paper.
|
| 491 |
+
Modified to use sliding window attention: Longformer and "Generating Long Sequences with Sparse Transformers".
|
| 492 |
+
Doesn't include output projection: output is (B, L, H, D).
|
| 493 |
+
"""
|
| 494 |
+
|
| 495 |
+
def __init__(self, config: DragonConfig, reuse_kv: bool, layer_idx: Optional[int], **kwargs):
|
| 496 |
+
super().__init__()
|
| 497 |
+
self.config = config
|
| 498 |
+
self.layer_idx = layer_idx
|
| 499 |
+
if layer_idx is None:
|
| 500 |
+
logger.warning_once(
|
| 501 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 502 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 503 |
+
"when creating this class."
|
| 504 |
+
)
|
| 505 |
+
self.num_heads = config.num_attention_heads
|
| 506 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 507 |
+
self.hidden_size = config.hidden_size
|
| 508 |
+
self.projection_dim = config.hidden_size * config.expand_factor
|
| 509 |
+
self.head_dim = self.projection_dim // self.num_heads
|
| 510 |
+
self.rope_theta = config.rope_theta
|
| 511 |
+
self.qk_norm = config.qk_norm
|
| 512 |
+
self.window_size = config.sliding_window_size
|
| 513 |
+
self.reuse_kv = reuse_kv
|
| 514 |
+
|
| 515 |
+
projection_dim = self.head_dim * (self.num_heads + 2 * (0 if reuse_kv else self.num_key_value_heads))
|
| 516 |
+
self.linear_qkv = DragonLinear(config, config.hidden_size, projection_dim, bias=False)
|
| 517 |
+
|
| 518 |
+
if self.qk_norm:
|
| 519 |
+
self.q_norm = DragonRMSNorm(self.head_dim, eps=config.norm_epsilon)
|
| 520 |
+
if not reuse_kv:
|
| 521 |
+
self.k_norm = DragonRMSNorm(self.head_dim, eps=config.norm_epsilon)
|
| 522 |
+
|
| 523 |
+
def forward(
|
| 524 |
+
self,
|
| 525 |
+
hidden_states: torch.Tensor,
|
| 526 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 527 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 528 |
+
cache_params: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 529 |
+
key_value_last_layer: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
|
| 530 |
+
**kwargs,
|
| 531 |
+
):
|
| 532 |
+
# Q, K, V projections.
|
| 533 |
+
if not self.reuse_kv:
|
| 534 |
+
query_states, key_states, value_states = get_query_key_value_tensors(self, hidden_states)
|
| 535 |
+
else:
|
| 536 |
+
query_states = get_query_key_value_tensors(self, hidden_states)
|
| 537 |
+
key_states, value_states = key_value_last_layer
|
| 538 |
+
last_key_states, last_value_states = None, None
|
| 539 |
+
|
| 540 |
+
# QK-norm.
|
| 541 |
+
if self.qk_norm:
|
| 542 |
+
query_states = self.q_norm(query_states)
|
| 543 |
+
if not self.reuse_kv:
|
| 544 |
+
key_states = self.k_norm(key_states)
|
| 545 |
+
|
| 546 |
+
# RoPE.
|
| 547 |
+
cos, sin = position_embeddings
|
| 548 |
+
query_states = apply_rotary_emb(query_states, cos, sin)
|
| 549 |
+
if not self.reuse_kv:
|
| 550 |
+
key_states = apply_rotary_emb(key_states, cos, sin)
|
| 551 |
+
|
| 552 |
+
# KV-cache.
|
| 553 |
+
if not self.reuse_kv and cache_params is not None:
|
| 554 |
+
key_states, value_states = cache_params.update(key_states, value_states, self.layer_idx)
|
| 555 |
+
|
| 556 |
+
# save k,v for next layer (*after* norm and RoPE and kv-cache update)
|
| 557 |
+
if not self.reuse_kv:
|
| 558 |
+
last_key_states, last_value_states = key_states, value_states
|
| 559 |
+
|
| 560 |
+
# attention computation. # TODO: do that in init ?
|
| 561 |
+
if ATTN_IMPL == "eager":
|
| 562 |
+
attention_interface = lambda q, k, v, **kw: eager_attention_forward(self, q, k, v, **kw)
|
| 563 |
+
elif ATTN_IMPL == "fa2":
|
| 564 |
+
attention_interface = lambda q, k, v, **kw: flash_attn_func(q, k, v, **kw)
|
| 565 |
+
elif ATTN_IMPL == "fa3":
|
| 566 |
+
attention_interface = lambda q, k, v, **kw: flash_attn_func(q, k, v, **kw)[0]
|
| 567 |
+
else:
|
| 568 |
+
raise ValueError(f"Unknown ATTN_IMPL: {ATTN_IMPL}")
|
| 569 |
+
|
| 570 |
+
attn_output = attention_interface(
|
| 571 |
+
query_states.bfloat16(),
|
| 572 |
+
key_states.bfloat16(),
|
| 573 |
+
value_states.bfloat16(),
|
| 574 |
+
causal=True,
|
| 575 |
+
window_size=(min(self.window_size, self.config.slw_wsize) if self.config.slw_wsize > 0 else self.window_size, 0),
|
| 576 |
+
softcap=self.config.softcap_local_attn,
|
| 577 |
+
softmax_scale=None if not self.config.use_uscaling else 1/self.head_dim,
|
| 578 |
+
**kwargs,
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
if cache_params is not None and not self.reuse_kv:
|
| 582 |
+
cache_params.trim(self.layer_idx)
|
| 583 |
+
|
| 584 |
+
return attn_output, last_key_states, last_value_states
|
| 585 |
+
|
| 586 |
+
# heavily adapted from official differential attention implementation
|
| 587 |
+
"""def eager_differential_attention_forward(
|
| 588 |
+
module: nn.Module,
|
| 589 |
+
query: torch.Tensor,
|
| 590 |
+
key: torch.Tensor,
|
| 591 |
+
value: torch.Tensor,
|
| 592 |
+
causal: bool = True,
|
| 593 |
+
window_size: Optional[Tuple[int, int]] = None,
|
| 594 |
+
softcap: Optional[float] = None,
|
| 595 |
+
softmax_scale: Optional[float] = None,
|
| 596 |
+
**kwargs,
|
| 597 |
+
) -> torch.Tensor:
|
| 598 |
+
if softmax_scale is None:
|
| 599 |
+
softmax_scale = module.head_dim ** -0.5
|
| 600 |
+
|
| 601 |
+
B, H2, Lq, Dh = query.shape # H2 = 2 * H
|
| 602 |
+
H = module.num_heads
|
| 603 |
+
Hkv = module.num_key_value_heads
|
| 604 |
+
assert H2 == 2 * H, "query must have 2*num_heads heads"
|
| 605 |
+
assert key.shape[-1] == Dh, "key head_dim must match query"
|
| 606 |
+
assert value.shape[-1] == 2 * Dh, "value must have 2*head_dim"
|
| 607 |
+
|
| 608 |
+
# repeat K to 2H (for the two "channels") and V to H (final combined heads)
|
| 609 |
+
n_rep = H // Hkv
|
| 610 |
+
k_2H = repeat_kv(key, 2 * n_rep) # [B, 2H, Lk, Dh]
|
| 611 |
+
v_H = repeat_kv(value, n_rep) # [B, H, Lk, 2Dh]
|
| 612 |
+
|
| 613 |
+
# raw attention logits for the 2 channels
|
| 614 |
+
attn_weights = torch.matmul(query, k_2H.transpose(2, 3)) * softmax_scale # [B, 2H, Lq, Lk]
|
| 615 |
+
|
| 616 |
+
if softcap is not None:
|
| 617 |
+
attn_weights = torch.tanh(attn_weights / softcap) * softcap
|
| 618 |
+
|
| 619 |
+
# masking (causal and/or sliding window)
|
| 620 |
+
if causal or (window_size is not None):
|
| 621 |
+
Lk = k_2H.size(2)
|
| 622 |
+
i = torch.arange(Lq, device=attn_weights.device).unsqueeze(1) # [Lq,1]
|
| 623 |
+
j = torch.arange(Lk, device=attn_weights.device).unsqueeze(0) # [1,Lk]
|
| 624 |
+
allowed = torch.ones((Lq, Lk), dtype=torch.bool, device=attn_weights.device)
|
| 625 |
+
if causal:
|
| 626 |
+
allowed &= (j <= i)
|
| 627 |
+
if window_size is not None:
|
| 628 |
+
w_left, w_right = window_size
|
| 629 |
+
if w_left is None: w_left = Lk
|
| 630 |
+
if w_right is None: w_right = Lk
|
| 631 |
+
allowed &= (j >= i - w_left) & (j <= i + w_right)
|
| 632 |
+
attn_weights = attn_weights.masked_fill(~allowed, float("-inf"))
|
| 633 |
+
|
| 634 |
+
# softmax in fp32 then cast back
|
| 635 |
+
attn_probs = torch.nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype) # [B,2H,Lq,Lk]
|
| 636 |
+
|
| 637 |
+
# reshape to [B, H, 2, Lq, Lk] and combine the two channels with learned lambda
|
| 638 |
+
attn_probs = attn_probs.view(B, H, 2, Lq, -1) # -1 = Lk
|
| 639 |
+
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
# per-head scalar lambdas: exp(<λ_q1,λ_k1>) - exp(<λ_q2,λ_k2>) + λ_init
|
| 643 |
+
lambda_1 = torch.exp(torch.sum(module.lambda_q1 * module.lambda_k1, dim=-1).float()).to(query.dtype) # [H]
|
| 644 |
+
lambda_2 = torch.exp(torch.sum(module.lambda_q2 * module.lambda_k2, dim=-1).float()).to(query.dtype) # [H]
|
| 645 |
+
lambda_full = (lambda_1 - lambda_2 + module.lambda_init).view(1, H, 1, 1) # [1,H,1,1] for broadcast
|
| 646 |
+
|
| 647 |
+
combined_probs = attn_probs[:, :, 0] - lambda_full * attn_probs[:, :, 1] # [B,H,Lq,Lk]
|
| 648 |
+
|
| 649 |
+
# weighted sum over V (note: V has 2*Dh per head)
|
| 650 |
+
attn = torch.matmul(combined_probs, v_H) # [B,H,Lq,2Dh]
|
| 651 |
+
|
| 652 |
+
# sub-layer norm (or similar) then final scaling
|
| 653 |
+
attn = module.subln(attn)
|
| 654 |
+
attn = attn * (1 - module.lambda_init)
|
| 655 |
+
|
| 656 |
+
# (B,Lq,H*2Dh)
|
| 657 |
+
attn = attn.transpose(1, 2).contiguous().view(B, Lq, H * 2 * Dh)
|
| 658 |
+
return attn"""
|
| 659 |
+
|
| 660 |
+
class DragonDifferentialAttention(nn.Module):
|
| 661 |
+
"""
|
| 662 |
+
Multi-headed differential attention (https://arxiv.org/abs/2410.05258)
|
| 663 |
+
"""
|
| 664 |
+
|
| 665 |
+
def __init__(self, config: DragonConfig, layer_idx: Optional[int], **kwargs):
|
| 666 |
+
super().__init__()
|
| 667 |
+
self.config = config
|
| 668 |
+
self.layer_idx = layer_idx
|
| 669 |
+
if layer_idx is None:
|
| 670 |
+
logger.warning_once(
|
| 671 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 672 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 673 |
+
"when creating this class."
|
| 674 |
+
)
|
| 675 |
+
self.num_heads = config.num_attention_heads
|
| 676 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 677 |
+
self.hidden_size = config.hidden_size
|
| 678 |
+
self.head_dim = config.hidden_size * config.expand_factor // self.num_heads
|
| 679 |
+
self.qk_norm = config.qk_norm
|
| 680 |
+
self.softcap = config.softcap_global_attn
|
| 681 |
+
self.scalable_softmax = config.scalable_softmax
|
| 682 |
+
|
| 683 |
+
projection_dim = self.head_dim * (self.num_heads + 2 * self.num_key_value_heads)
|
| 684 |
+
self.linear_qkv = DragonLinear(config, config.hidden_size, projection_dim, bias=False)
|
| 685 |
+
|
| 686 |
+
if self.qk_norm:
|
| 687 |
+
self.q_norm = DragonRMSNorm(self.head_dim, eps=config.norm_epsilon)
|
| 688 |
+
self.k_norm = DragonRMSNorm(self.head_dim, eps=config.norm_epsilon)
|
| 689 |
+
|
| 690 |
+
if self.scalable_softmax:
|
| 691 |
+
self.softmax_scaler = nn.Parameter(torch.ones(self.num_heads, dtype=torch.float32))
|
| 692 |
+
|
| 693 |
+
self.register_buffer("lambda_init", torch.tensor(0.8 - 0.6 * math.exp(-0.3 * (layer_idx+1))), persistent=False)
|
| 694 |
+
self.lambda_q1 = torch.nn.Parameter(torch.zeros(self.head_dim//2, dtype=torch.float32).normal_(mean=0,std=0.1))
|
| 695 |
+
self.lambda_k1 = torch.nn.Parameter(torch.zeros(self.head_dim//2, dtype=torch.float32).normal_(mean=0,std=0.1))
|
| 696 |
+
self.lambda_q2 = torch.nn.Parameter(torch.zeros(self.head_dim//2, dtype=torch.float32).normal_(mean=0,std=0.1))
|
| 697 |
+
self.lambda_k2 = torch.nn.Parameter(torch.zeros(self.head_dim//2, dtype=torch.float32).normal_(mean=0,std=0.1))
|
| 698 |
+
|
| 699 |
+
def forward(
|
| 700 |
+
self,
|
| 701 |
+
hidden_states: torch.Tensor,
|
| 702 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 703 |
+
cache_params: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 704 |
+
**kwargs,
|
| 705 |
+
):
|
| 706 |
+
# Q, K, V projections.
|
| 707 |
+
query_states, key_states, value_states = get_query_key_value_tensors(self, hidden_states)
|
| 708 |
+
value_states = value_states.reshape(value_states.size(0), value_states.size(1), value_states.size(2)//2, 2*value_states.size(3))
|
| 709 |
+
|
| 710 |
+
# QK-norm.
|
| 711 |
+
if self.qk_norm:
|
| 712 |
+
query_states = self.q_norm(query_states)
|
| 713 |
+
key_states = self.k_norm(key_states)
|
| 714 |
+
|
| 715 |
+
# scalable softmax.
|
| 716 |
+
if self.scalable_softmax:
|
| 717 |
+
# scalable-softmax (https://arxiv.org/abs/2501.19399): multiply q by s*log(n)
|
| 718 |
+
T = query_states.size(1)
|
| 719 |
+
pos = (position_ids.to(torch.float32).view(position_ids.size(0), T, 1, 1) + 1.)
|
| 720 |
+
log_pos = pos.log() if self.config.slw_wsize <= 0 else torch.clamp_max(pos, self.config.slw_wsize).log()
|
| 721 |
+
query_states = (self.softmax_scaler.view(1, 1, -1, 1) * log_pos) * query_states
|
| 722 |
+
# TODO: caching mechanism for log_pos
|
| 723 |
+
|
| 724 |
+
# KV-cache.
|
| 725 |
+
if cache_params is not None:
|
| 726 |
+
key_states, value_states = cache_params.update(key_states, value_states, self.layer_idx)
|
| 727 |
+
|
| 728 |
+
# attention computation.
|
| 729 |
+
# split q,k heads into two groups
|
| 730 |
+
query1_states, query2_states = query_states[:, :, torch.arange(0, self.num_heads, 2)].contiguous(), query_states[:, :, torch.arange(1, self.num_heads, 2)].contiguous()
|
| 731 |
+
key1_states, key2_states = key_states[:, :, torch.arange(0, self.num_key_value_heads, 2)].contiguous(), key_states[:, :, torch.arange(1, self.num_key_value_heads, 2)].contiguous()
|
| 732 |
+
# compute
|
| 733 |
+
# TODO: do that in init ?
|
| 734 |
+
if DIFF_ATTN_IMPL == "flex_head":
|
| 735 |
+
def diff_attention_interface(q, k, v, **kw):
|
| 736 |
+
return flex_head_fa.flash_attn_func(q, k, v, **kw)
|
| 737 |
+
elif DIFF_ATTN_IMPL == "fa2":
|
| 738 |
+
def diff_attention_interface(q, k, v, **kw):
|
| 739 |
+
D = v.size(3)
|
| 740 |
+
v1 = v[:, :, :, :D//2]#.contiguous()
|
| 741 |
+
v2 = v[:, :, :, D//2:]#.contiguous()
|
| 742 |
+
o1 = flash_attn_func(q, k, v1, **kw)
|
| 743 |
+
o2 = flash_attn_func(q, k, v2, **kw)
|
| 744 |
+
o = torch.cat([o1, o2], dim=-1)
|
| 745 |
+
return o
|
| 746 |
+
elif DIFF_ATTN_IMPL == "fa3":
|
| 747 |
+
def diff_attention_interface(q, k, v, **kw):
|
| 748 |
+
D = v.size(3)
|
| 749 |
+
v1 = v[:, :, :, :D//2]#.contiguous()
|
| 750 |
+
v2 = v[:, :, :, D//2:]#.contiguous()
|
| 751 |
+
o1 = flash_attn_func(q, k, v1, **kw)[0]
|
| 752 |
+
o2 = flash_attn_func(q, k, v2, **kw)[0]
|
| 753 |
+
o = torch.cat([o1, o2], dim=-1)
|
| 754 |
+
return o
|
| 755 |
+
elif DIFF_ATTN_IMPL == "eager":
|
| 756 |
+
def diff_attention_interface(q, k, v, **kw):
|
| 757 |
+
D = v.size(3)
|
| 758 |
+
v1 = v[:, :, :, :D//2]#.contiguous()
|
| 759 |
+
v2 = v[:, :, :, D//2:]#.contiguous()
|
| 760 |
+
o1 = eager_attention_forward(self, q, k, v1, **kw)
|
| 761 |
+
o2 = eager_attention_forward(self, q, k, v2, **kw)
|
| 762 |
+
o = torch.cat([o1, o2], dim=-1)
|
| 763 |
+
return o
|
| 764 |
+
|
| 765 |
+
y1 = diff_attention_interface(
|
| 766 |
+
query1_states.bfloat16(),
|
| 767 |
+
key1_states.bfloat16(),
|
| 768 |
+
value_states.bfloat16(),
|
| 769 |
+
causal=True,
|
| 770 |
+
window_size=(self.config.slw_wsize, 0),
|
| 771 |
+
softcap=self.softcap,
|
| 772 |
+
softmax_scale=None if not self.config.use_uscaling else 1/self.head_dim)
|
| 773 |
+
y2 = diff_attention_interface(
|
| 774 |
+
query2_states.bfloat16(),
|
| 775 |
+
key2_states.bfloat16(),
|
| 776 |
+
value_states.bfloat16(),
|
| 777 |
+
causal=True,
|
| 778 |
+
window_size=(self.config.slw_wsize, 0),
|
| 779 |
+
softcap=self.softcap,
|
| 780 |
+
softmax_scale=None if not self.config.use_uscaling else 1/self.head_dim)
|
| 781 |
+
lambda_1 = torch.exp((self.lambda_q1 * self.lambda_k1).sum(-1).float()) # (H/2)
|
| 782 |
+
lambda_2 = torch.exp((self.lambda_q2 * self.lambda_k2).sum(-1).float()) # (H/2)
|
| 783 |
+
lambda_full = (lambda_1 - lambda_2 + self.lambda_init).view(1, 1, -1, 1).type_as(y1)
|
| 784 |
+
attn_output = (y1 - lambda_full * y2).contiguous()
|
| 785 |
+
|
| 786 |
+
if cache_params is not None:
|
| 787 |
+
cache_params.trim(self.layer_idx)
|
| 788 |
+
|
| 789 |
+
return attn_output, None, None
|
| 790 |
+
|
| 791 |
+
class DragonGatedDeltaNet(nn.Module):
|
| 792 |
+
def __init__(self, config: DragonConfig, layer_idx: Optional[int], **kwargs):
|
| 793 |
+
super().__init__()
|
| 794 |
+
self.config = config
|
| 795 |
+
self.layer_idx = layer_idx
|
| 796 |
+
if layer_idx is None:
|
| 797 |
+
logger.warning_once(
|
| 798 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 799 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 800 |
+
"when creating this class."
|
| 801 |
+
)
|
| 802 |
+
|
| 803 |
+
self.conv_size = config.conv_kernel
|
| 804 |
+
self.conv_bias = config.use_bias
|
| 805 |
+
|
| 806 |
+
self.n_heads = config.num_attention_heads
|
| 807 |
+
self.n_heads_local = self.n_heads // 1
|
| 808 |
+
self.d_head = int(config.hidden_size * (config.expand_factor/2)) // self.n_heads
|
| 809 |
+
|
| 810 |
+
self.key_dim = int(self.n_heads * self.d_head)
|
| 811 |
+
self.value_dim = int(2*self.key_dim) # todo refactor
|
| 812 |
+
self.head_k_dim = self.d_head
|
| 813 |
+
self.head_v_dim = int(2*self.d_head)
|
| 814 |
+
self.silu = nn.SiLU()
|
| 815 |
+
|
| 816 |
+
self.dk = self.head_k_dim
|
| 817 |
+
self.dv = self.head_v_dim # todo : duplicate variables
|
| 818 |
+
self.per_head_proj = 2*self.dk + self.dv + 2 # [q k v b a] per head
|
| 819 |
+
in_proj_dim_global = self.n_heads * self.per_head_proj
|
| 820 |
+
|
| 821 |
+
# todo: rename d_head => head_dim (for consistency with other classes)
|
| 822 |
+
|
| 823 |
+
self.in_proj = DragonLinear(config, config.hidden_size, in_proj_dim_global, bias=False)
|
| 824 |
+
|
| 825 |
+
dt_min = config.time_step_min
|
| 826 |
+
dt_max = config.time_step_max
|
| 827 |
+
dt_init_floor = config.time_step_floor
|
| 828 |
+
A_init_range = config.A_init_range
|
| 829 |
+
# Initialize dt bias so that F.softplus(dt_bias) is between dt_min and dt_max
|
| 830 |
+
dt = torch.exp(
|
| 831 |
+
torch.rand(self.n_heads_local) * (math.log(dt_max) - math.log(dt_min))
|
| 832 |
+
+ math.log(dt_min)
|
| 833 |
+
)
|
| 834 |
+
dt = torch.clamp(dt, min=dt_init_floor)
|
| 835 |
+
# Inverse of softplus: https://github.com/pytorch/pytorch/issues/72759
|
| 836 |
+
inv_dt = dt + torch.log(-torch.expm1(-dt))
|
| 837 |
+
with torch.no_grad():
|
| 838 |
+
self.dt_bias = nn.Parameter(inv_dt)
|
| 839 |
+
|
| 840 |
+
assert A_init_range[0] > 0 and A_init_range[1] >= A_init_range[0]
|
| 841 |
+
A = torch.empty(
|
| 842 |
+
self.n_heads_local, dtype=torch.float32, device=torch.cuda.current_device()
|
| 843 |
+
).uniform_(*A_init_range)
|
| 844 |
+
A_log = torch.log(A) # Keep A_log in fp32
|
| 845 |
+
self.A_log = nn.Parameter(A_log)
|
| 846 |
+
|
| 847 |
+
self.q_conv1d = DragonConv1D(
|
| 848 |
+
hidden_size=self.key_dim,
|
| 849 |
+
kernel_size=self.conv_size,
|
| 850 |
+
)
|
| 851 |
+
self.k_conv1d = DragonConv1D(
|
| 852 |
+
hidden_size=self.key_dim,
|
| 853 |
+
kernel_size=self.conv_size,
|
| 854 |
+
)
|
| 855 |
+
self.v_conv1d = DragonConv1D(
|
| 856 |
+
hidden_size=self.value_dim,
|
| 857 |
+
kernel_size=self.conv_size,
|
| 858 |
+
)
|
| 859 |
+
|
| 860 |
+
self.g_proj = DragonLinear(config, config.hidden_size, config.hidden_size*config.expand_factor, bias=False)
|
| 861 |
+
self.act_func_gate = F.silu
|
| 862 |
+
|
| 863 |
+
def forward(self,
|
| 864 |
+
hidden_states: torch.Tensor,
|
| 865 |
+
cache_params: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 866 |
+
):
|
| 867 |
+
_, q_len, _ = hidden_states.shape
|
| 868 |
+
mode = 'fused_recurrent' if q_len <= 64 else 'chunk'
|
| 869 |
+
if self.training:
|
| 870 |
+
assert mode == 'chunk', "Only chunk mode is supported in training."
|
| 871 |
+
|
| 872 |
+
# input projection (TP-aware)
|
| 873 |
+
qkvba = self.in_proj(hidden_states) # (l, b, H_local * per_head_proj)
|
| 874 |
+
# [L,B,(H*P)] -> [B,L,H,P]
|
| 875 |
+
qkvba = rearrange(qkvba, "b l (h p) -> b l h p", h=self.n_heads_local).contiguous()
|
| 876 |
+
# split per head: [B,L,H,dk/dk/dv/1/1]
|
| 877 |
+
q_proj = qkvba[..., 0:self.dk]
|
| 878 |
+
k_proj = qkvba[..., self.dk:2*self.dk]
|
| 879 |
+
v_proj = qkvba[..., 2*self.dk:2*self.dk+self.dv]
|
| 880 |
+
b_proj = qkvba[..., 2*self.dk+self.dv:2*self.dk+self.dv+1]
|
| 881 |
+
a_proj = qkvba[..., 2*self.dk+self.dv+1:]
|
| 882 |
+
# concat for conv
|
| 883 |
+
q_proj = rearrange(q_proj, "b l h d -> b l (h d)")
|
| 884 |
+
k_proj = rearrange(k_proj, "b l h d -> b l (h d)")
|
| 885 |
+
v_proj = rearrange(v_proj, "b l h d -> b l (h d)")
|
| 886 |
+
b_proj = rearrange(b_proj, "b l h d -> b l (h d)") # d=1
|
| 887 |
+
a_proj = rearrange(a_proj, "b l h d -> b l (h d)")
|
| 888 |
+
|
| 889 |
+
q_conv_cache, k_conv_cache, v_conv_cache, ssm_cache = (None, None, None, None)
|
| 890 |
+
if cache_params is not None:
|
| 891 |
+
q_conv_cache, k_conv_cache, v_conv_cache, ssm_cache = cache_params.get_ssm_cache(self.layer_idx)
|
| 892 |
+
|
| 893 |
+
q, q_conv_cache = self.q_conv1d(
|
| 894 |
+
x=q_proj,
|
| 895 |
+
mask=None,
|
| 896 |
+
cache=q_conv_cache,
|
| 897 |
+
output_final_state=(cache_params is not None))
|
| 898 |
+
k, k_conv_cache = self.k_conv1d(
|
| 899 |
+
x=k_proj,
|
| 900 |
+
mask=None,
|
| 901 |
+
cache=k_conv_cache,
|
| 902 |
+
output_final_state=(cache_params is not None))
|
| 903 |
+
v, v_conv_cache = self.v_conv1d(
|
| 904 |
+
x=v_proj,
|
| 905 |
+
mask=None,
|
| 906 |
+
cache=v_conv_cache,
|
| 907 |
+
output_final_state=(cache_params is not None))
|
| 908 |
+
|
| 909 |
+
# back to per-head for kernels
|
| 910 |
+
q = rearrange(q, "b l (h d) -> b l h d", d=self.dk)
|
| 911 |
+
k = rearrange(k, "b l (h d) -> b l h d", d=self.dk)
|
| 912 |
+
v = rearrange(v, "b l (h d) -> b l h d", d=self.dv)
|
| 913 |
+
|
| 914 |
+
beta = b_proj.sigmoid()
|
| 915 |
+
g = -self.A_log.float().exp() * F.softplus(a_proj.float() + self.dt_bias)
|
| 916 |
+
|
| 917 |
+
if mode == 'chunk':
|
| 918 |
+
if chunk_gated_delta_rule is not None:
|
| 919 |
+
o, ssm_cache = chunk_gated_delta_rule(
|
| 920 |
+
q=q.bfloat16(),
|
| 921 |
+
k=k.bfloat16(),
|
| 922 |
+
v=v.bfloat16(),
|
| 923 |
+
g=g,
|
| 924 |
+
beta=beta,
|
| 925 |
+
scale=None if not self.config.use_uscaling else 1/self.head_k_dim,
|
| 926 |
+
initial_state=ssm_cache,
|
| 927 |
+
output_final_state=(cache_params is not None),
|
| 928 |
+
cu_seqlens=None, # for varlen training
|
| 929 |
+
head_first=False,
|
| 930 |
+
use_qk_l2norm_in_kernel=True
|
| 931 |
+
) # (B L H D) where d is head_v_dim
|
| 932 |
+
else:
|
| 933 |
+
raise NotImplementedError("PyTorch implementation of chunked GDN is not available.")
|
| 934 |
+
elif mode == 'fused_recurrent':
|
| 935 |
+
if fused_recurrent_gated_delta_rule is not None:
|
| 936 |
+
o, ssm_cache = fused_recurrent_gated_delta_rule(
|
| 937 |
+
q=q.bfloat16(),
|
| 938 |
+
k=k.bfloat16(),
|
| 939 |
+
v=v.bfloat16(),
|
| 940 |
+
g=g,
|
| 941 |
+
beta=beta,
|
| 942 |
+
scale=None if not self.config.use_uscaling else 1/self.head_k_dim,
|
| 943 |
+
initial_state=ssm_cache,
|
| 944 |
+
output_final_state=(cache_params is not None),
|
| 945 |
+
cu_seqlens=None,
|
| 946 |
+
use_qk_l2norm_in_kernel=True
|
| 947 |
+
) # (B L H D) where d is head_v_dim
|
| 948 |
+
else:
|
| 949 |
+
raise NotImplementedError("PyTorch implementation of recurrent GDN is not available.")
|
| 950 |
+
else:
|
| 951 |
+
raise NotImplementedError(f"Not supported mode `{mode}`.")
|
| 952 |
+
|
| 953 |
+
g = self.g_proj(hidden_states).view(o.size(0), o.size(1), o.size(2), o.size(3)) # (B, L, H, D)
|
| 954 |
+
o = o * self.act_func_gate(g)
|
| 955 |
+
|
| 956 |
+
if cache_params is not None:
|
| 957 |
+
cache_params.update_ssm_cache(
|
| 958 |
+
q_conv_states=q_conv_cache,
|
| 959 |
+
k_conv_states=k_conv_cache,
|
| 960 |
+
v_conv_states=v_conv_cache,
|
| 961 |
+
ssm_states=ssm_cache,
|
| 962 |
+
layer_idx=self.layer_idx,
|
| 963 |
+
)
|
| 964 |
+
|
| 965 |
+
return o
|
| 966 |
+
|
| 967 |
+
class DragonMLP(nn.Module):
|
| 968 |
+
def __init__(self, config: DragonConfig):
|
| 969 |
+
super().__init__()
|
| 970 |
+
self.fc_1 = DragonLinear(config, config.hidden_size, config.intermediate_size, bias=False)
|
| 971 |
+
self.fc_2 = DragonLinear(config, config.intermediate_size, config.hidden_size, bias=False)
|
| 972 |
+
self.register_buffer("_2_sqrt_5", torch.tensor(2/math.sqrt(5)) if config.use_uscaling else torch.tensor(1.), persistent=False)
|
| 973 |
+
|
| 974 |
+
def forward(self, hidden_states):
|
| 975 |
+
hidden_states = self.fc_1(hidden_states)
|
| 976 |
+
hidden_states = self._2_sqrt_5 * F.relu(hidden_states).square()
|
| 977 |
+
hidden_states = self.fc_2(hidden_states)
|
| 978 |
+
return hidden_states
|
| 979 |
+
|
| 980 |
+
class DragonBlock(GradientCheckpointingLayer):
|
| 981 |
+
def __init__(self, config: DragonConfig, layer_idx: int, layer_type: str):
|
| 982 |
+
super().__init__()
|
| 983 |
+
self.config = config
|
| 984 |
+
self.layer_idx = layer_idx
|
| 985 |
+
self.expand_factor = config.expand_factor
|
| 986 |
+
|
| 987 |
+
if layer_type in ['l', 'r']:
|
| 988 |
+
self.attn = DragonAttention(config, reuse_kv=(layer_type=='r'), layer_idx=layer_idx)
|
| 989 |
+
elif layer_type == 'd':
|
| 990 |
+
self.attn = DragonDifferentialAttention(config, layer_idx=layer_idx)
|
| 991 |
+
else:
|
| 992 |
+
raise ValueError(f"Unknown layer type: {layer_type}")
|
| 993 |
+
self.lin_attn = DragonGatedDeltaNet(config, layer_idx=layer_idx)
|
| 994 |
+
self.mixer_proj = DragonLinear(config, int(self.expand_factor*config.hidden_size), config.hidden_size, bias=False)
|
| 995 |
+
|
| 996 |
+
if isinstance(self.attn, (DragonDifferentialAttention)):
|
| 997 |
+
self.attn_group_norm = DragonHeadWiseRMSNorm(n_heads=self.attn.num_heads//2, d_head=2*self.attn.head_dim, eps=config.norm_epsilon)
|
| 998 |
+
else:
|
| 999 |
+
self.attn_group_norm = DragonHeadWiseRMSNorm(n_heads=self.attn.num_heads, d_head=self.attn.head_dim, eps=config.norm_epsilon)
|
| 1000 |
+
self.lin_attn_group_norm = DragonHeadWiseRMSNorm(n_heads=self.lin_attn.n_heads, d_head=self.lin_attn.head_v_dim, eps=config.norm_epsilon)
|
| 1001 |
+
|
| 1002 |
+
self.input_norm = DragonRMSNorm(config.hidden_size, eps=config.norm_epsilon)
|
| 1003 |
+
self.postmixer_norm = DragonRMSNorm(config.hidden_size, eps=config.norm_epsilon)
|
| 1004 |
+
self.mlp = DragonMLP(config)
|
| 1005 |
+
|
| 1006 |
+
self.register_buffer("lns", torch.tensor(1.0 if config.use_uscaling else 1. / math.sqrt(layer_idx + (2 if config.old_lns else 1))), persistent=False)
|
| 1007 |
+
self.register_buffer("sqrt_2_2", torch.tensor(math.sqrt(2)/2) if config.use_uscaling else torch.tensor(1/2), persistent=False)
|
| 1008 |
+
self.register_buffer("sqrt_tau", torch.sqrt(torch.tensor(self.config.uscaling_tau)) if config.use_uscaling else torch.tensor(1.0), persistent=False)
|
| 1009 |
+
self.register_buffer("sqrt_one_minus_tau", torch.sqrt(torch.tensor(1.0 - self.config.uscaling_tau)) if config.use_uscaling else torch.tensor(1.0), persistent=False)
|
| 1010 |
+
|
| 1011 |
+
def forward(
|
| 1012 |
+
self,
|
| 1013 |
+
hidden_states: torch.Tensor,
|
| 1014 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1015 |
+
cache_params: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 1016 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1017 |
+
position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
|
| 1018 |
+
key_value_last_layer: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
|
| 1019 |
+
**kwargs,
|
| 1020 |
+
):
|
| 1021 |
+
# MIXER.
|
| 1022 |
+
residual = hidden_states
|
| 1023 |
+
hidden_states = self.lns * self.input_norm(hidden_states) # (B, L, D)
|
| 1024 |
+
y_attn, last_key_states, last_value_states = self.attn(
|
| 1025 |
+
hidden_states=hidden_states,
|
| 1026 |
+
position_embeddings=position_embeddings,
|
| 1027 |
+
position_ids=position_ids,
|
| 1028 |
+
cache_params=cache_params,
|
| 1029 |
+
key_value_last_layer=key_value_last_layer,
|
| 1030 |
+
) # (B, L, E*D)
|
| 1031 |
+
y_lin_attn = self.lin_attn(
|
| 1032 |
+
hidden_states=hidden_states,
|
| 1033 |
+
cache_params=cache_params,
|
| 1034 |
+
) # (B, L, E*D)
|
| 1035 |
+
y_attn = self.attn_group_norm(y_attn).view(y_attn.size(0), y_attn.size(1), -1)
|
| 1036 |
+
y_lin_attn = self.lin_attn_group_norm(y_lin_attn).view(y_lin_attn.size(0), y_lin_attn.size(1), -1)
|
| 1037 |
+
y_mixer = self.mixer_proj(self.sqrt_2_2 * (y_attn + y_lin_attn))
|
| 1038 |
+
hidden_states = self.sqrt_one_minus_tau * residual + self.sqrt_tau * y_mixer
|
| 1039 |
+
|
| 1040 |
+
# MLP.
|
| 1041 |
+
residual = hidden_states
|
| 1042 |
+
hidden_states = self.lns * self.postmixer_norm(hidden_states)
|
| 1043 |
+
y_mlp = self.mlp(hidden_states) # (B, L, D)
|
| 1044 |
+
hidden_states = self.sqrt_one_minus_tau * residual + self.sqrt_tau * y_mlp
|
| 1045 |
+
|
| 1046 |
+
return hidden_states, last_key_states, last_value_states
|
| 1047 |
+
|
| 1048 |
+
class DragonPreTrainedModel(PreTrainedModel):
|
| 1049 |
+
config: DragonConfig
|
| 1050 |
+
base_model_prefix = "model"
|
| 1051 |
+
supports_gradient_checkpointing = True
|
| 1052 |
+
_no_split_modules = ["DragonBlock"]
|
| 1053 |
+
_supports_flash_attn = True
|
| 1054 |
+
_supports_sdpa = True
|
| 1055 |
+
_supports_flex_attn = True
|
| 1056 |
+
|
| 1057 |
+
_can_compile_fullgraph = True
|
| 1058 |
+
_supports_attention_backend = True
|
| 1059 |
+
_can_record_outputs = {
|
| 1060 |
+
"hidden_states": DragonBlock,
|
| 1061 |
+
"attentions": DragonBlock,
|
| 1062 |
+
}
|
| 1063 |
+
|
| 1064 |
+
def _init_weights(self, module):
|
| 1065 |
+
if isinstance(module, (DragonLinear, DragonConv1D)):
|
| 1066 |
+
if module.bias is not None:
|
| 1067 |
+
nn.init.zeros_(module.bias)
|
| 1068 |
+
nn.init.normal_(module.weight, mean=0., std=1. if self.config.use_uscaling else 0.006)
|
| 1069 |
+
elif isinstance(module, nn.Embedding):
|
| 1070 |
+
nn.init.normal_(module.weight, mean=0., std=1. if self.config.use_uscaling else 0.006)
|
| 1071 |
+
|
| 1072 |
+
@dataclass
|
| 1073 |
+
class DragonOutput(ModelOutput):
|
| 1074 |
+
"""
|
| 1075 |
+
Class for the Dragon model outputs.
|
| 1076 |
+
Args:
|
| 1077 |
+
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
|
| 1078 |
+
Sequence of hidden-states at the output of the last layer of the model.
|
| 1079 |
+
cache_params (`HybridDragonAttentionDynamicCache`):
|
| 1080 |
+
The state of the model at the last time step. Can be used in a forward method with the next `input_ids` to
|
| 1081 |
+
avoid providing the old `input_ids`.
|
| 1082 |
+
Includes both the RNN-like state matrices after the selective scan, and the conv states
|
| 1083 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
| 1084 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
| 1085 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
| 1086 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
| 1087 |
+
"""
|
| 1088 |
+
|
| 1089 |
+
last_hidden_state: Optional[torch.FloatTensor] = None
|
| 1090 |
+
past_key_values: Optional[HybridDragonAttentionDynamicCache] = None
|
| 1091 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
| 1092 |
+
|
| 1093 |
+
@dataclass
|
| 1094 |
+
class DragonCausalLMOutput(ModelOutput):
|
| 1095 |
+
"""
|
| 1096 |
+
Base class for causal language model (or autoregressive) outputs.
|
| 1097 |
+
Args:
|
| 1098 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 1099 |
+
Language modeling loss (for next-token prediction).
|
| 1100 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
| 1101 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
| 1102 |
+
cache_params (`HybridDragonAttentionDynamicCache`):
|
| 1103 |
+
The state of the model at the last time step. Can be used in a forward method with the next `input_ids` to
|
| 1104 |
+
avoid providing the old `input_ids`.
|
| 1105 |
+
Includes both the State space model state matrices after the selective scan, and the Convolutional states
|
| 1106 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
| 1107 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
| 1108 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
| 1109 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
| 1110 |
+
"""
|
| 1111 |
+
|
| 1112 |
+
loss: Optional[torch.FloatTensor] = None
|
| 1113 |
+
logits: Optional[torch.FloatTensor] = None
|
| 1114 |
+
past_key_values: Optional[HybridDragonAttentionDynamicCache] = None
|
| 1115 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
| 1116 |
+
|
| 1117 |
+
class DragonModel(DragonPreTrainedModel):
|
| 1118 |
+
def __init__(self, config: DragonConfig):
|
| 1119 |
+
super().__init__(config)
|
| 1120 |
+
self.padding_idx = config.pad_token_id
|
| 1121 |
+
self.vocab_size = config.vocab_size
|
| 1122 |
+
|
| 1123 |
+
self.embedding = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 1124 |
+
self.layers = nn.ModuleList([DragonBlock(config, layer_idx=i, layer_type=layer) for i, layer in enumerate(config.layers_config)])
|
| 1125 |
+
|
| 1126 |
+
self.rotary_emb = DragonRotaryEmbedding(config, head_dim=(config.expand_factor*config.hidden_size)//config.num_attention_heads) # only for SWA
|
| 1127 |
+
self.final_norm = DragonRMSNorm(config.hidden_size, eps=config.norm_epsilon)
|
| 1128 |
+
|
| 1129 |
+
alpha_fwd_out = 1. / float(self.config.hidden_size) if self.config.use_uscaling else 1.0
|
| 1130 |
+
alpha_bwd_out = 1. / math.sqrt(float(self.config.hidden_size)) if self.config.use_uscaling else 1.0
|
| 1131 |
+
self.register_buffer("alpha_fwd_out", torch.tensor(alpha_fwd_out), persistent=False)
|
| 1132 |
+
self.register_buffer("alpha_bwd_out", torch.tensor(alpha_bwd_out), persistent=False)
|
| 1133 |
+
|
| 1134 |
+
self.gradient_checkpointing = False
|
| 1135 |
+
self.post_init()
|
| 1136 |
+
|
| 1137 |
+
def get_input_embeddings(self):
|
| 1138 |
+
return self.embedding
|
| 1139 |
+
|
| 1140 |
+
def set_input_embeddings(self, new_embeddings):
|
| 1141 |
+
self.embedding = new_embeddings
|
| 1142 |
+
|
| 1143 |
+
def forward(
|
| 1144 |
+
self,
|
| 1145 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1146 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1147 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1148 |
+
use_cache: Optional[bool] = None,
|
| 1149 |
+
past_key_values: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 1150 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1151 |
+
output_hidden_states: Optional[bool] = None,
|
| 1152 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1153 |
+
**kwargs
|
| 1154 |
+
) -> DragonOutput:
|
| 1155 |
+
use_cache = use_cache if use_cache is not None else (self.config.use_cache if not self.training else False)
|
| 1156 |
+
|
| 1157 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 1158 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 1159 |
+
|
| 1160 |
+
if inputs_embeds is None:
|
| 1161 |
+
inputs_embeds = self.embedding(input_ids)
|
| 1162 |
+
|
| 1163 |
+
if self.gradient_checkpointing and self.training and use_cache:
|
| 1164 |
+
logger.warning_once(
|
| 1165 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
|
| 1166 |
+
)
|
| 1167 |
+
use_cache = False
|
| 1168 |
+
|
| 1169 |
+
if use_cache:
|
| 1170 |
+
if past_key_values is None:
|
| 1171 |
+
past_key_values = HybridDragonAttentionDynamicCache(self.config, dtype=self.dtype)
|
| 1172 |
+
elif not isinstance(past_key_values, HybridDragonAttentionDynamicCache):
|
| 1173 |
+
# recreate (todo: upcast instead of recreate)
|
| 1174 |
+
if type(past_key_values) is DynamicCache:
|
| 1175 |
+
print("upgrading DynamicCache → HybridDragonAttentionDynamicCache")
|
| 1176 |
+
past_key_values = HybridDragonAttentionDynamicCache(self.config, dtype=self.dtype)
|
| 1177 |
+
else:
|
| 1178 |
+
raise TypeError(f"Unsupported cache type: {type(past_key_values)}")
|
| 1179 |
+
|
| 1180 |
+
hidden_states = inputs_embeds
|
| 1181 |
+
|
| 1182 |
+
if cache_position is None:
|
| 1183 |
+
cache_position = torch.arange(hidden_states.shape[1], device=hidden_states.device)
|
| 1184 |
+
if position_ids is None:
|
| 1185 |
+
position_ids = cache_position.unsqueeze(0)
|
| 1186 |
+
|
| 1187 |
+
all_hidden_states = () if output_hidden_states else None
|
| 1188 |
+
|
| 1189 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 1190 |
+
|
| 1191 |
+
shared_kv = (None, None)
|
| 1192 |
+
for block in self.layers:
|
| 1193 |
+
if output_hidden_states:
|
| 1194 |
+
all_hidden_states += (hidden_states,)
|
| 1195 |
+
|
| 1196 |
+
hidden_states, last_k, last_v = block(
|
| 1197 |
+
hidden_states,
|
| 1198 |
+
position_ids=position_ids,
|
| 1199 |
+
cache_params=past_key_values,
|
| 1200 |
+
cache_position=cache_position,
|
| 1201 |
+
position_embeddings=position_embeddings,
|
| 1202 |
+
key_value_last_layer=shared_kv,
|
| 1203 |
+
**kwargs,
|
| 1204 |
+
)
|
| 1205 |
+
shared_kv = (last_k, last_v)
|
| 1206 |
+
|
| 1207 |
+
hidden_states = self.final_norm(hidden_states)
|
| 1208 |
+
hidden_states = _ScaleFB.apply(hidden_states, self.alpha_fwd_out, self.alpha_bwd_out)
|
| 1209 |
+
|
| 1210 |
+
if output_hidden_states:
|
| 1211 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
| 1212 |
+
|
| 1213 |
+
return DragonOutput(
|
| 1214 |
+
last_hidden_state=hidden_states,
|
| 1215 |
+
past_key_values=past_key_values if use_cache else None,
|
| 1216 |
+
hidden_states=all_hidden_states,
|
| 1217 |
+
)
|
| 1218 |
+
DragonModel.register_for_auto_class("AutoModel")
|
| 1219 |
+
|
| 1220 |
+
class DragonForCausalLM(DragonPreTrainedModel, GenerationMixin):
|
| 1221 |
+
def __init__(self, config: DragonConfig):
|
| 1222 |
+
super().__init__(config)
|
| 1223 |
+
self.model = DragonModel(config)
|
| 1224 |
+
self.vocab_size = config.vocab_size
|
| 1225 |
+
#self.lm_head = DragonLinear(config, config.hidden_size, config.vocab_size, bias=False, alpha_fwd=1/config.hidden_size, alpha_bwd=1/math.sqrt(config.hidden_size))
|
| 1226 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1227 |
+
self.post_init()
|
| 1228 |
+
|
| 1229 |
+
def forward(
|
| 1230 |
+
self,
|
| 1231 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1232 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1233 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1234 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1235 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1236 |
+
use_cache: Optional[bool] = None,
|
| 1237 |
+
past_key_values: Optional[HybridDragonAttentionDynamicCache] = None,
|
| 1238 |
+
cache_position: Optional[torch.Tensor] = None,
|
| 1239 |
+
output_hidden_states: Optional[bool] = None,
|
| 1240 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1241 |
+
**kwargs,
|
| 1242 |
+
) -> DragonCausalLMOutput:
|
| 1243 |
+
output_hidden_states = (output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states)
|
| 1244 |
+
|
| 1245 |
+
outputs: DragonOutput = self.model(
|
| 1246 |
+
input_ids=input_ids,
|
| 1247 |
+
position_ids=position_ids,
|
| 1248 |
+
attention_mask=attention_mask,
|
| 1249 |
+
use_cache=use_cache,
|
| 1250 |
+
past_key_values=past_key_values,
|
| 1251 |
+
cache_position=cache_position,
|
| 1252 |
+
inputs_embeds=inputs_embeds,
|
| 1253 |
+
output_hidden_states=output_hidden_states,
|
| 1254 |
+
**kwargs,
|
| 1255 |
+
)
|
| 1256 |
+
|
| 1257 |
+
hidden_states = outputs.last_hidden_state
|
| 1258 |
+
|
| 1259 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 1260 |
+
logits = self.lm_head(hidden_states.to(self.lm_head.weight.dtype)[:, slice_indices, :]).float()
|
| 1261 |
+
|
| 1262 |
+
loss = None
|
| 1263 |
+
if labels is not None:
|
| 1264 |
+
# move labels to correct device
|
| 1265 |
+
labels = labels.to(logits.device)
|
| 1266 |
+
# shift
|
| 1267 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 1268 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 1269 |
+
# compute loss
|
| 1270 |
+
loss = F.cross_entropy(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1), ignore_index=self.model.padding_idx)
|
| 1271 |
+
|
| 1272 |
+
return DragonCausalLMOutput(
|
| 1273 |
+
loss=loss,
|
| 1274 |
+
logits=logits,
|
| 1275 |
+
past_key_values=outputs.past_key_values,
|
| 1276 |
+
hidden_states=outputs.hidden_states,
|
| 1277 |
+
)
|
| 1278 |
+
DragonForCausalLM.register_for_auto_class("AutoModelForCausalLM")
|
| 1279 |
+
|
| 1280 |
+
__all__ = ["DragonModel", "DragonForCausalLM", "DragonPreTrainedModel"]
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<|endoftext|>",
|
| 3 |
+
"eos_token": "<|endoftext|>",
|
| 4 |
+
"pad_token": "<|endoftext|>"
|
| 5 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14e265037e4c487453fc3c1238f3cd2a5883f4b7a1c83e1da2dd154492f2527b
|
| 3 |
+
size 14941185
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "<|endoftext|>",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "<|im_start|>",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "<|im_end|>",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "<|object_ref_start|>",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"4": {
|
| 36 |
+
"content": "<|object_ref_end|>",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
},
|
| 43 |
+
"5": {
|
| 44 |
+
"content": "<|box_start|>",
|
| 45 |
+
"lstrip": false,
|
| 46 |
+
"normalized": false,
|
| 47 |
+
"rstrip": false,
|
| 48 |
+
"single_word": false,
|
| 49 |
+
"special": true
|
| 50 |
+
},
|
| 51 |
+
"6": {
|
| 52 |
+
"content": "<|box_end|>",
|
| 53 |
+
"lstrip": false,
|
| 54 |
+
"normalized": false,
|
| 55 |
+
"rstrip": false,
|
| 56 |
+
"single_word": false,
|
| 57 |
+
"special": true
|
| 58 |
+
},
|
| 59 |
+
"7": {
|
| 60 |
+
"content": "<|quad_start|>",
|
| 61 |
+
"lstrip": false,
|
| 62 |
+
"normalized": false,
|
| 63 |
+
"rstrip": false,
|
| 64 |
+
"single_word": false,
|
| 65 |
+
"special": true
|
| 66 |
+
},
|
| 67 |
+
"8": {
|
| 68 |
+
"content": "<|quad_end|>",
|
| 69 |
+
"lstrip": false,
|
| 70 |
+
"normalized": false,
|
| 71 |
+
"rstrip": false,
|
| 72 |
+
"single_word": false,
|
| 73 |
+
"special": true
|
| 74 |
+
},
|
| 75 |
+
"9": {
|
| 76 |
+
"content": "<|vision_start|>",
|
| 77 |
+
"lstrip": false,
|
| 78 |
+
"normalized": false,
|
| 79 |
+
"rstrip": false,
|
| 80 |
+
"single_word": false,
|
| 81 |
+
"special": true
|
| 82 |
+
},
|
| 83 |
+
"10": {
|
| 84 |
+
"content": "<|vision_end|>",
|
| 85 |
+
"lstrip": false,
|
| 86 |
+
"normalized": false,
|
| 87 |
+
"rstrip": false,
|
| 88 |
+
"single_word": false,
|
| 89 |
+
"special": true
|
| 90 |
+
},
|
| 91 |
+
"11": {
|
| 92 |
+
"content": "<|vision_pad|>",
|
| 93 |
+
"lstrip": false,
|
| 94 |
+
"normalized": false,
|
| 95 |
+
"rstrip": false,
|
| 96 |
+
"single_word": false,
|
| 97 |
+
"special": true
|
| 98 |
+
},
|
| 99 |
+
"12": {
|
| 100 |
+
"content": "<|image_pad|>",
|
| 101 |
+
"lstrip": false,
|
| 102 |
+
"normalized": false,
|
| 103 |
+
"rstrip": false,
|
| 104 |
+
"single_word": false,
|
| 105 |
+
"special": true
|
| 106 |
+
},
|
| 107 |
+
"13": {
|
| 108 |
+
"content": "<|video_pad|>",
|
| 109 |
+
"lstrip": false,
|
| 110 |
+
"normalized": false,
|
| 111 |
+
"rstrip": false,
|
| 112 |
+
"single_word": false,
|
| 113 |
+
"special": true
|
| 114 |
+
},
|
| 115 |
+
"14": {
|
| 116 |
+
"content": "<tool_call>",
|
| 117 |
+
"lstrip": false,
|
| 118 |
+
"normalized": false,
|
| 119 |
+
"rstrip": false,
|
| 120 |
+
"single_word": false,
|
| 121 |
+
"special": true
|
| 122 |
+
},
|
| 123 |
+
"15": {
|
| 124 |
+
"content": "</tool_call>",
|
| 125 |
+
"lstrip": false,
|
| 126 |
+
"normalized": false,
|
| 127 |
+
"rstrip": false,
|
| 128 |
+
"single_word": false,
|
| 129 |
+
"special": true
|
| 130 |
+
},
|
| 131 |
+
"16": {
|
| 132 |
+
"content": "<|fim_prefix|>",
|
| 133 |
+
"lstrip": false,
|
| 134 |
+
"normalized": false,
|
| 135 |
+
"rstrip": false,
|
| 136 |
+
"single_word": false,
|
| 137 |
+
"special": true
|
| 138 |
+
},
|
| 139 |
+
"17": {
|
| 140 |
+
"content": "<|fim_middle|>",
|
| 141 |
+
"lstrip": false,
|
| 142 |
+
"normalized": false,
|
| 143 |
+
"rstrip": false,
|
| 144 |
+
"single_word": false,
|
| 145 |
+
"special": true
|
| 146 |
+
},
|
| 147 |
+
"18": {
|
| 148 |
+
"content": "<|fim_suffix|>",
|
| 149 |
+
"lstrip": false,
|
| 150 |
+
"normalized": false,
|
| 151 |
+
"rstrip": false,
|
| 152 |
+
"single_word": false,
|
| 153 |
+
"special": true
|
| 154 |
+
},
|
| 155 |
+
"19": {
|
| 156 |
+
"content": "<|fim_pad|>",
|
| 157 |
+
"lstrip": false,
|
| 158 |
+
"normalized": false,
|
| 159 |
+
"rstrip": false,
|
| 160 |
+
"single_word": false,
|
| 161 |
+
"special": true
|
| 162 |
+
},
|
| 163 |
+
"20": {
|
| 164 |
+
"content": "<|repo_name|>",
|
| 165 |
+
"lstrip": false,
|
| 166 |
+
"normalized": false,
|
| 167 |
+
"rstrip": false,
|
| 168 |
+
"single_word": false,
|
| 169 |
+
"special": true
|
| 170 |
+
},
|
| 171 |
+
"21": {
|
| 172 |
+
"content": "<|file_sep|>",
|
| 173 |
+
"lstrip": false,
|
| 174 |
+
"normalized": false,
|
| 175 |
+
"rstrip": false,
|
| 176 |
+
"single_word": false,
|
| 177 |
+
"special": true
|
| 178 |
+
},
|
| 179 |
+
"22": {
|
| 180 |
+
"content": "<tool_response>",
|
| 181 |
+
"lstrip": false,
|
| 182 |
+
"normalized": false,
|
| 183 |
+
"rstrip": false,
|
| 184 |
+
"single_word": false,
|
| 185 |
+
"special": true
|
| 186 |
+
},
|
| 187 |
+
"23": {
|
| 188 |
+
"content": "</tool_response>",
|
| 189 |
+
"lstrip": false,
|
| 190 |
+
"normalized": false,
|
| 191 |
+
"rstrip": false,
|
| 192 |
+
"single_word": false,
|
| 193 |
+
"special": true
|
| 194 |
+
},
|
| 195 |
+
"24": {
|
| 196 |
+
"content": "<think>",
|
| 197 |
+
"lstrip": false,
|
| 198 |
+
"normalized": false,
|
| 199 |
+
"rstrip": false,
|
| 200 |
+
"single_word": false,
|
| 201 |
+
"special": true
|
| 202 |
+
},
|
| 203 |
+
"25": {
|
| 204 |
+
"content": "</think>",
|
| 205 |
+
"lstrip": false,
|
| 206 |
+
"normalized": false,
|
| 207 |
+
"rstrip": false,
|
| 208 |
+
"single_word": false,
|
| 209 |
+
"special": true
|
| 210 |
+
}
|
| 211 |
+
},
|
| 212 |
+
"bos_token": "<|endoftext|>",
|
| 213 |
+
"clean_up_tokenization_spaces": false,
|
| 214 |
+
"eos_token": "<|endoftext|>",
|
| 215 |
+
"extra_special_tokens": {},
|
| 216 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 217 |
+
"pad_token": "<|endoftext|>",
|
| 218 |
+
"tokenizer_class": "PreTrainedTokenizerFast"
|
| 219 |
+
}
|