SituatedEmbedding commited on
Commit
dfa1e77
·
verified ·
1 Parent(s): 301c24a

Publish QRRanker-BRIGHT model, tokenizer and model code

Browse files
.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
README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # QRRanker-BRIGHT
2
+
3
+ QRRanker-BRIGHT is trained using the `reasonrank-131k` training data and
4
+ provides the full model parameters, tokenizer and custom model implementation
5
+ used for BRIGHT reranking evaluation.
6
+
7
+ Related dataset: [ReasonRank 13k](https://huggingface.co/datasets/liuwenhan/reasonrank_data_13k).
8
+
9
+ For the main QRRanker method, QR heads, scoring mechanism and model details,
10
+ please refer to [MindscapeRAG/QRRanker](https://huggingface.co/MindscapeRAG/QRRanker).
11
+ The implementation and hardware notes below are specific to this BRIGHT release.
12
+
13
+ ## Full Model, Without Layer Truncation
14
+
15
+ **This release retains all 36 transformer layers and the complete model
16
+ parameters. It does not truncate upper layers that contain no selected QR
17
+ heads.**
18
+
19
+ Unlike the reference
20
+ [`modeling_qwen3_qr.py`](https://huggingface.co/MindscapeRAG/QRRanker/blob/main/modeling_qwen3_qr.py)
21
+ implementation, QRRanker-BRIGHT does not truncate upper layers without selected
22
+ QR heads. All 36 layers remain in the model and are executed during the forward
23
+ pass. Selecting the top-16 QR heads for scoring does not remove the other layers
24
+ or their parameters.
25
+
26
+ No additional QRRanker-specific computational optimizations have been
27
+ applied to this release. The evaluation uses FP16, FlashAttention 2 and
28
+ tensor parallelism, but does not introduce layer
29
+ pruning, early exit or selective-layer scoring optimizations. As a result,
30
+ the full-model implementation can consume substantial GPU memory and
31
+ computation, particularly with long inputs and 100 candidate documents.
32
+
33
+ ## Tested Hardware
34
+
35
+ BRIGHT evaluation was run on:
36
+
37
+ - **4 NVIDIA A100 GPUs, each with 40 GB of memory** (TP=4).
38
+ - **8 NVIDIA A100 GPUs, each with 40 GB of memory** (TP=8).
39
+
40
+ Runs with fewer than four GPUs have not been tested.
41
+
42
+ ## Evaluation Code and Data
43
+
44
+ **Both the BRIGHT evaluation data and evaluation code are available in
45
+ [`SituatedEmbedding/BRIGHT-DIVER-4B-Top100-QRRanker`](https://huggingface.co/datasets/SituatedEmbedding/BRIGHT-DIVER-4B-Top100-QRRanker).**
46
+
47
+ The dataset repository includes the original BRIGHT queries and labels,
48
+ DIVER-Retriever-4B top-100 candidate pools, evaluation scripts and reference
49
+ results. See its
50
+ [README](https://huggingface.co/datasets/SituatedEmbedding/BRIGHT-DIVER-4B-Top100-QRRanker/blob/main/README.md)
51
+ for download instructions, environment requirements, data format and evaluation
52
+ commands.
53
+
54
+ Evaluation uses the original BRIGHT queries, top-16 QR heads, a maximum input
55
+ length of 65,536 tokens and no calibration. This is fixed-pool reranking,
56
+ not full-corpus retrieval.
57
+
58
+ ## Loading
59
+
60
+ Model code is provided in `custom_modeling_qwen3_new.py` and
61
+ `custom_cache_new.py`. The evaluation explicitly imports the custom
62
+ `Qwen3Model` and calls `Qwen3Model.from_pretrained(...)`.
63
+
64
+ Use the evaluation entry point or explicitly import the custom model class.
65
+ The model configuration does not register an `auto_map`, so
66
+ `AutoModel.from_pretrained(..., trust_remote_code=True)` alone does not select
67
+ the custom QRRanker implementation.
added_tokens.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|box_end|>": 151649,
9
+ "<|box_start|>": 151648,
10
+ "<|endoftext|>": 151643,
11
+ "<|file_sep|>": 151664,
12
+ "<|fim_middle|>": 151660,
13
+ "<|fim_pad|>": 151662,
14
+ "<|fim_prefix|>": 151659,
15
+ "<|fim_suffix|>": 151661,
16
+ "<|im_end|>": 151645,
17
+ "<|im_start|>": 151644,
18
+ "<|image_pad|>": 151655,
19
+ "<|object_ref_end|>": 151647,
20
+ "<|object_ref_start|>": 151646,
21
+ "<|quad_end|>": 151651,
22
+ "<|quad_start|>": 151650,
23
+ "<|repo_name|>": 151663,
24
+ "<|video_pad|>": 151656,
25
+ "<|vision_end|>": 151653,
26
+ "<|vision_pad|>": 151654,
27
+ "<|vision_start|>": 151652
28
+ }
chat_template.jinja ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if message.content is string %}
27
+ {%- set content = message.content %}
28
+ {%- else %}
29
+ {%- set content = '' %}
30
+ {%- endif %}
31
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
33
+ {%- elif message.role == "assistant" %}
34
+ {%- set reasoning_content = '' %}
35
+ {%- if message.reasoning_content is string %}
36
+ {%- set reasoning_content = message.reasoning_content %}
37
+ {%- else %}
38
+ {%- if '</think>' in content %}
39
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+ {%- if loop.index0 > ns.last_query_index %}
44
+ {%- if loop.last or (not loop.last and reasoning_content) %}
45
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
46
+ {%- else %}
47
+ {{- '<|im_start|>' + message.role + '\n' + content }}
48
+ {%- endif %}
49
+ {%- else %}
50
+ {{- '<|im_start|>' + message.role + '\n' + content }}
51
+ {%- endif %}
52
+ {%- if message.tool_calls %}
53
+ {%- for tool_call in message.tool_calls %}
54
+ {%- if (loop.first and content) or (not loop.first) %}
55
+ {{- '\n' }}
56
+ {%- endif %}
57
+ {%- if tool_call.function %}
58
+ {%- set tool_call = tool_call.function %}
59
+ {%- endif %}
60
+ {{- '<tool_call>\n{"name": "' }}
61
+ {{- tool_call.name }}
62
+ {{- '", "arguments": ' }}
63
+ {%- if tool_call.arguments is string %}
64
+ {{- tool_call.arguments }}
65
+ {%- else %}
66
+ {{- tool_call.arguments | tojson }}
67
+ {%- endif %}
68
+ {{- '}\n</tool_call>' }}
69
+ {%- endfor %}
70
+ {%- endif %}
71
+ {{- '<|im_end|>\n' }}
72
+ {%- elif message.role == "tool" %}
73
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
+ {{- '<|im_start|>user' }}
75
+ {%- endif %}
76
+ {{- '\n<tool_response>\n' }}
77
+ {{- content }}
78
+ {{- '\n</tool_response>' }}
79
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
+ {{- '<|im_end|>\n' }}
81
+ {%- endif %}
82
+ {%- endif %}
83
+ {%- endfor %}
84
+ {%- if add_generation_prompt %}
85
+ {{- '<|im_start|>assistant\n' }}
86
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "head_dim": 128,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 2560,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 9728,
14
+ "layer_types": [
15
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention"
51
+ ],
52
+ "max_position_embeddings": 262144,
53
+ "max_window_layers": 36,
54
+ "model_type": "qwen3",
55
+ "num_attention_heads": 32,
56
+ "num_hidden_layers": 36,
57
+ "num_key_value_heads": 8,
58
+ "rms_norm_eps": 1e-06,
59
+ "rope_scaling": null,
60
+ "rope_theta": 5000000,
61
+ "sliding_window": null,
62
+ "tie_word_embeddings": true,
63
+ "torch_dtype": "bfloat16",
64
+ "transformers_version": "4.53.0",
65
+ "use_cache": true,
66
+ "use_sliding_window": false,
67
+ "vocab_size": 151936
68
+ }
custom_cache_new.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Dict, Optional, Tuple
2
+ from transformers.cache_utils import DynamicCache
3
+ import torch
4
+
5
+
6
+ class DynamicCacheWithQuery(DynamicCache):
7
+ """
8
+ Cache class used for QRRetriever;
9
+ LJN: put the query states in the cache_kwargs to keep the same signature as DynamicCache
10
+ LJN: please take the query states from the cache_kwargs
11
+ """
12
+
13
+ def __init__(self, query_indices=[]) -> None:
14
+ super().__init__()
15
+ self._query_indices = query_indices # indices for query vectors to save
16
+ self.query_cache = []
17
+
18
+ def update(
19
+ self,
20
+ key_states: torch.Tensor,
21
+ value_states: torch.Tensor,
22
+ layer_idx: int,
23
+ cache_kwargs: Optional[Dict[str, Any]] = None,
24
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
25
+ """
26
+ Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`.
27
+
28
+ Parameters:
29
+ key_states (`torch.Tensor`):
30
+ The new key states to cache.
31
+ value_states (`torch.Tensor`):
32
+ The new value states to cache.
33
+ layer_idx (`int`):
34
+ The index of the layer to cache the states for.
35
+ cache_kwargs (`Dict[str, Any]`, `optional`):
36
+ Additional arguments for the cache subclass. No additional arguments are used in `DynamicCache`.
37
+
38
+ Return:
39
+ A tuple containing the updated key and value states.
40
+ """
41
+ # Update the number of seen tokens
42
+ if layer_idx == 0:
43
+ self._seen_tokens += key_states.shape[-2]
44
+
45
+ # Update the cache
46
+ if key_states is not None:
47
+ if len(self.key_cache) <= layer_idx:
48
+ # There may be skipped layers, fill them with empty lists
49
+ for _ in range(len(self.key_cache), layer_idx):
50
+ self.key_cache.append(torch.tensor([]))
51
+ self.value_cache.append(torch.tensor([]))
52
+ self.key_cache.append(key_states)
53
+ self.value_cache.append(value_states)
54
+ elif (
55
+ not self.key_cache[layer_idx].numel() # prefers not t.numel() to len(t) == 0 to export the model
56
+ ): # fills previously skipped layers; checking for tensor causes errors
57
+ self.key_cache[layer_idx] = key_states
58
+ self.value_cache[layer_idx] = value_states
59
+ else:
60
+ self.key_cache[layer_idx] = torch.cat([self.key_cache[layer_idx], key_states], dim=-2)
61
+ self.value_cache[layer_idx] = torch.cat([self.value_cache[layer_idx], value_states], dim=-2)
62
+
63
+ if cache_kwargs is not None:
64
+ query_states = cache_kwargs.get("query_states", None)
65
+ else:
66
+ query_states = None
67
+ if query_states is not None:
68
+ if len(self.query_cache) <= layer_idx:
69
+ self.query_cache.append(query_states)
70
+ else:
71
+ self.query_cache[layer_idx] = torch.cat([self.query_cache[layer_idx], query_states], dim=-2)
72
+ return self.key_cache[layer_idx], self.value_cache[layer_idx]
73
+
74
+ @classmethod
75
+ def from_legacy_cache_with_query_indices(cls, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, query_indices = []) -> "DynamicCache":
76
+ """Converts a cache in the legacy cache format into an equivalent `DynamicCache`. Used for
77
+ backward compatibility."""
78
+ cache = cls(query_indices=query_indices)
79
+ if past_key_values is not None:
80
+ for layer_idx in range(len(past_key_values)):
81
+ key_states, value_states = past_key_values[layer_idx]
82
+ cache.update(key_states, value_states, layer_idx)
83
+ return cache
custom_modeling_qwen3_new.py ADDED
@@ -0,0 +1,895 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/qwen3/modular_qwen3.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_qwen3.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+ from functools import partial
23
+ from typing import Callable, Optional, Tuple, Union
24
+
25
+ import torch
26
+ from torch import nn
27
+
28
+ from transformers.activations import ACT2FN
29
+ from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
30
+
31
+ from custom_cache_new import DynamicCacheWithQuery
32
+
33
+ from transformers.generation import GenerationMixin
34
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
35
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
36
+ from transformers.modeling_outputs import (
37
+ BaseModelOutputWithPast,
38
+ CausalLMOutputWithPast,
39
+ QuestionAnsweringModelOutput,
40
+ SequenceClassifierOutputWithPast,
41
+ TokenClassifierOutput,
42
+ )
43
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
44
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
45
+ from transformers.processing_utils import Unpack
46
+ from transformers.utils import (
47
+ LossKwargs,
48
+ add_code_sample_docstrings,
49
+ add_start_docstrings,
50
+ add_start_docstrings_to_model_forward,
51
+ can_return_tuple,
52
+ logging,
53
+ replace_return_docstrings,
54
+ )
55
+ from transformers.utils.deprecation import deprecate_kwarg
56
+ from transformers.models.qwen3.configuration_qwen3 import Qwen3Config
57
+
58
+
59
+ logger = logging.get_logger(__name__)
60
+
61
+ _CHECKPOINT_FOR_DOC = "Qwen/Qwen3-8B"
62
+ _CONFIG_FOR_DOC = "Qwen3Config"
63
+
64
+
65
+ class Qwen3RMSNorm(nn.Module):
66
+ def __init__(self, hidden_size, eps=1e-6):
67
+ """
68
+ Qwen3RMSNorm is equivalent to T5LayerNorm
69
+ """
70
+ super().__init__()
71
+ self.weight = nn.Parameter(torch.ones(hidden_size))
72
+ self.variance_epsilon = eps
73
+
74
+ def forward(self, hidden_states):
75
+ input_dtype = hidden_states.dtype
76
+ hidden_states = hidden_states.to(torch.float32)
77
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
78
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
79
+ return self.weight * hidden_states.to(input_dtype)
80
+
81
+ def extra_repr(self):
82
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
83
+
84
+
85
+ class Qwen3MLP(nn.Module):
86
+ def __init__(self, config):
87
+ super().__init__()
88
+ self.config = config
89
+ self.hidden_size = config.hidden_size
90
+ self.intermediate_size = config.intermediate_size
91
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
92
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
93
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
94
+ self.act_fn = ACT2FN[config.hidden_act]
95
+
96
+ def forward(self, x):
97
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
98
+ return down_proj
99
+
100
+
101
+ def rotate_half(x):
102
+ """Rotates half the hidden dims of the input."""
103
+ x1 = x[..., : x.shape[-1] // 2]
104
+ x2 = x[..., x.shape[-1] // 2 :]
105
+ return torch.cat((-x2, x1), dim=-1)
106
+
107
+
108
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
109
+ """Applies Rotary Position Embedding to the query and key tensors.
110
+
111
+ Args:
112
+ q (`torch.Tensor`): The query tensor.
113
+ k (`torch.Tensor`): The key tensor.
114
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
115
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
116
+ position_ids (`torch.Tensor`, *optional*):
117
+ Deprecated and unused.
118
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
119
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
120
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
121
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
122
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
123
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
124
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
125
+ Returns:
126
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
127
+ """
128
+ cos = cos.unsqueeze(unsqueeze_dim)
129
+ sin = sin.unsqueeze(unsqueeze_dim)
130
+ q_embed = (q * cos) + (rotate_half(q) * sin)
131
+ k_embed = (k * cos) + (rotate_half(k) * sin)
132
+ return q_embed, k_embed
133
+
134
+
135
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
136
+ """
137
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
138
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
139
+ """
140
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
141
+ if n_rep == 1:
142
+ return hidden_states
143
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
144
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
145
+
146
+
147
+ def eager_attention_forward(
148
+ module: nn.Module,
149
+ query: torch.Tensor,
150
+ key: torch.Tensor,
151
+ value: torch.Tensor,
152
+ attention_mask: Optional[torch.Tensor],
153
+ scaling: float,
154
+ dropout: float = 0.0,
155
+ **kwargs,
156
+ ):
157
+ key_states = repeat_kv(key, module.num_key_value_groups)
158
+ value_states = repeat_kv(value, module.num_key_value_groups)
159
+
160
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
161
+ if attention_mask is not None:
162
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
163
+ attn_weights = attn_weights + causal_mask
164
+
165
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
166
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
167
+ attn_output = torch.matmul(attn_weights, value_states)
168
+ attn_output = attn_output.transpose(1, 2).contiguous()
169
+
170
+ return attn_output, attn_weights
171
+
172
+
173
+ class Qwen3Attention(nn.Module):
174
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
175
+
176
+ def __init__(self, config: Qwen3Config, layer_idx: int):
177
+ super().__init__()
178
+ self.config = config
179
+ self.layer_idx = layer_idx
180
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
181
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
182
+ self.scaling = self.head_dim**-0.5
183
+ self.attention_dropout = config.attention_dropout
184
+ self.is_causal = True
185
+
186
+ self.q_proj = nn.Linear(
187
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
188
+ )
189
+ self.k_proj = nn.Linear(
190
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
191
+ )
192
+ self.v_proj = nn.Linear(
193
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
194
+ )
195
+ self.o_proj = nn.Linear(
196
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
197
+ )
198
+ self.q_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # unlike olmo, only on the head dim!
199
+ self.k_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # thus post q_norm does not need reshape
200
+ self.sliding_window = config.sliding_window
201
+ if not (
202
+ self.config.use_sliding_window
203
+ and getattr(self.config, "sliding_window", None) is not None
204
+ and self.layer_idx >= self.config.max_window_layers
205
+ ):
206
+ self.sliding_window = None
207
+
208
+ def forward(
209
+ self,
210
+ hidden_states: torch.Tensor,
211
+ position_embeddings: Tuple[torch.Tensor, torch.Tensor],
212
+ attention_mask: Optional[torch.Tensor],
213
+ past_key_value: Optional[Cache] = None,
214
+ cache_position: Optional[torch.LongTensor] = None,
215
+ **kwargs: Unpack[FlashAttentionKwargs],
216
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
217
+ input_shape = hidden_states.shape[:-1]
218
+ hidden_shape = (*input_shape, -1, self.head_dim)
219
+
220
+ query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
221
+ key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
222
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
223
+
224
+ cos, sin = position_embeddings
225
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
226
+
227
+ if past_key_value is not None:
228
+ if isinstance(past_key_value, DynamicCacheWithQuery):
229
+ # LJN: add query hidden states here
230
+ query_states_to_cache = query_states[:, :, past_key_value._query_indices, :]
231
+ cache_kwargs = {
232
+ "sin": sin, "cos": cos, "cache_position": cache_position, "query_states": query_states_to_cache}
233
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
234
+ else:
235
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
236
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
237
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
238
+
239
+ attention_interface: Callable = eager_attention_forward
240
+ if self.config._attn_implementation != "eager":
241
+ if self.config._attn_implementation == "sdpa" and kwargs.get("output_attentions", False):
242
+ logger.warning_once(
243
+ "`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to "
244
+ 'eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
245
+ )
246
+ else:
247
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
248
+
249
+ attn_output, attn_weights = attention_interface(
250
+ self,
251
+ query_states,
252
+ key_states,
253
+ value_states,
254
+ attention_mask,
255
+ dropout=0.0 if not self.training else self.attention_dropout,
256
+ scaling=self.scaling,
257
+ sliding_window=self.sliding_window, # diff with Llama
258
+ **kwargs,
259
+ )
260
+
261
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
262
+ attn_output = self.o_proj(attn_output)
263
+ return attn_output, attn_weights
264
+
265
+
266
+ class Qwen3DecoderLayer(nn.Module):
267
+ def __init__(self, config: Qwen3Config, layer_idx: int):
268
+ super().__init__()
269
+ self.hidden_size = config.hidden_size
270
+ self.self_attn = Qwen3Attention(config=config, layer_idx=layer_idx)
271
+ self.mlp = Qwen3MLP(config)
272
+ self.input_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
273
+ self.post_attention_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
274
+ if (
275
+ config.sliding_window and config._attn_implementation != "flash_attention_2"
276
+ ): # diff with Llama is this warning
277
+ logger.warning_once(
278
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
279
+ "unexpected results may be encountered."
280
+ )
281
+
282
+ def forward(
283
+ self,
284
+ hidden_states: torch.Tensor,
285
+ attention_mask: Optional[torch.Tensor] = None,
286
+ position_ids: Optional[torch.LongTensor] = None,
287
+ past_key_value: Optional[Cache] = None,
288
+ output_attentions: Optional[bool] = False,
289
+ use_cache: Optional[bool] = False,
290
+ cache_position: Optional[torch.LongTensor] = None,
291
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
292
+ **kwargs: Unpack[FlashAttentionKwargs],
293
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
294
+ residual = hidden_states
295
+
296
+ hidden_states = self.input_layernorm(hidden_states)
297
+
298
+ # Self Attention
299
+ hidden_states, self_attn_weights = self.self_attn(
300
+ hidden_states=hidden_states,
301
+ attention_mask=attention_mask,
302
+ position_ids=position_ids,
303
+ past_key_value=past_key_value,
304
+ output_attentions=output_attentions,
305
+ use_cache=use_cache,
306
+ cache_position=cache_position,
307
+ position_embeddings=position_embeddings,
308
+ **kwargs,
309
+ )
310
+ hidden_states = residual + hidden_states
311
+
312
+ # Fully Connected
313
+ residual = hidden_states
314
+ hidden_states = self.post_attention_layernorm(hidden_states)
315
+ hidden_states = self.mlp(hidden_states)
316
+ hidden_states = residual + hidden_states
317
+
318
+ outputs = (hidden_states,)
319
+ if output_attentions:
320
+ outputs += (self_attn_weights,)
321
+
322
+ return outputs
323
+
324
+
325
+ class Qwen3RotaryEmbedding(nn.Module):
326
+ def __init__(self, config: Qwen3Config, device=None):
327
+ super().__init__()
328
+ # BC: "rope_type" was originally "type"
329
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
330
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
331
+ else:
332
+ self.rope_type = "default"
333
+ self.max_seq_len_cached = config.max_position_embeddings
334
+ self.original_max_seq_len = config.max_position_embeddings
335
+
336
+ self.config = config
337
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
338
+
339
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
340
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
341
+ self.original_inv_freq = self.inv_freq
342
+
343
+ @torch.no_grad()
344
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
345
+ def forward(self, x, position_ids):
346
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
347
+ position_ids_expanded = position_ids[:, None, :].float()
348
+
349
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
350
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
351
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
352
+ emb = torch.cat((freqs, freqs), dim=-1)
353
+ cos = emb.cos() * self.attention_scaling
354
+ sin = emb.sin() * self.attention_scaling
355
+
356
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
357
+
358
+
359
+ QWEN3_START_DOCSTRING = r"""
360
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
361
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
362
+ etc.)
363
+
364
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
365
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
366
+ and behavior.
367
+
368
+ Parameters:
369
+ config ([`Qwen3Config`]):
370
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
371
+ load the weights associated with the model, only the configuration. Check out the
372
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
373
+ """
374
+
375
+
376
+ @add_start_docstrings(
377
+ "The bare Qwen3 Model outputting raw hidden-states without any specific head on top.",
378
+ QWEN3_START_DOCSTRING,
379
+ )
380
+ class Qwen3PreTrainedModel(PreTrainedModel):
381
+ config_class = Qwen3Config
382
+ base_model_prefix = "model"
383
+ supports_gradient_checkpointing = True
384
+ _no_split_modules = ["Qwen3DecoderLayer"]
385
+ _skip_keys_device_placement = ["past_key_values"]
386
+ _supports_flash_attn_2 = True
387
+ _supports_sdpa = True
388
+ _supports_flex_attn = True
389
+ _supports_cache_class = True
390
+ _supports_quantized_cache = True
391
+ _supports_static_cache = True
392
+ _supports_attention_backend = True
393
+
394
+ def _init_weights(self, module):
395
+ std = self.config.initializer_range
396
+ if isinstance(module, nn.Linear):
397
+ module.weight.data.normal_(mean=0.0, std=std)
398
+ if module.bias is not None:
399
+ module.bias.data.zero_()
400
+ elif isinstance(module, nn.Embedding):
401
+ module.weight.data.normal_(mean=0.0, std=std)
402
+ if module.padding_idx is not None:
403
+ module.weight.data[module.padding_idx].zero_()
404
+
405
+
406
+ QWEN3_INPUTS_DOCSTRING = r"""
407
+ Args:
408
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
409
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
410
+ it.
411
+
412
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
413
+ [`PreTrainedTokenizer.__call__`] for details.
414
+
415
+ [What are input IDs?](../glossary#input-ids)
416
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
417
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
418
+
419
+ - 1 for tokens that are **not masked**,
420
+ - 0 for tokens that are **masked**.
421
+
422
+ [What are attention masks?](../glossary#attention-mask)
423
+
424
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
425
+ [`PreTrainedTokenizer.__call__`] for details.
426
+
427
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
428
+ `past_key_values`).
429
+
430
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
431
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
432
+ information on the default strategy.
433
+
434
+ - 1 indicates the head is **not masked**,
435
+ - 0 indicates the head is **masked**.
436
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
437
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
438
+ config.n_positions - 1]`.
439
+
440
+ [What are position IDs?](../glossary#position-ids)
441
+ past_key_values (`Cache`, *optional*):
442
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
443
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
444
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
445
+
446
+ It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
447
+
448
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
449
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
450
+ of shape `(batch_size, sequence_length)`.
451
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
452
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
453
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
454
+ model's internal embedding lookup matrix.
455
+ use_cache (`bool`, *optional*):
456
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
457
+ `past_key_values`).
458
+ output_attentions (`bool`, *optional*):
459
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
460
+ tensors for more detail.
461
+ output_hidden_states (`bool`, *optional*):
462
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
463
+ more detail.
464
+ return_dict (`bool`, *optional*):
465
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
466
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
467
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
468
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
469
+ the complete sequence length.
470
+ """
471
+
472
+
473
+ @add_start_docstrings(
474
+ "The bare Qwen3 Model outputting raw hidden-states without any specific head on top.",
475
+ QWEN3_START_DOCSTRING,
476
+ )
477
+ class Qwen3Model(Qwen3PreTrainedModel):
478
+ """
479
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Qwen3DecoderLayer`]
480
+
481
+ Args:
482
+ config: Qwen3Config
483
+ """
484
+
485
+ def __init__(self, config: Qwen3Config):
486
+ super().__init__(config)
487
+ self.padding_idx = config.pad_token_id
488
+ self.vocab_size = config.vocab_size
489
+
490
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
491
+ self.layers = nn.ModuleList(
492
+ [Qwen3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
493
+ )
494
+ self.norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
495
+ self.rotary_emb = Qwen3RotaryEmbedding(config=config)
496
+ self.gradient_checkpointing = False
497
+
498
+ # Initialize weights and apply final processing
499
+ self.post_init()
500
+
501
+ def get_input_embeddings(self):
502
+ return self.embed_tokens
503
+
504
+ def set_input_embeddings(self, value):
505
+ self.embed_tokens = value
506
+
507
+ @can_return_tuple
508
+ @add_start_docstrings_to_model_forward(QWEN3_INPUTS_DOCSTRING)
509
+ def forward(
510
+ self,
511
+ input_ids: Optional[torch.LongTensor] = None,
512
+ attention_mask: Optional[torch.Tensor] = None,
513
+ position_ids: Optional[torch.LongTensor] = None,
514
+ past_key_values: Optional[Cache] = None,
515
+ inputs_embeds: Optional[torch.FloatTensor] = None,
516
+ use_cache: Optional[bool] = None,
517
+ output_attentions: Optional[bool] = None,
518
+ output_hidden_states: Optional[bool] = None,
519
+ cache_position: Optional[torch.LongTensor] = None,
520
+ **flash_attn_kwargs: Unpack[FlashAttentionKwargs],
521
+ ) -> BaseModelOutputWithPast:
522
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
523
+ output_hidden_states = (
524
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
525
+ )
526
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
527
+
528
+ if (input_ids is None) ^ (inputs_embeds is not None):
529
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
530
+
531
+ if self.gradient_checkpointing and self.training and use_cache:
532
+ logger.warning_once(
533
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
534
+ )
535
+ use_cache = False
536
+
537
+ # TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache
538
+ if not isinstance(past_key_values, (type(None), Cache)):
539
+ raise ValueError("The `past_key_values` should be either a `Cache` object or `None`.")
540
+
541
+ if inputs_embeds is None:
542
+ inputs_embeds = self.embed_tokens(input_ids)
543
+
544
+ if use_cache and past_key_values is None:
545
+ past_key_values = DynamicCache()
546
+
547
+ if cache_position is None:
548
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
549
+ cache_position = torch.arange(
550
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
551
+ )
552
+
553
+ if position_ids is None:
554
+ position_ids = cache_position.unsqueeze(0)
555
+
556
+ causal_mask = self._update_causal_mask(
557
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
558
+ )
559
+
560
+ hidden_states = inputs_embeds
561
+
562
+ # create position embeddings to be shared across the decoder layers
563
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
564
+
565
+ # decoder layers
566
+ all_hidden_states = () if output_hidden_states else None
567
+ all_self_attns = () if output_attentions else None
568
+
569
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
570
+ if output_hidden_states:
571
+ all_hidden_states += (hidden_states,)
572
+
573
+ if self.gradient_checkpointing and self.training:
574
+ layer_outputs = self._gradient_checkpointing_func(
575
+ partial(decoder_layer.__call__, **flash_attn_kwargs),
576
+ hidden_states,
577
+ causal_mask,
578
+ position_ids,
579
+ past_key_values,
580
+ output_attentions,
581
+ use_cache,
582
+ cache_position,
583
+ position_embeddings,
584
+ )
585
+ else:
586
+ layer_outputs = decoder_layer(
587
+ hidden_states,
588
+ attention_mask=causal_mask,
589
+ position_ids=position_ids,
590
+ past_key_value=past_key_values,
591
+ output_attentions=output_attentions,
592
+ use_cache=use_cache,
593
+ cache_position=cache_position,
594
+ position_embeddings=position_embeddings,
595
+ **flash_attn_kwargs,
596
+ )
597
+
598
+ hidden_states = layer_outputs[0]
599
+
600
+ if output_attentions:
601
+ all_self_attns += (layer_outputs[1],)
602
+
603
+ hidden_states = self.norm(hidden_states)
604
+
605
+ # add hidden states from the last decoder layer
606
+ if output_hidden_states:
607
+ all_hidden_states += (hidden_states,)
608
+
609
+ return BaseModelOutputWithPast(
610
+ last_hidden_state=hidden_states,
611
+ past_key_values=past_key_values if use_cache else None,
612
+ hidden_states=all_hidden_states,
613
+ attentions=all_self_attns,
614
+ )
615
+
616
+ def _update_causal_mask(
617
+ self,
618
+ attention_mask: torch.Tensor,
619
+ input_tensor: torch.Tensor,
620
+ cache_position: torch.Tensor,
621
+ past_key_values: Cache,
622
+ output_attentions: bool = False,
623
+ ):
624
+ if self.config._attn_implementation == "flash_attention_2":
625
+ if attention_mask is not None and past_key_values is not None:
626
+ is_padding_right = attention_mask[:, -1].sum().item() != input_tensor.size()[0]
627
+ if is_padding_right:
628
+ raise ValueError(
629
+ "You are attempting to perform batched generation with padding_side='right'"
630
+ " this may lead to unexpected behaviour for Flash Attention version of Qwen3. Make sure to "
631
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
632
+ )
633
+ if attention_mask is not None and 0.0 in attention_mask:
634
+ return attention_mask
635
+ return None
636
+
637
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
638
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
639
+ # to infer the attention mask.
640
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
641
+ using_static_cache = isinstance(past_key_values, StaticCache)
642
+ using_sliding_window_cache = isinstance(past_key_values, SlidingWindowCache)
643
+
644
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
645
+ if (
646
+ self.config._attn_implementation == "sdpa"
647
+ and not (using_static_cache or using_sliding_window_cache)
648
+ and not output_attentions
649
+ ):
650
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
651
+ attention_mask,
652
+ inputs_embeds=input_tensor,
653
+ past_key_values_length=past_seen_tokens,
654
+ sliding_window=self.config.sliding_window,
655
+ is_training=self.training,
656
+ ):
657
+ return None
658
+
659
+ dtype, device = input_tensor.dtype, input_tensor.device
660
+ min_dtype = torch.finfo(dtype).min
661
+ sequence_length = input_tensor.shape[1]
662
+ # SlidingWindowCache or StaticCache
663
+ if using_sliding_window_cache or using_static_cache:
664
+ target_length = past_key_values.get_max_cache_shape()
665
+ # DynamicCache or no cache
666
+ else:
667
+ target_length = (
668
+ attention_mask.shape[-1]
669
+ if isinstance(attention_mask, torch.Tensor)
670
+ else past_seen_tokens + sequence_length + 1
671
+ )
672
+
673
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
674
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
675
+ attention_mask,
676
+ sequence_length=sequence_length,
677
+ target_length=target_length,
678
+ dtype=dtype,
679
+ device=device,
680
+ cache_position=cache_position,
681
+ batch_size=input_tensor.shape[0],
682
+ config=self.config,
683
+ past_key_values=past_key_values,
684
+ )
685
+
686
+ if (
687
+ self.config._attn_implementation == "sdpa"
688
+ and attention_mask is not None
689
+ and attention_mask.device.type in ["cuda", "xpu"]
690
+ and not output_attentions
691
+ ):
692
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
693
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
694
+ # Details: https://github.com/pytorch/pytorch/issues/110213
695
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
696
+
697
+ return causal_mask
698
+
699
+ @staticmethod
700
+ def _prepare_4d_causal_attention_mask_with_cache_position(
701
+ attention_mask: torch.Tensor,
702
+ sequence_length: int,
703
+ target_length: int,
704
+ dtype: torch.dtype,
705
+ device: torch.device,
706
+ cache_position: torch.Tensor,
707
+ batch_size: int,
708
+ config: Qwen3Config,
709
+ past_key_values: Cache,
710
+ ):
711
+ """
712
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
713
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
714
+
715
+ Args:
716
+ attention_mask (`torch.Tensor`):
717
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
718
+ sequence_length (`int`):
719
+ The sequence length being processed.
720
+ target_length (`int`):
721
+ The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
722
+ dtype (`torch.dtype`):
723
+ The dtype to use for the 4D attention mask.
724
+ device (`torch.device`):
725
+ The device to place the 4D attention mask on.
726
+ cache_position (`torch.Tensor`):
727
+ Indices depicting the position of the input sequence tokens in the sequence.
728
+ batch_size (`torch.Tensor`):
729
+ Batch size.
730
+ config (`Qwen3Config`):
731
+ The model's configuration class
732
+ past_key_values (`Cache`):
733
+ The cache class that is being used currently to generate
734
+ """
735
+ if attention_mask is not None and attention_mask.dim() == 4:
736
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
737
+ causal_mask = attention_mask
738
+ else:
739
+ min_dtype = torch.finfo(dtype).min
740
+ causal_mask = torch.full(
741
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
742
+ )
743
+ diagonal_attend_mask = torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
744
+ if config.sliding_window is not None:
745
+ # if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
746
+ # the check is needed to verify is current checkpoint was trained with sliding window or not
747
+ if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
748
+ sliding_attend_mask = torch.arange(target_length, device=device) <= (
749
+ cache_position.reshape(-1, 1) - config.sliding_window
750
+ )
751
+ diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
752
+ causal_mask *= diagonal_attend_mask
753
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
754
+ if attention_mask is not None:
755
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
756
+ if attention_mask.shape[-1] > target_length:
757
+ attention_mask = attention_mask[:, :target_length]
758
+ mask_length = attention_mask.shape[-1]
759
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
760
+ causal_mask.device
761
+ )
762
+ padding_mask = padding_mask == 0
763
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
764
+ padding_mask, min_dtype
765
+ )
766
+ return causal_mask
767
+
768
+
769
+ class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ...
770
+
771
+
772
+ class Qwen3ForCausalLM(Qwen3PreTrainedModel, GenerationMixin):
773
+ _tied_weights_keys = ["lm_head.weight"]
774
+ _tp_plan = {"lm_head": "colwise_rep"}
775
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
776
+
777
+ def __init__(self, config):
778
+ super().__init__(config)
779
+ self.model = Qwen3Model(config)
780
+ self.vocab_size = config.vocab_size
781
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
782
+
783
+ # Initialize weights and apply final processing
784
+ self.post_init()
785
+
786
+ def get_input_embeddings(self):
787
+ return self.model.embed_tokens
788
+
789
+ def set_input_embeddings(self, value):
790
+ self.model.embed_tokens = value
791
+
792
+ def get_output_embeddings(self):
793
+ return self.lm_head
794
+
795
+ def set_output_embeddings(self, new_embeddings):
796
+ self.lm_head = new_embeddings
797
+
798
+ def set_decoder(self, decoder):
799
+ self.model = decoder
800
+
801
+ def get_decoder(self):
802
+ return self.model
803
+
804
+ @can_return_tuple
805
+ @deprecate_kwarg("num_logits_to_keep", version="4.50", new_name="logits_to_keep")
806
+ @add_start_docstrings_to_model_forward(QWEN3_INPUTS_DOCSTRING)
807
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
808
+ def forward(
809
+ self,
810
+ input_ids: Optional[torch.LongTensor] = None,
811
+ attention_mask: Optional[torch.Tensor] = None,
812
+ position_ids: Optional[torch.LongTensor] = None,
813
+ past_key_values: Optional[Cache] = None,
814
+ inputs_embeds: Optional[torch.FloatTensor] = None,
815
+ labels: Optional[torch.LongTensor] = None,
816
+ use_cache: Optional[bool] = None,
817
+ output_attentions: Optional[bool] = None,
818
+ output_hidden_states: Optional[bool] = None,
819
+ cache_position: Optional[torch.LongTensor] = None,
820
+ logits_to_keep: Union[int, torch.Tensor] = 0,
821
+ **kwargs: Unpack[KwargsForCausalLM],
822
+ ) -> CausalLMOutputWithPast:
823
+ r"""
824
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
825
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
826
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
827
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
828
+
829
+ logits_to_keep (`int` or `torch.Tensor`, *optional*):
830
+ If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
831
+ `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
832
+ token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
833
+ If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
834
+ This is useful when using packed tensor format (single dimension for batch and sequence length).
835
+
836
+ Returns:
837
+
838
+ Example:
839
+
840
+ ```python
841
+ >>> from transformers import AutoTokenizer, Qwen3ForCausalLM
842
+
843
+ >>> model = Qwen3ForCausalLM.from_pretrained("Qwen/Qwen3-8B")
844
+ >>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
845
+
846
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
847
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
848
+
849
+ >>> # Generate
850
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
851
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
852
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
853
+ ```"""
854
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
855
+ output_hidden_states = (
856
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
857
+ )
858
+
859
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
860
+ outputs: BaseModelOutputWithPast = self.model(
861
+ input_ids=input_ids,
862
+ attention_mask=attention_mask,
863
+ position_ids=position_ids,
864
+ past_key_values=past_key_values,
865
+ inputs_embeds=inputs_embeds,
866
+ use_cache=use_cache,
867
+ output_attentions=output_attentions,
868
+ output_hidden_states=output_hidden_states,
869
+ cache_position=cache_position,
870
+ **kwargs,
871
+ )
872
+
873
+ hidden_states = outputs.last_hidden_state
874
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
875
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
876
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
877
+
878
+ loss = None
879
+ if labels is not None:
880
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
881
+
882
+ return CausalLMOutputWithPast(
883
+ loss=loss,
884
+ logits=logits,
885
+ past_key_values=outputs.past_key_values,
886
+ hidden_states=outputs.hidden_states,
887
+ attentions=outputs.attentions,
888
+ )
889
+
890
+
891
+ __all__ = [
892
+ "Qwen3ForCausalLM",
893
+ "Qwen3Model",
894
+ "Qwen3PreTrainedModel",
895
+ ]
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "attn_implementation": "flash_attention_2",
3
+ "bos_token_id": 151643,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 151645,
7
+ 151643
8
+ ],
9
+ "pad_token_id": 151643,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "4.53.0"
14
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5b2006f771b07cf385f0d23f9227f28054f9fbd92b85680b54085db3fc670da
3
+ size 4967215360
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8661879e85528fc5ebf5dfeada596dba94559bc42ebe710a0f9bd438820548b
3
+ size 3077766632
model.safetensors.index.json ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 4022468096,
4
+ "total_size": 8044936192
5
+ },
6
+ "weight_map": {
7
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
107
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
127
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
129
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
141
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
145
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
146
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
152
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
153
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
155
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
156
+ "model.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
157
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
159
+ "model.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
161
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
162
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
163
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
164
+ "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
165
+ "model.layers.21.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
166
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
167
+ "model.layers.21.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
168
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
169
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
170
+ "model.layers.21.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
171
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
172
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
173
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
174
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
175
+ "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
176
+ "model.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
177
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
178
+ "model.layers.22.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
179
+ "model.layers.22.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
180
+ "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
181
+ "model.layers.22.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
182
+ "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
183
+ "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
184
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
185
+ "model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
186
+ "model.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
187
+ "model.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
188
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
189
+ "model.layers.23.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
190
+ "model.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
191
+ "model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
192
+ "model.layers.23.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
193
+ "model.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
194
+ "model.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
195
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
196
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
197
+ "model.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
198
+ "model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
199
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
200
+ "model.layers.24.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
201
+ "model.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
202
+ "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
203
+ "model.layers.24.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
204
+ "model.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
205
+ "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
206
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
207
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
208
+ "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
209
+ "model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
210
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
211
+ "model.layers.25.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
212
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
213
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
214
+ "model.layers.25.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
215
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
216
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
217
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
218
+ "model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
219
+ "model.layers.26.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
220
+ "model.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
221
+ "model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
222
+ "model.layers.26.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
223
+ "model.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
224
+ "model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
225
+ "model.layers.26.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
226
+ "model.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
227
+ "model.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
228
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
229
+ "model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
230
+ "model.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
231
+ "model.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
232
+ "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
233
+ "model.layers.27.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
234
+ "model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
235
+ "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
236
+ "model.layers.27.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
237
+ "model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
238
+ "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
239
+ "model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
240
+ "model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
241
+ "model.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
242
+ "model.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
243
+ "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
244
+ "model.layers.28.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
245
+ "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
246
+ "model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
247
+ "model.layers.28.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
248
+ "model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
249
+ "model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
250
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
251
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
252
+ "model.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
253
+ "model.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
254
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
255
+ "model.layers.29.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
256
+ "model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
257
+ "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
258
+ "model.layers.29.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
259
+ "model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
260
+ "model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
261
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
267
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
271
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
272
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
273
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
274
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
275
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
276
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
277
+ "model.layers.30.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
278
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
279
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
280
+ "model.layers.30.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
281
+ "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
282
+ "model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
283
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
284
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
285
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
286
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
287
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
288
+ "model.layers.31.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
289
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
290
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
291
+ "model.layers.31.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
292
+ "model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
293
+ "model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
294
+ "model.layers.32.input_layernorm.weight": "model-00002-of-00002.safetensors",
295
+ "model.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
296
+ "model.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
297
+ "model.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
298
+ "model.layers.32.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
299
+ "model.layers.32.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
300
+ "model.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
301
+ "model.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
302
+ "model.layers.32.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
303
+ "model.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
304
+ "model.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
305
+ "model.layers.33.input_layernorm.weight": "model-00002-of-00002.safetensors",
306
+ "model.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
307
+ "model.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
308
+ "model.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
309
+ "model.layers.33.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
310
+ "model.layers.33.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
311
+ "model.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
312
+ "model.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
313
+ "model.layers.33.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
314
+ "model.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
315
+ "model.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
316
+ "model.layers.34.input_layernorm.weight": "model-00002-of-00002.safetensors",
317
+ "model.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
318
+ "model.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
319
+ "model.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
320
+ "model.layers.34.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
321
+ "model.layers.34.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
322
+ "model.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
323
+ "model.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
324
+ "model.layers.34.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
325
+ "model.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
326
+ "model.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
327
+ "model.layers.35.input_layernorm.weight": "model-00002-of-00002.safetensors",
328
+ "model.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
329
+ "model.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
330
+ "model.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
331
+ "model.layers.35.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
332
+ "model.layers.35.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
333
+ "model.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
334
+ "model.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
335
+ "model.layers.35.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
336
+ "model.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
337
+ "model.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
338
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
339
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
340
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
341
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
343
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
344
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
345
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
346
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
347
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
348
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
349
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
350
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
351
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
352
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
353
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
354
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
355
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
356
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
357
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
358
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
359
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
360
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
361
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
362
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
363
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
364
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
365
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
366
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
367
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
368
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
369
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
370
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
371
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
372
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
373
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
374
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
375
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
376
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
377
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
378
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
379
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
380
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
381
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
382
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
383
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
384
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
385
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
386
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
387
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
388
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
389
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
390
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
391
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
392
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
393
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
394
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
395
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
396
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
397
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
398
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
399
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
400
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
401
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
402
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
403
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
404
+ "model.norm.weight": "model-00002-of-00002.safetensors"
405
+ }
406
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90ccdcb0ad6ec5269e2ba64e81731b549f6e8222ec3daf103db96a6612682e43
3
+ size 11422755
tokenizer_config.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "model_max_length": 262144,
235
+ "pad_token": "<|endoftext|>",
236
+ "padding_side": "left",
237
+ "split_special_tokens": false,
238
+ "tokenizer_class": "Qwen2Tokenizer",
239
+ "unk_token": null
240
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff