Text Generation
Transformers
Safetensors
qwen3
feature-extraction
conversational
custom_code
text-generation-inference
Instructions to use nvidia/Efficient-DLM-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Efficient-DLM-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Efficient-DLM-4B", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("nvidia/Efficient-DLM-4B", trust_remote_code=True) model = AutoModel.from_pretrained("nvidia/Efficient-DLM-4B", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nvidia/Efficient-DLM-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Efficient-DLM-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Efficient-DLM-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/Efficient-DLM-4B
- SGLang
How to use nvidia/Efficient-DLM-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nvidia/Efficient-DLM-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Efficient-DLM-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nvidia/Efficient-DLM-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Efficient-DLM-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/Efficient-DLM-4B with Docker Model Runner:
docker model run hf.co/nvidia/Efficient-DLM-4B
Upload model
Browse files- README.md +3 -0
- config.json +50 -0
- configuration_nvrdiff.py +250 -0
- generation_config.json +5 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +406 -0
- modeling_nvrdiff.py +534 -0
README.md
CHANGED
|
@@ -1 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
Coming soon.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
{}
|
| 3 |
+
---
|
| 4 |
Coming soon.
|
config.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"adaptive_mask_rate": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DiffEncoderModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"attn_implementation": "sdpa",
|
| 9 |
+
"auto_map": {
|
| 10 |
+
"AutoConfig": "configuration_nvrdiff.NVRDiffConfig",
|
| 11 |
+
"AutoModel": "modeling_nvrdiff.DiffEncoderModel"
|
| 12 |
+
},
|
| 13 |
+
"block_size": 32,
|
| 14 |
+
"diff_loss_weight": 1,
|
| 15 |
+
"disable_qk_norm": false,
|
| 16 |
+
"dlm_arch": "encoder",
|
| 17 |
+
"dlm_paradigm": "bidirectional",
|
| 18 |
+
"dlm_type": "dream",
|
| 19 |
+
"enforce_mask": false,
|
| 20 |
+
"head_dim": 128,
|
| 21 |
+
"hidden_act": "silu",
|
| 22 |
+
"hidden_size": 2560,
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"intermediate_size": 9728,
|
| 25 |
+
"intl_mask": false,
|
| 26 |
+
"mask_token_id": 151662,
|
| 27 |
+
"max_position_embeddings": 32768,
|
| 28 |
+
"max_window_layers": 28,
|
| 29 |
+
"model_type": "qwen3",
|
| 30 |
+
"multi_sampling": null,
|
| 31 |
+
"num_ar_layers": 0,
|
| 32 |
+
"num_attention_heads": 32,
|
| 33 |
+
"num_diffusion_layers": 0,
|
| 34 |
+
"num_hidden_layers": 36,
|
| 35 |
+
"num_key_value_heads": 8,
|
| 36 |
+
"prefix_ratio": 0.8,
|
| 37 |
+
"random_length_prob": 0,
|
| 38 |
+
"rms_norm_eps": 1e-06,
|
| 39 |
+
"rope_scaling": null,
|
| 40 |
+
"rope_theta": 1000000,
|
| 41 |
+
"seq_length": 1024,
|
| 42 |
+
"sliding_window": null,
|
| 43 |
+
"tie_word_embeddings": true,
|
| 44 |
+
"tok_mask_half_life_ratio": null,
|
| 45 |
+
"torch_dtype": "bfloat16",
|
| 46 |
+
"transformers_version": "4.52.2",
|
| 47 |
+
"use_cache": false,
|
| 48 |
+
"use_sliding_window": false,
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""Qwen3 model configuration"""
|
| 16 |
+
|
| 17 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 18 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 19 |
+
from transformers.utils import logging
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class NVRDiffConfig(PretrainedConfig):
|
| 26 |
+
r"""
|
| 27 |
+
This is the configuration class to store the configuration of a [`Qwen3Model`]. It is used to instantiate a
|
| 28 |
+
Qwen3 model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 29 |
+
with the defaults will yield a similar configuration to that of
|
| 30 |
+
Qwen3-8B [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B).
|
| 31 |
+
|
| 32 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 33 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
vocab_size (`int`, *optional*, defaults to 151936):
|
| 38 |
+
Vocabulary size of the Qwen3 model. Defines the number of different tokens that can be represented by the
|
| 39 |
+
`inputs_ids` passed when calling [`Qwen3Model`]
|
| 40 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 41 |
+
Dimension of the hidden representations.
|
| 42 |
+
intermediate_size (`int`, *optional*, defaults to 22016):
|
| 43 |
+
Dimension of the MLP representations.
|
| 44 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 45 |
+
Number of hidden layers in the Transformer encoder.
|
| 46 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 47 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 48 |
+
num_key_value_heads (`int`, *optional*, defaults to 32):
|
| 49 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 50 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 51 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 52 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 53 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 54 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
|
| 55 |
+
head_dim (`int`, *optional*, defaults to 128):
|
| 56 |
+
The attention head dimension.
|
| 57 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 58 |
+
The non-linear activation function (function or string) in the decoder.
|
| 59 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 60 |
+
The maximum sequence length that this model might ever be used with.
|
| 61 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 62 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 63 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 64 |
+
The epsilon used by the rms normalization layers.
|
| 65 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 66 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 67 |
+
relevant if `config.is_decoder=True`.
|
| 68 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 69 |
+
Whether the model's input and output word embeddings should be tied.
|
| 70 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 71 |
+
The base period of the RoPE embeddings.
|
| 72 |
+
rope_scaling (`Dict`, *optional*):
|
| 73 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
| 74 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
| 75 |
+
accordingly.
|
| 76 |
+
Expected contents:
|
| 77 |
+
`rope_type` (`str`):
|
| 78 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
| 79 |
+
'llama3'], with 'default' being the original RoPE implementation.
|
| 80 |
+
`factor` (`float`, *optional*):
|
| 81 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
| 82 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
| 83 |
+
original maximum pre-trained length.
|
| 84 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
| 85 |
+
Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
|
| 86 |
+
pretraining.
|
| 87 |
+
`attention_factor` (`float`, *optional*):
|
| 88 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
| 89 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
| 90 |
+
`factor` field to infer the suggested value.
|
| 91 |
+
`beta_fast` (`float`, *optional*):
|
| 92 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
| 93 |
+
ramp function. If unspecified, it defaults to 32.
|
| 94 |
+
`beta_slow` (`float`, *optional*):
|
| 95 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
| 96 |
+
ramp function. If unspecified, it defaults to 1.
|
| 97 |
+
`short_factor` (`List[float]`, *optional*):
|
| 98 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
| 99 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 100 |
+
size divided by the number of attention heads divided by 2
|
| 101 |
+
`long_factor` (`List[float]`, *optional*):
|
| 102 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
| 103 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 104 |
+
size divided by the number of attention heads divided by 2
|
| 105 |
+
`low_freq_factor` (`float`, *optional*):
|
| 106 |
+
Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
|
| 107 |
+
`high_freq_factor` (`float`, *optional*):
|
| 108 |
+
Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
|
| 109 |
+
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
| 110 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 111 |
+
use_sliding_window (`bool`, *optional*, defaults to `False`):
|
| 112 |
+
Whether to use sliding window attention.
|
| 113 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
| 114 |
+
Sliding window attention (SWA) window size. If not specified, will default to `4096`.
|
| 115 |
+
max_window_layers (`int`, *optional*, defaults to 28):
|
| 116 |
+
The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
|
| 117 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 118 |
+
The dropout ratio for the attention probabilities.
|
| 119 |
+
|
| 120 |
+
```python
|
| 121 |
+
>>> from transformers import Qwen3Model, Qwen3Config
|
| 122 |
+
|
| 123 |
+
>>> # Initializing a Qwen3 style configuration
|
| 124 |
+
>>> configuration = Qwen3Config()
|
| 125 |
+
|
| 126 |
+
>>> # Initializing a model from the Qwen3-8B style configuration
|
| 127 |
+
>>> model = Qwen3Model(configuration)
|
| 128 |
+
|
| 129 |
+
>>> # Accessing the model configuration
|
| 130 |
+
>>> configuration = model.config
|
| 131 |
+
```"""
|
| 132 |
+
|
| 133 |
+
model_type = "qwen3"
|
| 134 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 135 |
+
|
| 136 |
+
# Default tensor parallel plan for base model `Qwen3`
|
| 137 |
+
base_model_tp_plan = {
|
| 138 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 139 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 140 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 141 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 142 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 143 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 144 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 145 |
+
}
|
| 146 |
+
base_model_pp_plan = {
|
| 147 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 148 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 149 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
def __init__(
|
| 153 |
+
self,
|
| 154 |
+
vocab_size=151936,
|
| 155 |
+
hidden_size=4096,
|
| 156 |
+
intermediate_size=22016,
|
| 157 |
+
num_hidden_layers=32,
|
| 158 |
+
num_attention_heads=32,
|
| 159 |
+
num_key_value_heads=32,
|
| 160 |
+
head_dim=128,
|
| 161 |
+
hidden_act="silu",
|
| 162 |
+
max_position_embeddings=32768,
|
| 163 |
+
initializer_range=0.02,
|
| 164 |
+
rms_norm_eps=1e-6,
|
| 165 |
+
use_cache=True,
|
| 166 |
+
tie_word_embeddings=False,
|
| 167 |
+
rope_theta=10000.0,
|
| 168 |
+
rope_scaling=None,
|
| 169 |
+
attention_bias=False,
|
| 170 |
+
use_sliding_window=False,
|
| 171 |
+
sliding_window=4096,
|
| 172 |
+
max_window_layers=28,
|
| 173 |
+
attention_dropout=0.0,
|
| 174 |
+
attn_implementation="sdpa",
|
| 175 |
+
seq_length=1024,
|
| 176 |
+
mask_token_id=-1,
|
| 177 |
+
dlm_type='llada',
|
| 178 |
+
random_length_prob=None,
|
| 179 |
+
num_ar_layers=4,
|
| 180 |
+
num_diffusion_layers=4,
|
| 181 |
+
diff_loss_weight=1,
|
| 182 |
+
enforce_mask=False,
|
| 183 |
+
prefix_ratio=0.8,
|
| 184 |
+
dlm_paradigm='bidirectional',
|
| 185 |
+
dlm_arch='encoder',
|
| 186 |
+
block_size=32,
|
| 187 |
+
disable_qk_norm=False,
|
| 188 |
+
intl_mask=False,
|
| 189 |
+
tok_mask_half_life_ratio=None,
|
| 190 |
+
adaptive_mask_rate=False,
|
| 191 |
+
multi_sampling=None,
|
| 192 |
+
**kwargs,
|
| 193 |
+
):
|
| 194 |
+
self.vocab_size = vocab_size
|
| 195 |
+
self.max_position_embeddings = max_position_embeddings
|
| 196 |
+
self.hidden_size = hidden_size
|
| 197 |
+
self.intermediate_size = intermediate_size
|
| 198 |
+
self.num_hidden_layers = num_hidden_layers
|
| 199 |
+
self.num_attention_heads = num_attention_heads
|
| 200 |
+
self.use_sliding_window = use_sliding_window
|
| 201 |
+
self.sliding_window = sliding_window # we check `use_sliding_window` in the modeling code
|
| 202 |
+
self.max_window_layers = max_window_layers
|
| 203 |
+
|
| 204 |
+
# for backward compatibility
|
| 205 |
+
if num_key_value_heads is None:
|
| 206 |
+
num_key_value_heads = num_attention_heads
|
| 207 |
+
|
| 208 |
+
self.num_key_value_heads = num_key_value_heads
|
| 209 |
+
self.head_dim = head_dim
|
| 210 |
+
self.hidden_act = hidden_act
|
| 211 |
+
self.initializer_range = initializer_range
|
| 212 |
+
self.rms_norm_eps = rms_norm_eps
|
| 213 |
+
self.use_cache = use_cache
|
| 214 |
+
self.rope_theta = rope_theta
|
| 215 |
+
self.rope_scaling = rope_scaling
|
| 216 |
+
self.attention_bias = attention_bias
|
| 217 |
+
self.attention_dropout = attention_dropout
|
| 218 |
+
# Validate the correctness of rotary position embeddings parameters
|
| 219 |
+
# BC: if there is a 'type' field, move it to 'rope_type'.
|
| 220 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 221 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 222 |
+
rope_config_validation(self)
|
| 223 |
+
|
| 224 |
+
self.attn_implementation = attn_implementation
|
| 225 |
+
self.seq_length = seq_length
|
| 226 |
+
|
| 227 |
+
self.mask_token_id = mask_token_id
|
| 228 |
+
self.dlm_type = dlm_type
|
| 229 |
+
self.random_length_prob = random_length_prob
|
| 230 |
+
self.num_ar_layers = num_ar_layers
|
| 231 |
+
self.num_diffusion_layers = num_diffusion_layers
|
| 232 |
+
self.diff_loss_weight = diff_loss_weight
|
| 233 |
+
self.enforce_mask = enforce_mask
|
| 234 |
+
self.prefix_ratio = prefix_ratio
|
| 235 |
+
self.dlm_paradigm = dlm_paradigm
|
| 236 |
+
self.dlm_arch = dlm_arch
|
| 237 |
+
self.block_size = block_size
|
| 238 |
+
self.disable_qk_norm = disable_qk_norm
|
| 239 |
+
self.intl_mask = intl_mask
|
| 240 |
+
self.tok_mask_half_life_ratio = tok_mask_half_life_ratio
|
| 241 |
+
self.adaptive_mask_rate = adaptive_mask_rate
|
| 242 |
+
self.multi_sampling = multi_sampling
|
| 243 |
+
|
| 244 |
+
super().__init__(
|
| 245 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 246 |
+
**kwargs,
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
__all__ = ["Qwen3Config"]
|
generation_config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"transformers_version": "4.52.2",
|
| 4 |
+
"use_cache": false
|
| 5 |
+
}
|
model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:070b9c33863b6d0c88d32d6eafb9d7f284cb677b510debe5a042aee70334ba93
|
| 3 |
+
size 4967215816
|
model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ca94ec5acb0b8dbf845d54c04f8c72c99c15a84ee14ff30b1cc0f3878b148d62
|
| 3 |
+
size 3855679488
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 8822848512
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"diffusion_head.weight": "model-00002-of-00002.safetensors",
|
| 7 |
+
"encoder.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 8 |
+
"encoder.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"encoder.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"encoder.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"encoder.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"encoder.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"encoder.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"encoder.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"encoder.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"encoder.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"encoder.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"encoder.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"encoder.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"encoder.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"encoder.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"encoder.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"encoder.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"encoder.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"encoder.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"encoder.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"encoder.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"encoder.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"encoder.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"encoder.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"encoder.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"encoder.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"encoder.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"encoder.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"encoder.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"encoder.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"encoder.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"encoder.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"encoder.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"encoder.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"encoder.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"encoder.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"encoder.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"encoder.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"encoder.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"encoder.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"encoder.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"encoder.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"encoder.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"encoder.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"encoder.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"encoder.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"encoder.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"encoder.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"encoder.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"encoder.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"encoder.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"encoder.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"encoder.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"encoder.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"encoder.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"encoder.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"encoder.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"encoder.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"encoder.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"encoder.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"encoder.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"encoder.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"encoder.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"encoder.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"encoder.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"encoder.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"encoder.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"encoder.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"encoder.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"encoder.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"encoder.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"encoder.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"encoder.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"encoder.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"encoder.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"encoder.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"encoder.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"encoder.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"encoder.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"encoder.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"encoder.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"encoder.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"encoder.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"encoder.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"encoder.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"encoder.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 93 |
+
"encoder.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 94 |
+
"encoder.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 95 |
+
"encoder.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 96 |
+
"encoder.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"encoder.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 98 |
+
"encoder.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 99 |
+
"encoder.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 100 |
+
"encoder.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 101 |
+
"encoder.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 102 |
+
"encoder.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 103 |
+
"encoder.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 104 |
+
"encoder.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 105 |
+
"encoder.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 106 |
+
"encoder.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 107 |
+
"encoder.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 108 |
+
"encoder.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 109 |
+
"encoder.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 110 |
+
"encoder.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 111 |
+
"encoder.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 112 |
+
"encoder.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 113 |
+
"encoder.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 114 |
+
"encoder.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 115 |
+
"encoder.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 116 |
+
"encoder.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 117 |
+
"encoder.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 118 |
+
"encoder.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 119 |
+
"encoder.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 120 |
+
"encoder.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 121 |
+
"encoder.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 122 |
+
"encoder.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 123 |
+
"encoder.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 124 |
+
"encoder.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 125 |
+
"encoder.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 126 |
+
"encoder.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 127 |
+
"encoder.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 128 |
+
"encoder.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 129 |
+
"encoder.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 130 |
+
"encoder.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 131 |
+
"encoder.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 132 |
+
"encoder.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 133 |
+
"encoder.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 134 |
+
"encoder.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 135 |
+
"encoder.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 136 |
+
"encoder.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 137 |
+
"encoder.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 138 |
+
"encoder.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 139 |
+
"encoder.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 140 |
+
"encoder.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 141 |
+
"encoder.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 142 |
+
"encoder.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 143 |
+
"encoder.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 144 |
+
"encoder.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 145 |
+
"encoder.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 146 |
+
"encoder.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"encoder.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"encoder.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"encoder.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"encoder.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"encoder.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 152 |
+
"encoder.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 153 |
+
"encoder.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 154 |
+
"encoder.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 155 |
+
"encoder.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 156 |
+
"encoder.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 157 |
+
"encoder.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 158 |
+
"encoder.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 159 |
+
"encoder.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 160 |
+
"encoder.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 161 |
+
"encoder.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 162 |
+
"encoder.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 163 |
+
"encoder.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 164 |
+
"encoder.layers.21.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 165 |
+
"encoder.layers.21.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 166 |
+
"encoder.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 167 |
+
"encoder.layers.21.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 168 |
+
"encoder.layers.21.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 169 |
+
"encoder.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 170 |
+
"encoder.layers.21.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 171 |
+
"encoder.layers.21.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 172 |
+
"encoder.layers.21.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 173 |
+
"encoder.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 174 |
+
"encoder.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 175 |
+
"encoder.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 176 |
+
"encoder.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 177 |
+
"encoder.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 178 |
+
"encoder.layers.22.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 179 |
+
"encoder.layers.22.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 180 |
+
"encoder.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 181 |
+
"encoder.layers.22.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 182 |
+
"encoder.layers.22.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 183 |
+
"encoder.layers.22.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 184 |
+
"encoder.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 185 |
+
"encoder.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 186 |
+
"encoder.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 187 |
+
"encoder.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 188 |
+
"encoder.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 189 |
+
"encoder.layers.23.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 190 |
+
"encoder.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 191 |
+
"encoder.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 192 |
+
"encoder.layers.23.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 193 |
+
"encoder.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 194 |
+
"encoder.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 195 |
+
"encoder.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 196 |
+
"encoder.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 197 |
+
"encoder.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 198 |
+
"encoder.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 199 |
+
"encoder.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 200 |
+
"encoder.layers.24.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 201 |
+
"encoder.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 202 |
+
"encoder.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 203 |
+
"encoder.layers.24.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 204 |
+
"encoder.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 205 |
+
"encoder.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 206 |
+
"encoder.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 207 |
+
"encoder.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 208 |
+
"encoder.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 209 |
+
"encoder.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 210 |
+
"encoder.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 211 |
+
"encoder.layers.25.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 212 |
+
"encoder.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 213 |
+
"encoder.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 214 |
+
"encoder.layers.25.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 215 |
+
"encoder.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 216 |
+
"encoder.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 217 |
+
"encoder.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 218 |
+
"encoder.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 219 |
+
"encoder.layers.26.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 220 |
+
"encoder.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 221 |
+
"encoder.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 222 |
+
"encoder.layers.26.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 223 |
+
"encoder.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 224 |
+
"encoder.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 225 |
+
"encoder.layers.26.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 226 |
+
"encoder.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 227 |
+
"encoder.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 228 |
+
"encoder.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 229 |
+
"encoder.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 230 |
+
"encoder.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 231 |
+
"encoder.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 232 |
+
"encoder.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 233 |
+
"encoder.layers.27.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 234 |
+
"encoder.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 235 |
+
"encoder.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 236 |
+
"encoder.layers.27.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 237 |
+
"encoder.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 238 |
+
"encoder.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 239 |
+
"encoder.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 240 |
+
"encoder.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 241 |
+
"encoder.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 242 |
+
"encoder.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 243 |
+
"encoder.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 244 |
+
"encoder.layers.28.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 245 |
+
"encoder.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 246 |
+
"encoder.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 247 |
+
"encoder.layers.28.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 248 |
+
"encoder.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 249 |
+
"encoder.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 250 |
+
"encoder.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 251 |
+
"encoder.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 252 |
+
"encoder.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 253 |
+
"encoder.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 254 |
+
"encoder.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 255 |
+
"encoder.layers.29.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 256 |
+
"encoder.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 257 |
+
"encoder.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 258 |
+
"encoder.layers.29.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 259 |
+
"encoder.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 260 |
+
"encoder.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 261 |
+
"encoder.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 262 |
+
"encoder.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 263 |
+
"encoder.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 264 |
+
"encoder.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 265 |
+
"encoder.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 266 |
+
"encoder.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 267 |
+
"encoder.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 268 |
+
"encoder.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 269 |
+
"encoder.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 270 |
+
"encoder.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 271 |
+
"encoder.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 272 |
+
"encoder.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 273 |
+
"encoder.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 274 |
+
"encoder.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 275 |
+
"encoder.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 276 |
+
"encoder.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 277 |
+
"encoder.layers.30.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 278 |
+
"encoder.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 279 |
+
"encoder.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 280 |
+
"encoder.layers.30.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 281 |
+
"encoder.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 282 |
+
"encoder.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 283 |
+
"encoder.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 284 |
+
"encoder.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 285 |
+
"encoder.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 286 |
+
"encoder.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 287 |
+
"encoder.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 288 |
+
"encoder.layers.31.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 289 |
+
"encoder.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 290 |
+
"encoder.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 291 |
+
"encoder.layers.31.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 292 |
+
"encoder.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 293 |
+
"encoder.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 294 |
+
"encoder.layers.32.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 295 |
+
"encoder.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 296 |
+
"encoder.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 297 |
+
"encoder.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 298 |
+
"encoder.layers.32.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 299 |
+
"encoder.layers.32.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 300 |
+
"encoder.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 301 |
+
"encoder.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 302 |
+
"encoder.layers.32.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 303 |
+
"encoder.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 304 |
+
"encoder.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 305 |
+
"encoder.layers.33.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 306 |
+
"encoder.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 307 |
+
"encoder.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 308 |
+
"encoder.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 309 |
+
"encoder.layers.33.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 310 |
+
"encoder.layers.33.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 311 |
+
"encoder.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 312 |
+
"encoder.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 313 |
+
"encoder.layers.33.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 314 |
+
"encoder.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 315 |
+
"encoder.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 316 |
+
"encoder.layers.34.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 317 |
+
"encoder.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 318 |
+
"encoder.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 319 |
+
"encoder.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 320 |
+
"encoder.layers.34.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 321 |
+
"encoder.layers.34.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 322 |
+
"encoder.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 323 |
+
"encoder.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 324 |
+
"encoder.layers.34.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 325 |
+
"encoder.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 326 |
+
"encoder.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 327 |
+
"encoder.layers.35.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 328 |
+
"encoder.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 329 |
+
"encoder.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
|
| 330 |
+
"encoder.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 331 |
+
"encoder.layers.35.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 332 |
+
"encoder.layers.35.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
|
| 333 |
+
"encoder.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
|
| 334 |
+
"encoder.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 335 |
+
"encoder.layers.35.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
|
| 336 |
+
"encoder.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
|
| 337 |
+
"encoder.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
|
| 338 |
+
"encoder.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 339 |
+
"encoder.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 340 |
+
"encoder.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 341 |
+
"encoder.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 342 |
+
"encoder.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 343 |
+
"encoder.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 344 |
+
"encoder.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 345 |
+
"encoder.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 346 |
+
"encoder.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 347 |
+
"encoder.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 348 |
+
"encoder.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 349 |
+
"encoder.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 350 |
+
"encoder.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 351 |
+
"encoder.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 352 |
+
"encoder.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 353 |
+
"encoder.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 354 |
+
"encoder.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 355 |
+
"encoder.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 356 |
+
"encoder.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 357 |
+
"encoder.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 358 |
+
"encoder.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 359 |
+
"encoder.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 360 |
+
"encoder.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 361 |
+
"encoder.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 362 |
+
"encoder.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 363 |
+
"encoder.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 364 |
+
"encoder.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 365 |
+
"encoder.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 366 |
+
"encoder.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 367 |
+
"encoder.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 368 |
+
"encoder.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 369 |
+
"encoder.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 370 |
+
"encoder.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 371 |
+
"encoder.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 372 |
+
"encoder.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 373 |
+
"encoder.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 374 |
+
"encoder.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 375 |
+
"encoder.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 376 |
+
"encoder.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 377 |
+
"encoder.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 378 |
+
"encoder.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 379 |
+
"encoder.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 380 |
+
"encoder.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 381 |
+
"encoder.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 382 |
+
"encoder.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 383 |
+
"encoder.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 384 |
+
"encoder.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 385 |
+
"encoder.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 386 |
+
"encoder.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 387 |
+
"encoder.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 388 |
+
"encoder.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 389 |
+
"encoder.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 390 |
+
"encoder.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 391 |
+
"encoder.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 392 |
+
"encoder.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 393 |
+
"encoder.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 394 |
+
"encoder.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 395 |
+
"encoder.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 396 |
+
"encoder.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 397 |
+
"encoder.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 398 |
+
"encoder.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
|
| 399 |
+
"encoder.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 400 |
+
"encoder.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 401 |
+
"encoder.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
|
| 402 |
+
"encoder.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 403 |
+
"encoder.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 404 |
+
"encoder.norm.weight": "model-00002-of-00002.safetensors"
|
| 405 |
+
}
|
| 406 |
+
}
|
modeling_nvrdiff.py
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
from typing import Callable, Optional, Tuple, Union
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn.functional as F
|
| 7 |
+
from torch import nn
|
| 8 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 9 |
+
|
| 10 |
+
from torchtitan.models.qwen3.modeling_qwen3 import Qwen3Config, Qwen3Model, Qwen3PreTrainedModel, Qwen3Attention, apply_rotary_pos_emb, repeat_kv
|
| 11 |
+
|
| 12 |
+
from torch.nn.attention.flex_attention import flex_attention, create_block_mask
|
| 13 |
+
|
| 14 |
+
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
|
| 15 |
+
|
| 16 |
+
from transformers.processing_utils import Unpack
|
| 17 |
+
|
| 18 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 19 |
+
|
| 20 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 21 |
+
|
| 22 |
+
from transformers.generation import GenerationMixin
|
| 23 |
+
|
| 24 |
+
import math
|
| 25 |
+
|
| 26 |
+
# @torch.compile(dynamic=True, mode="reduce-overhead")
|
| 27 |
+
# @torch.compile(mode="default")
|
| 28 |
+
# @torch.compile(fullgraph=True, mode="reduce-overhead", dynamic=False)
|
| 29 |
+
@torch.compile(fullgraph=True, mode="max-autotune-no-cudagraphs", dynamic=False)
|
| 30 |
+
def fused_flex_attention(q, k, v, block_mask=None):
|
| 31 |
+
return flex_attention(q, k, v, block_mask=block_mask)
|
| 32 |
+
|
| 33 |
+
# with reference to https://github.com/pytorch-labs/attention-gym/blob/main/examples/flex_attn.ipynb
|
| 34 |
+
class Qwen3FlexAttention(Qwen3Attention):
|
| 35 |
+
def __init__(self, *args, **kwargs):
|
| 36 |
+
super().__init__(*args, **kwargs)
|
| 37 |
+
|
| 38 |
+
self.max_seq_length = self.config.seq_length
|
| 39 |
+
self.prefix_len_orig = int(self.config.seq_length * self.config.prefix_ratio)
|
| 40 |
+
self.block_size_orig = self.config.block_size
|
| 41 |
+
|
| 42 |
+
if self.config.dlm_paradigm == 'bidirectional':
|
| 43 |
+
self.bidirectional_mask = self.compute_block_mask(mode='bidirectional')
|
| 44 |
+
elif self.config.dlm_paradigm == 'prefix_bidirectional':
|
| 45 |
+
self.prefix_bidirectional_mask = self.compute_block_mask(mode='prefix_bidirectional', prefix_len=self.prefix_len_orig)
|
| 46 |
+
elif self.config.dlm_paradigm == 'efficient_block_diff':
|
| 47 |
+
self.efficient_block_diff_mask = self.compute_block_mask(mode='efficient_block_diff', block_size=self.block_size_orig)
|
| 48 |
+
elif self.config.dlm_paradigm == 'block_diff':
|
| 49 |
+
self.block_diff_mask = self.compute_block_mask(mode='block_diff', block_size=self.block_size_orig)
|
| 50 |
+
else:
|
| 51 |
+
raise ValueError(f"Unknown attention mode: {self.config.dlm_paradigm}")
|
| 52 |
+
|
| 53 |
+
self.prefix_len = self.prefix_len_orig
|
| 54 |
+
self.block_size = self.block_size_orig
|
| 55 |
+
self.mode = 'bidirectional'
|
| 56 |
+
|
| 57 |
+
import torch._dynamo.config as dcfg
|
| 58 |
+
dcfg.cache_size_limit = 512
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def set_attention_mode(self, mode, prefix_len=None, block_size=None):
|
| 62 |
+
self.mode = mode
|
| 63 |
+
self.prefix_len = prefix_len
|
| 64 |
+
self.block_size = block_size
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def compute_block_mask(self, mode, prefix_len=None, q_len=None, block_size=None):
|
| 68 |
+
|
| 69 |
+
def bidirectional_mask(b, h, q, kv):
|
| 70 |
+
return (q >= kv) | (q < kv)
|
| 71 |
+
|
| 72 |
+
def prefix_bidirectional_mask(prefix_len, b, h, q, kv):
|
| 73 |
+
return (kv <= prefix_len) | (q >= prefix_len)
|
| 74 |
+
|
| 75 |
+
def efficient_block_diff_mask(block_size, b, h, q, kv):
|
| 76 |
+
return (q // block_size) >= (kv // block_size)
|
| 77 |
+
|
| 78 |
+
def block_diff_mask(block_size, b, h, q_idx, kv_idx, n):
|
| 79 |
+
"""
|
| 80 |
+
Constructs the specialized block diffusion attention mask for training
|
| 81 |
+
composed of three masks:
|
| 82 |
+
- **Block Diagonal Mask (M_BD)**: Self-attention within noised blocks
|
| 83 |
+
- **Offset Block Causal Mask (M_OBC)**: Cross-attention for conditional context
|
| 84 |
+
- **Block Causal Mask (M_BC)**: Attention to update x0
|
| 85 |
+
|
| 86 |
+
Args:
|
| 87 |
+
b, h: Batch and head indices (ignored for mask logic).
|
| 88 |
+
q_idx, kv_idx: Query and Key indices.
|
| 89 |
+
seq_len: Total sequence length.
|
| 90 |
+
block_size: Defines the block structure.
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
A boolean attention mask.
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
# Indicate whether token belongs to xt or x0
|
| 97 |
+
x0_flag_q = (q_idx >= n)
|
| 98 |
+
x0_flag_kv = (kv_idx >= n)
|
| 99 |
+
|
| 100 |
+
# Compute block indices
|
| 101 |
+
block_q = torch.where(x0_flag_q == 1,
|
| 102 |
+
(q_idx - n) // block_size,
|
| 103 |
+
q_idx // block_size)
|
| 104 |
+
block_kv = torch.where(x0_flag_kv == 1,
|
| 105 |
+
(kv_idx - n) // block_size,
|
| 106 |
+
kv_idx // block_size)
|
| 107 |
+
|
| 108 |
+
# **1. Block Diagonal Mask (M_BD) **
|
| 109 |
+
block_diagonal = (block_q == block_kv) & (x0_flag_q == x0_flag_kv)
|
| 110 |
+
|
| 111 |
+
# **2. Offset Block-Causal Mask (M_OBC) **
|
| 112 |
+
offset_block_causal = (
|
| 113 |
+
(block_q > block_kv)
|
| 114 |
+
& (x0_flag_kv == 1)
|
| 115 |
+
& (x0_flag_q == 0)
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# **3. Block-Causal Mask (M_BC) **
|
| 119 |
+
block_causal = (block_q >= block_kv) & (x0_flag_kv == 1) & (x0_flag_q == 1)
|
| 120 |
+
|
| 121 |
+
# **4. Combine Masks **
|
| 122 |
+
return block_diagonal | offset_block_causal | block_causal
|
| 123 |
+
|
| 124 |
+
if mode == 'bidirectional':
|
| 125 |
+
attn_mask = bidirectional_mask
|
| 126 |
+
elif mode == 'prefix_bidirectional':
|
| 127 |
+
assert prefix_len is not None
|
| 128 |
+
attn_mask = lambda b, h, q, kv: prefix_bidirectional_mask(prefix_len, b, h, q, kv)
|
| 129 |
+
elif mode == 'efficient_block_diff':
|
| 130 |
+
assert block_size is not None
|
| 131 |
+
attn_mask = lambda b, h, q, kv: efficient_block_diff_mask(block_size, b, h, q, kv)
|
| 132 |
+
elif mode == 'block_diff':
|
| 133 |
+
assert block_size is not None
|
| 134 |
+
attn_mask = lambda b, h, q, kv: block_diff_mask(block_size, b, h, q, kv, self.max_seq_length)
|
| 135 |
+
else:
|
| 136 |
+
raise ValueError(f"Unknown attention mode: {mode}")
|
| 137 |
+
|
| 138 |
+
if q_len is not None:
|
| 139 |
+
Q_LEN = q_len
|
| 140 |
+
else:
|
| 141 |
+
if mode == 'block_diff':
|
| 142 |
+
Q_LEN = self.max_seq_length * 2
|
| 143 |
+
else:
|
| 144 |
+
Q_LEN = self.max_seq_length
|
| 145 |
+
|
| 146 |
+
block_mask = create_block_mask(
|
| 147 |
+
attn_mask, B=None, H=None, Q_LEN=Q_LEN, KV_LEN=Q_LEN
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
return block_mask
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def forward(
|
| 154 |
+
self,
|
| 155 |
+
hidden_states: torch.Tensor,
|
| 156 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 157 |
+
attention_mask: Optional[torch.Tensor],
|
| 158 |
+
past_key_value: Optional[Cache] = None,
|
| 159 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 160 |
+
is_training: bool = True,
|
| 161 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 162 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 163 |
+
bsz, q_len, _ = hidden_states.size()
|
| 164 |
+
input_shape = hidden_states.shape[:-1]
|
| 165 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 166 |
+
|
| 167 |
+
query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 168 |
+
key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 169 |
+
value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 170 |
+
|
| 171 |
+
cos, sin = position_embeddings
|
| 172 |
+
|
| 173 |
+
if self.mode == 'block_diff' and is_training:
|
| 174 |
+
# Split query and key states in half along sequence length dimension
|
| 175 |
+
q1, q2 = query_states.chunk(2, dim=2)
|
| 176 |
+
k1, k2 = key_states.chunk(2, dim=2)
|
| 177 |
+
|
| 178 |
+
# Apply RoPE independently to each half
|
| 179 |
+
q1, k1 = apply_rotary_pos_emb(q1, k1, cos, sin)
|
| 180 |
+
q2, k2 = apply_rotary_pos_emb(q2, k2, cos, sin)
|
| 181 |
+
|
| 182 |
+
# Recombine the halves
|
| 183 |
+
query_states = torch.cat([q1, q2], dim=2)
|
| 184 |
+
key_states = torch.cat([k1, k2], dim=2)
|
| 185 |
+
else:
|
| 186 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 187 |
+
|
| 188 |
+
if past_key_value is not None:
|
| 189 |
+
# sin and cos are specific to RoPE models; cache_position needed for the static cache
|
| 190 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 191 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 192 |
+
|
| 193 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 194 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 195 |
+
|
| 196 |
+
if self.mode == 'bidirectional':
|
| 197 |
+
if q_len != self.bidirectional_mask.shape[-2]:
|
| 198 |
+
block_mask = self.compute_block_mask(mode='bidirectional', prefix_len=self.prefix_len, q_len=q_len)
|
| 199 |
+
else:
|
| 200 |
+
block_mask = self.bidirectional_mask
|
| 201 |
+
|
| 202 |
+
elif self.mode == 'prefix_bidirectional':
|
| 203 |
+
if self.prefix_len != self.prefix_len_orig or q_len != self.prefix_bidirectional_mask.shape[-2]:
|
| 204 |
+
block_mask = self.compute_block_mask(mode='prefix_bidirectional', prefix_len=self.prefix_len, q_len=q_len)
|
| 205 |
+
|
| 206 |
+
# print('create new block mask length for:',self.prefix_len)
|
| 207 |
+
# print(f"Block mask shape: {block_mask.shape}")
|
| 208 |
+
# print("Block mask pattern:")
|
| 209 |
+
# print(block_mask)
|
| 210 |
+
else:
|
| 211 |
+
block_mask = self.prefix_bidirectional_mask
|
| 212 |
+
elif self.mode == 'efficient_block_diff':
|
| 213 |
+
if self.block_size != self.block_size_orig or q_len != self.efficient_block_diff_mask.shape[-2]:
|
| 214 |
+
block_mask = self.compute_block_mask(mode='efficient_block_diff', block_size=self.block_size, q_len=q_len)
|
| 215 |
+
else:
|
| 216 |
+
block_mask = self.efficient_block_diff_mask
|
| 217 |
+
elif self.mode == 'block_diff':
|
| 218 |
+
if self.block_size != self.block_size_orig or q_len != self.block_diff_mask.shape[-2]:
|
| 219 |
+
block_mask = self.compute_block_mask(mode='block_diff', block_size=self.block_size, q_len=q_len)
|
| 220 |
+
else:
|
| 221 |
+
block_mask = self.block_diff_mask
|
| 222 |
+
else:
|
| 223 |
+
raise ValueError(f"Unknown attention mode: {self.mode}")
|
| 224 |
+
|
| 225 |
+
attn_output = fused_flex_attention(query_states, key_states, value_states, block_mask=block_mask)
|
| 226 |
+
attn_output = attn_output.transpose(1, 2).reshape(*input_shape, -1).contiguous()
|
| 227 |
+
|
| 228 |
+
attn_output = self.o_proj(attn_output)
|
| 229 |
+
|
| 230 |
+
return attn_output, None
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def gumbel_topk(log_w: torch.Tensor, k: int) -> torch.Tensor:
|
| 234 |
+
"""Return a Bool mask of length len(log_w) with exactly k True."""
|
| 235 |
+
g = -torch.log(-torch.log(torch.rand_like(log_w) + 1e-9) + 1e-9)
|
| 236 |
+
topk = torch.topk(log_w + g, k).indices
|
| 237 |
+
mask = torch.zeros_like(log_w, dtype=torch.bool)
|
| 238 |
+
mask[topk] = True
|
| 239 |
+
return mask
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
class DiffEncoderModel(Qwen3PreTrainedModel, GenerationMixin):
|
| 243 |
+
"""
|
| 244 |
+
A single model with:
|
| 245 |
+
- a bidirectional encoder + diffusion‐LM head over A
|
| 246 |
+
- a causal decoder + LM head over B, conditioned on F_A
|
| 247 |
+
"""
|
| 248 |
+
|
| 249 |
+
def __init__(self, config: Qwen3Config):
|
| 250 |
+
super().__init__(config)
|
| 251 |
+
|
| 252 |
+
self.mask_token_id = config.mask_token_id
|
| 253 |
+
|
| 254 |
+
diffusion_config = copy.deepcopy(config)
|
| 255 |
+
diffusion_config.diffusion_lm = True
|
| 256 |
+
|
| 257 |
+
if config.dlm_paradigm in ['prefix_bidirectional', 'efficient_block_diff', 'block_diff']:
|
| 258 |
+
diffusion_config.attn_class = Qwen3FlexAttention
|
| 259 |
+
elif config.dlm_paradigm in ['bidirectional', 'autoregressive']:
|
| 260 |
+
diffusion_config.attn_class = Qwen3Attention
|
| 261 |
+
|
| 262 |
+
if config.dlm_paradigm == 'autoregressive':
|
| 263 |
+
diffusion_config.diffusion_lm = False
|
| 264 |
+
else:
|
| 265 |
+
raise ValueError(f"Unsupported DLM paradigm: {config.dlm_paradigm}")
|
| 266 |
+
|
| 267 |
+
self.encoder = Qwen3Model(diffusion_config)
|
| 268 |
+
self.diffusion_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 269 |
+
self.vocab_size = config.vocab_size
|
| 270 |
+
|
| 271 |
+
self.post_init()
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def forward_process(self, input_ids, eps=1e-3, block_size=None, loss_mask=None):
|
| 275 |
+
b, l = input_ids.shape
|
| 276 |
+
device = input_ids.device
|
| 277 |
+
|
| 278 |
+
t = torch.rand(b, device=device)
|
| 279 |
+
|
| 280 |
+
p_mask = (1 - eps) * t + eps # shape: (b,)
|
| 281 |
+
p_mask = p_mask[:, None].expand(-1, l) # shape: (b, l)
|
| 282 |
+
|
| 283 |
+
masked_indices = torch.rand((b, l), device=device) < p_mask
|
| 284 |
+
|
| 285 |
+
if loss_mask is not None:
|
| 286 |
+
masked_indices[loss_mask == 0] = 0
|
| 287 |
+
|
| 288 |
+
noisy_batch = torch.where(masked_indices, self.mask_token_id, input_ids)
|
| 289 |
+
|
| 290 |
+
return noisy_batch, masked_indices, p_mask
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def forward_process_exp(
|
| 294 |
+
self,
|
| 295 |
+
input_ids: torch.Tensor,
|
| 296 |
+
eps: float = 1e-3,
|
| 297 |
+
block_size: int | None = None,
|
| 298 |
+
half_life_ratio: float = 0.25, # λ = ln 2 / (half_life_ratio·L)
|
| 299 |
+
loss_mask: Optional[torch.Tensor] = None,
|
| 300 |
+
):
|
| 301 |
+
"""
|
| 302 |
+
Two-stage corruption with optional per-block sampling.
|
| 303 |
+
|
| 304 |
+
• Stage 1: m ~ U(eps, 1) → k = round(m · len) (exact budget).
|
| 305 |
+
• Stage 2: sample exactly k positions with weights
|
| 306 |
+
w_i(m) = exp[ λ · (1−m) · i ] (late-heavy when m→0,
|
| 307 |
+
uniform when m→1).
|
| 308 |
+
|
| 309 |
+
If `block_size` is given, the procedure is run *independently*
|
| 310 |
+
inside each contiguous block of that length (last block may be shorter).
|
| 311 |
+
When block_size is provided, m is sampled per-block and p_mask is per-block.
|
| 312 |
+
|
| 313 |
+
Args
|
| 314 |
+
----
|
| 315 |
+
input_ids : (B, L) LongTensor
|
| 316 |
+
eps : minimum corruption ratio
|
| 317 |
+
block_size: if not None, operate block-wise with per-block m sampling
|
| 318 |
+
half_life_ratio : controls steepness when m→0
|
| 319 |
+
"""
|
| 320 |
+
B, L = input_ids.shape
|
| 321 |
+
device = input_ids.device
|
| 322 |
+
dtype = torch.float32
|
| 323 |
+
|
| 324 |
+
masked_indices = torch.zeros((B, L), dtype=torch.bool, device=device)
|
| 325 |
+
p_mask = torch.zeros((B, L), dtype=dtype, device=device)
|
| 326 |
+
|
| 327 |
+
# ---------- Stage 1 & 2: whole-sentence or block-wise -------------------
|
| 328 |
+
for b in range(B):
|
| 329 |
+
if block_size is None:
|
| 330 |
+
# ---------- Per-batch sampling (original behavior) ----------
|
| 331 |
+
m = eps + (1.0 - eps) * torch.rand(1, device=device).item() # scalar
|
| 332 |
+
k_tot = int(round(m * L))
|
| 333 |
+
k_tot = max(1, min(k_tot, L)) # clamp to [1, L]
|
| 334 |
+
|
| 335 |
+
# Fill p_mask for this batch
|
| 336 |
+
p_mask[b, :] = m
|
| 337 |
+
|
| 338 |
+
slope = 1.0 - m # ∈ [0,1]; 0 ⇒ uniform, 1 ⇒ late-heavy
|
| 339 |
+
|
| 340 |
+
# ------- single pool over the whole sentence -------------
|
| 341 |
+
lam_base = math.log(2.0) / (half_life_ratio * L) # base decay rate (λ when slope=1)
|
| 342 |
+
|
| 343 |
+
pos = torch.arange(L, device=device, dtype=dtype)
|
| 344 |
+
log_w = (lam_base * slope * pos).clone()
|
| 345 |
+
|
| 346 |
+
masked_indices[b] = gumbel_topk(log_w, k_tot)
|
| 347 |
+
|
| 348 |
+
else:
|
| 349 |
+
# ---------- Per-block sampling ----------
|
| 350 |
+
num_blocks = math.ceil(L / block_size)
|
| 351 |
+
lam_base = math.log(2.0) / (half_life_ratio * block_size) # base decay rate (λ when slope=1)
|
| 352 |
+
|
| 353 |
+
for blk in range(num_blocks):
|
| 354 |
+
start = blk * block_size
|
| 355 |
+
end = min((blk + 1) * block_size, L)
|
| 356 |
+
blk_len = end - start
|
| 357 |
+
|
| 358 |
+
# Sample m per block
|
| 359 |
+
m_blk = eps + (1.0 - eps) * torch.rand(1, device=device).item()
|
| 360 |
+
|
| 361 |
+
# Fill p_mask for this block
|
| 362 |
+
p_mask[b, start:end] = m_blk
|
| 363 |
+
|
| 364 |
+
# per-block budget
|
| 365 |
+
k_blk = int(round(m_blk * blk_len))
|
| 366 |
+
k_blk = max(0, min(k_blk, blk_len))
|
| 367 |
+
if k_blk == 0:
|
| 368 |
+
continue
|
| 369 |
+
|
| 370 |
+
slope = 1.0 - m_blk # ∈ [0,1]; 0 ⇒ uniform, 1 ⇒ late-heavy
|
| 371 |
+
|
| 372 |
+
pos = torch.arange(blk_len, device=device, dtype=dtype)
|
| 373 |
+
log_w = lam_base * slope * pos
|
| 374 |
+
|
| 375 |
+
blk_mask = gumbel_topk(log_w, k_blk)
|
| 376 |
+
masked_indices[b, start:end] = blk_mask
|
| 377 |
+
|
| 378 |
+
if loss_mask is not None:
|
| 379 |
+
masked_indices[loss_mask == 0] = 0
|
| 380 |
+
|
| 381 |
+
noisy_batch = torch.where(masked_indices, self.mask_token_id, input_ids)
|
| 382 |
+
return noisy_batch, masked_indices, p_mask
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def forward(
|
| 386 |
+
self,
|
| 387 |
+
input_ids: torch.LongTensor,
|
| 388 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 389 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 390 |
+
labels: Optional[torch.LongTensor] = None,
|
| 391 |
+
split_len: Optional[int] = None,
|
| 392 |
+
past_key_values: Optional[Cache] = None,
|
| 393 |
+
block_size: Optional[int] = None,
|
| 394 |
+
block_diff_ppl: bool = False,
|
| 395 |
+
eps: float = 1e-3,
|
| 396 |
+
is_teacher: bool = False,
|
| 397 |
+
masked_indices: Optional[torch.Tensor] = None,
|
| 398 |
+
p_mask: Optional[torch.Tensor] = None,
|
| 399 |
+
loss_mask: Optional[torch.Tensor] = None,
|
| 400 |
+
**kwargs,
|
| 401 |
+
) -> CausalLMOutputWithPast:
|
| 402 |
+
|
| 403 |
+
batch_size, seq_len = input_ids.shape
|
| 404 |
+
|
| 405 |
+
if self.config.dlm_paradigm == 'bidirectional':
|
| 406 |
+
if labels is not None and torch.rand(1) < self.config.random_length_prob:
|
| 407 |
+
random_length = torch.randint(2, input_ids.shape[1] + 1, (1,))
|
| 408 |
+
input_ids = input_ids[:, :random_length]
|
| 409 |
+
labels = labels[:, :random_length]
|
| 410 |
+
|
| 411 |
+
if attention_mask is not None:
|
| 412 |
+
attention_mask = attention_mask[:, :random_length]
|
| 413 |
+
if position_ids is not None:
|
| 414 |
+
position_ids = position_ids[:, :random_length]
|
| 415 |
+
|
| 416 |
+
elif self.config.dlm_paradigm == 'prefix_bidirectional':
|
| 417 |
+
if labels is not None and split_len is None:
|
| 418 |
+
if torch.rand(1) < self.config.random_length_prob:
|
| 419 |
+
split_len = torch.randint(1, seq_len//64, (1,)).item() * 64 ## [64, seq_len] divisible by 64
|
| 420 |
+
else:
|
| 421 |
+
split_len = int(seq_len * self.config.prefix_ratio)
|
| 422 |
+
|
| 423 |
+
elif self.config.dlm_paradigm == 'efficient_block_diff':
|
| 424 |
+
if labels is not None and block_size is None:
|
| 425 |
+
if torch.rand(1) < self.config.random_length_prob:
|
| 426 |
+
block_size = torch.randint(1, 8, (1,)).item() * 4 ## [4, 32] divisible by 4
|
| 427 |
+
else:
|
| 428 |
+
block_size = self.config.block_size
|
| 429 |
+
|
| 430 |
+
elif self.config.dlm_paradigm == 'block_diff':
|
| 431 |
+
if labels is not None and block_size is None:
|
| 432 |
+
if torch.rand(1) < self.config.random_length_prob:
|
| 433 |
+
block_size = torch.randint(1, 8, (1,)).item() * 4 ## [4, 32] divisible by 4
|
| 434 |
+
else:
|
| 435 |
+
block_size = self.config.block_size
|
| 436 |
+
|
| 437 |
+
if labels is not None and self.config.dlm_paradigm != 'autoregressive':
|
| 438 |
+
if masked_indices is not None:
|
| 439 |
+
assert p_mask is not None
|
| 440 |
+
|
| 441 |
+
if loss_mask is not None:
|
| 442 |
+
masked_indices[loss_mask == 0] = 0
|
| 443 |
+
|
| 444 |
+
noisy_inputs = torch.where(masked_indices, self.mask_token_id, input_ids)
|
| 445 |
+
|
| 446 |
+
else:
|
| 447 |
+
if self.config.tok_mask_half_life_ratio is not None:
|
| 448 |
+
noisy_inputs, masked_indices, p_mask = self.forward_process_exp(input_ids, eps=eps, block_size=block_size, half_life_ratio=self.config.tok_mask_half_life_ratio, loss_mask=loss_mask)
|
| 449 |
+
else:
|
| 450 |
+
noisy_inputs, masked_indices, p_mask = self.forward_process(input_ids, eps=eps, block_size=block_size, loss_mask=loss_mask)
|
| 451 |
+
|
| 452 |
+
else:
|
| 453 |
+
noisy_inputs = input_ids
|
| 454 |
+
masked_indices = None
|
| 455 |
+
p_mask = None
|
| 456 |
+
|
| 457 |
+
if self.config.dlm_paradigm in ['prefix_bidirectional', 'efficient_block_diff', 'block_diff']:
|
| 458 |
+
for layer in self.encoder.layers:
|
| 459 |
+
if hasattr(layer.self_attn, 'set_attention_mode'):
|
| 460 |
+
layer.self_attn.set_attention_mode(self.config.dlm_paradigm, prefix_len=split_len, block_size=block_size)
|
| 461 |
+
|
| 462 |
+
input_ids_len = noisy_inputs.shape[1]
|
| 463 |
+
if labels is not None and self.config.dlm_paradigm == 'block_diff':
|
| 464 |
+
if position_ids is None:
|
| 465 |
+
position_ids = torch.arange(input_ids_len, device=noisy_inputs.device).unsqueeze(0)
|
| 466 |
+
noisy_inputs = torch.cat([noisy_inputs, input_ids], dim=1)
|
| 467 |
+
|
| 468 |
+
if block_diff_ppl:
|
| 469 |
+
if position_ids is None:
|
| 470 |
+
position_ids = torch.arange(input_ids_len // 2, device=noisy_inputs.device).unsqueeze(0)
|
| 471 |
+
|
| 472 |
+
enc_out = self.encoder(
|
| 473 |
+
past_key_values=past_key_values,
|
| 474 |
+
input_ids=noisy_inputs,
|
| 475 |
+
attention_mask=attention_mask,
|
| 476 |
+
position_ids=position_ids,
|
| 477 |
+
is_training=(labels is not None) or (block_diff_ppl),
|
| 478 |
+
**kwargs,
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
logits = self.diffusion_head(enc_out.last_hidden_state) # (batch, len_B, vocab)
|
| 482 |
+
|
| 483 |
+
if labels is not None and self.config.dlm_paradigm == 'block_diff':
|
| 484 |
+
logits = logits[:, :input_ids_len]
|
| 485 |
+
|
| 486 |
+
loss = None
|
| 487 |
+
if labels is not None:
|
| 488 |
+
if self.config.dlm_paradigm == 'autoregressive':
|
| 489 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 490 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 491 |
+
|
| 492 |
+
if loss_mask is None:
|
| 493 |
+
loss_fct = CrossEntropyLoss()
|
| 494 |
+
shift_logits = shift_logits.view(-1, shift_logits.size(-1))
|
| 495 |
+
shift_labels = shift_labels.view(-1)
|
| 496 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 497 |
+
|
| 498 |
+
else:
|
| 499 |
+
loss_mask = loss_mask[..., 1:].contiguous()
|
| 500 |
+
|
| 501 |
+
loss_fct = CrossEntropyLoss(reduction='none')
|
| 502 |
+
shift_logits = shift_logits.view(-1, shift_logits.size(-1))
|
| 503 |
+
shift_labels = shift_labels.view(-1)
|
| 504 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 505 |
+
|
| 506 |
+
token_losses = loss_fct(shift_logits, shift_labels)
|
| 507 |
+
|
| 508 |
+
loss = token_losses[loss_mask].sum() / loss_mask.sum()
|
| 509 |
+
|
| 510 |
+
else:
|
| 511 |
+
# Handle DREAM vs LLADA style losses
|
| 512 |
+
if hasattr(self.config, 'dlm_type') and self.config.dlm_type == 'dream':
|
| 513 |
+
logits = logits[..., :-1, :].contiguous()
|
| 514 |
+
labels = labels[..., 1:].contiguous()
|
| 515 |
+
masked_indices = masked_indices[:, 1:]
|
| 516 |
+
p_mask = p_mask[:, 1:]
|
| 517 |
+
|
| 518 |
+
# Calculate token-wise cross entropy loss for masked positions in B
|
| 519 |
+
token_loss = torch.nn.functional.cross_entropy(
|
| 520 |
+
logits[masked_indices],
|
| 521 |
+
labels[masked_indices],
|
| 522 |
+
reduction='none'
|
| 523 |
+
) / p_mask[masked_indices]
|
| 524 |
+
|
| 525 |
+
loss = token_loss.sum() / masked_indices.sum()
|
| 526 |
+
|
| 527 |
+
return CausalLMOutputWithPast(
|
| 528 |
+
loss=loss if not is_teacher else logits,
|
| 529 |
+
logits=logits,
|
| 530 |
+
past_key_values=enc_out.past_key_values,
|
| 531 |
+
hidden_states=None,
|
| 532 |
+
attentions=None,
|
| 533 |
+
)
|
| 534 |
+
|