moelanoby commited on
Commit
42bcacc
·
verified ·
1 Parent(s): c0b02b1

Initial upload of ALM-Qwen model package

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
+ qwen_generator/qwen_tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
ALM.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --- START OF FILE ALM.py ---
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.nn.functional as F
6
+ import math
7
+
8
+ class AttentionLinkedMemory(nn.Module):
9
+ """
10
+ Implements an Attention-Linked Memory Layer.
11
+
12
+ This layer retrieves context from a structured memory based on a query.
13
+ It uses a two-level attention mechanism:
14
+ 1. Within-Bucket Attention: Summarizes each memory bucket based on relevance
15
+ to the query.
16
+ 2. Between-Bucket Attention: Weights the summarized buckets to find the most
17
+ relevant buckets for the query, producing a final aggregated context.
18
+
19
+ Args:
20
+ query_dim (int): Dimension of the input query vector.
21
+ memory_dim (int): Dimension of the memory item vectors.
22
+ embed_dim (int): Internal embedding dimension for attention. Keys, Queries,
23
+ and Values will be projected to this dimension.
24
+ num_heads (int): Number of attention heads for both levels. Must divide embed_dim.
25
+ output_dim (int, optional): Dimension of the final output context vector.
26
+ If None, defaults to embed_dim.
27
+ dropout_rate (float, optional): Dropout probability. Defaults to 0.1.
28
+ """
29
+ def __init__(self,
30
+ query_dim: int,
31
+ memory_dim: int,
32
+ embed_dim: int,
33
+ num_heads: int,
34
+ output_dim: int = None,
35
+ dropout_rate: float = 0.1):
36
+ super().__init__()
37
+
38
+ if embed_dim % num_heads != 0:
39
+ raise ValueError(f"embed_dim ({embed_dim}) must be divisible by num_heads ({num_heads})")
40
+
41
+ self.query_dim = query_dim
42
+ self.memory_dim = memory_dim
43
+ self.embed_dim = embed_dim
44
+ self.output_dim = output_dim if output_dim is not None else embed_dim
45
+ self.num_heads = num_heads
46
+ self.head_dim = embed_dim // num_heads
47
+ self.scale = math.sqrt(self.head_dim)
48
+
49
+ # --- Level 1 (Within-Bucket) Projections ---
50
+ self.q_proj_l1 = nn.Linear(query_dim, embed_dim)
51
+ self.k_proj_l1 = nn.Linear(memory_dim, embed_dim)
52
+ self.v_proj_l1 = nn.Linear(memory_dim, embed_dim)
53
+ self.dropout_l1 = nn.Dropout(dropout_rate)
54
+ self.norm_l1_out = nn.LayerNorm(embed_dim)
55
+
56
+ # --- Level 2 (Between-Bucket) Projections ---
57
+ self.q_proj_l2 = nn.Linear(query_dim, embed_dim)
58
+ self.k_proj_l2 = nn.Linear(embed_dim, embed_dim)
59
+ self.v_proj_l2 = nn.Linear(embed_dim, embed_dim)
60
+ self.dropout_l2 = nn.Dropout(dropout_rate)
61
+
62
+ # --- Final Output Projection ---
63
+ self.out_proj = nn.Linear(embed_dim, self.output_dim)
64
+ self.norm_final = nn.LayerNorm(self.output_dim)
65
+
66
+ def forward(self,
67
+ query: torch.Tensor,
68
+ memory_buckets: torch.Tensor,
69
+ memory_mask: torch.Tensor = None):
70
+ """
71
+ Forward pass through the Attention-Linked Memory layer.
72
+
73
+ Args:
74
+ query (torch.Tensor): Input query tensor.
75
+ Shape: (batch_size, query_dim)
76
+ memory_buckets (torch.Tensor): Tensor containing memory items organized
77
+ into buckets. Padded for consistent size.
78
+ Shape: (batch_size, num_buckets, max_items_per_bucket, memory_dim)
79
+ memory_mask (torch.Tensor, optional): Boolean mask indicating valid
80
+ memory items (True) vs padding (False).
81
+ Shape: (batch_size, num_buckets, max_items_per_bucket)
82
+
83
+ Returns:
84
+ Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
85
+ - aggregated_context (torch.Tensor): The final context vector.
86
+ Shape: (batch_size, output_dim)
87
+ - bucket_attention_weights_l2 (torch.Tensor): Attention weights for buckets (L2).
88
+ Shape: (batch_size, num_buckets)
89
+ - item_attention_weights_l1 (torch.Tensor): Attention weights for items within buckets (L1, averaged over heads).
90
+ Shape: (batch_size, num_buckets, max_items_per_bucket)
91
+ """
92
+ batch_size, num_buckets, max_items, _ = memory_buckets.shape
93
+
94
+ # ========================= Level 1: Within-Bucket Attention =========================
95
+ q1 = self.q_proj_l1(query).view(batch_size, self.num_heads, 1, 1, self.head_dim)
96
+ k1 = self.k_proj_l1(memory_buckets)
97
+ v1 = self.v_proj_l1(memory_buckets)
98
+
99
+ k1 = k1.view(batch_size, num_buckets, max_items, self.num_heads, self.head_dim).permute(0, 3, 1, 2, 4)
100
+ v1 = v1.view(batch_size, num_buckets, max_items, self.num_heads, self.head_dim).permute(0, 3, 1, 2, 4)
101
+
102
+ attn_scores_l1 = torch.einsum('bhqid,bhnkd->bhnqk', q1, k1) / self.scale
103
+ attn_scores_l1 = attn_scores_l1.squeeze(3) # (B, H, N_b, N_i)
104
+
105
+ if memory_mask is not None:
106
+ expanded_mask_l1 = memory_mask.unsqueeze(1) # (B, 1, N_b, N_i)
107
+ attn_scores_l1 = attn_scores_l1.masked_fill(expanded_mask_l1 == 0, -1e9)
108
+
109
+ attn_weights_l1_raw = F.softmax(attn_scores_l1, dim=-1) # (B, H, N_b, N_i)
110
+ # For returning, average over heads
111
+ item_attention_weights_l1_for_output = attn_weights_l1_raw.mean(dim=1) # (B, N_b, N_i)
112
+
113
+ attn_weights_l1_dropout = self.dropout_l1(attn_weights_l1_raw)
114
+
115
+ bucket_summaries = torch.einsum('bhnk,bhnkd->bhnd', attn_weights_l1_dropout, v1)
116
+ bucket_summaries = bucket_summaries.permute(0, 2, 1, 3).contiguous().view(batch_size, num_buckets, self.embed_dim)
117
+ bucket_summaries = self.norm_l1_out(bucket_summaries)
118
+
119
+ # ========================= Level 2: Between-Bucket Attention ========================
120
+ q2 = self.q_proj_l2(query).view(batch_size, self.num_heads, 1, self.head_dim)
121
+ k2 = self.k_proj_l2(bucket_summaries)
122
+ v2 = self.v_proj_l2(bucket_summaries)
123
+
124
+ # Corrected typo: self.head__dim -> self.head_dim
125
+ k2 = k2.view(batch_size, num_buckets, self.num_heads, self.head_dim).permute(0, 2, 1, 3)
126
+ v2 = v2.view(batch_size, num_buckets, self.num_heads, self.head_dim).permute(0, 2, 1, 3)
127
+
128
+ attn_scores_l2 = torch.einsum('bhqd,bhnd->bhqn', q2, k2) / self.scale
129
+ attn_scores_l2 = attn_scores_l2.squeeze(2) # (B, H, N_b)
130
+
131
+ # Optional: Mask entire buckets if they were all padding in L1 (advanced)
132
+ # For now, assume valid buckets have non-zero summaries
133
+ # Or if memory_mask indicates all items in a bucket are false, that bucket's summary might be ~0
134
+ # and L2 attention should naturally give it low weight.
135
+
136
+ attn_weights_l2_raw = F.softmax(attn_scores_l2, dim=-1) # (B, H, N_b)
137
+ bucket_attention_weights_l2_for_output = attn_weights_l2_raw.mean(dim=1) # (B, N_b)
138
+
139
+ attn_weights_l2_dropout = self.dropout_l2(attn_weights_l2_raw)
140
+
141
+ aggregated_context_heads = torch.einsum('bhn,bhnd->bhd', attn_weights_l2_dropout, v2)
142
+ aggregated_context = aggregated_context_heads.contiguous().view(batch_size, self.embed_dim)
143
+
144
+ # ========================= Final Output Projection ========================
145
+ final_output = self.out_proj(aggregated_context)
146
+ final_output = self.norm_final(final_output)
147
+
148
+ return final_output, bucket_attention_weights_l2_for_output, item_attention_weights_l1_for_output
149
+
150
+ # ========================= Example Usage (ALM Standalone) =========================
151
+ if __name__ == '__main__':
152
+ # Test the modified ALM layer
153
+ _batch_size = 2
154
+ _query_dim = 32
155
+ _memory_dim = 24
156
+ _embed_dim = 64
157
+ _num_heads = 4
158
+ _output_dim = 32
159
+ _num_buckets = 3
160
+ _max_items_per_bucket = 5
161
+
162
+ alm_layer_test = AttentionLinkedMemory(
163
+ query_dim=_query_dim, memory_dim=_memory_dim, embed_dim=_embed_dim,
164
+ num_heads=_num_heads, output_dim=_output_dim
165
+ )
166
+
167
+ query_test = torch.randn(_batch_size, _query_dim)
168
+ memory_buckets_test = torch.randn(_batch_size, _num_buckets, _max_items_per_bucket, _memory_dim)
169
+ memory_mask_test = torch.ones(_batch_size, _num_buckets, _max_items_per_bucket, dtype=torch.bool)
170
+ memory_mask_test[:, :, -1] = 0 # Mask last item in each bucket
171
+
172
+ agg_ctx, buck_att, item_att = alm_layer_test(query_test, memory_buckets_test, memory_mask_test)
173
+
174
+ print("--- ALM Standalone Test ---")
175
+ print(f"Aggregated Context Shape: {agg_ctx.shape}") # Expected: (B, output_dim)
176
+ print(f"Bucket Attention (L2) Shape: {buck_att.shape}") # Expected: (B, num_buckets)
177
+ print(f"Item Attention (L1) Shape: {item_att.shape}") # Expected: (B, num_buckets, max_items_per_bucket)
178
+ print("Item Attention for first batch, first bucket:\n", item_att[0, 0, :])
179
+ print("Sum of item attentions (should be ~1.0 for unmasked items):", item_att[0,0,:-1].sum())
180
+ print("Attention on masked item (should be ~0.0):", item_att[0,0,-1])
181
+
182
+
183
+ # --- END OF FILE ALM.py ---
README.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # ALM-Qwen Model: ALM-Qwen-0.5B-testing
3
+
4
+ This repository contains an Attention-Linked Memory augmented Qwen model (ALM-Qwen).
5
+
6
+ ## Model Components
7
+
8
+ * **AttentionLinkedMemory (ALM)**: A custom PyTorch module for two-level attention-based retrieval from structured memory. (See `ALM.py`)
9
+ * **QwenGenerator**: Wraps a Hugging Face Qwen model (e.g., Qwen2.5-0.5B-Instruct or Qwen2.5-7B-Instruct) for text generation.
10
+ * **ALMQwenModel_HF**: The main class orchestrating the ALM retrieval and Qwen generation. (See `alm_qwen_hf.py`)
11
+ * **Saved Weights & Config**:
12
+ * `alm_layer_state_dict.pth`: Trained weights for the ALM layer.
13
+ * `alm_qwen_hf_config.json`: Configuration for the `ALMQwenModel_HF`, including ALM parameters and paths to the Qwen components.
14
+ * `qwen_generator/`: Contains the saved Hugging Face Qwen model and tokenizer.
15
+
16
+ ## How to Use
17
+
18
+ 1. **Prerequisites**:
19
+ ```bash
20
+ pip install torch transformers huggingface_hub sentencepiece accelerate
21
+ # Add other dependencies if any, e.g., bitsandbytes for quantization
22
+ ```
23
+
24
+ 2. **Clone the repository (or download files manually)**:
25
+ ```bash
26
+ git lfs install # if large files are used, though typically not for these components directly
27
+ git clone https://huggingface.co/moelanoby/ALM-Qwen-0.5B-testing
28
+ cd ALM-Qwen-0.5B-testing
29
+ ```
30
+
31
+ 3. **Load the model in Python**:
32
+ ```python
33
+ from alm_qwen_hf import ALMQwenModel_HF # Make sure alm_qwen_hf.py and ALM.py are in your PYTHONPATH
34
+ import torch
35
+
36
+ # Desired device
37
+ device = "cuda" if torch.cuda.is_available() else "cpu"
38
+
39
+ # Path to the directory where you cloned/downloaded the model
40
+ model_directory = "." # Or the specific path if you are running from outside the cloned repo
41
+
42
+ # Load the model
43
+ loaded_model = ALMQwenModel_HF.load_model(model_directory, device=device)
44
+ print("ALM-Qwen model loaded successfully!")
45
+
46
+ # --- Prepare Dummy Input Data (similar to the example in alm_qwen_hf.py) ---
47
+ # batch_size = 1
48
+ # alm_query_dim = loaded_model.alm_config['query_dim']
49
+ # alm_memory_dim = loaded_model.alm_config['memory_dim']
50
+ # num_kb_buckets = 3 # Example
51
+ # max_kb_items_per_bucket = 5 # Example
52
+
53
+ # query_texts = ["What is the capital of France?"]
54
+ # query_embeddings_for_alm = torch.randn(batch_size, alm_query_dim)
55
+ # memory_item_embeddings = torch.randn(batch_size, num_kb_buckets, max_kb_items_per_bucket, alm_memory_dim)
56
+ # memory_text_items = [[["Paris is the capital of France." for _ in range(max_kb_items_per_bucket)] for _ in range(num_kb_buckets)] for _ in range(batch_size)]
57
+ # memory_mask = torch.ones(batch_size, num_kb_buckets, max_kb_items_per_bucket, dtype=torch.bool)
58
+ # memory_mask[:, :, -1] = False # Example mask
59
+
60
+ # # Run inference
61
+ # generated_answers, _, _ = loaded_model(
62
+ # query_texts,
63
+ # query_embeddings_for_alm,
64
+ # memory_item_embeddings,
65
+ # memory_text_items,
66
+ # memory_mask
67
+ # )
68
+ # print(f"Query: {query_texts[0]}")
69
+ # print(f"Answer: {generated_answers[0]}")
70
+ ```
71
+
72
+ ## Training
73
+
74
+ The ALM layer (`alm_layer_state_dict.pth`) might have been trained. The Qwen model inside `qwen_generator/` is typically a pre-trained model from Hugging Face, possibly fine-tuned.
75
+
76
+ ## Notes
77
+
78
+ * The Qwen model components can be large. Ensure you have sufficient disk space and network bandwidth.
79
+ * The `load_model` method in `alm_qwen_hf.py` handles the reconstruction of the composite model.
80
+
81
+ ---
82
+ *This README was auto-generated. Please update with more specific details about your model.*
alm_layer_state_dict.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:912c97d56840c90c88850157d771ee9edc7c34ef2e8258821bc98aef56813707
3
+ size 1064830
alm_qwen_hf_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alm_config": {
3
+ "query_dim": 128,
4
+ "memory_dim": 64,
5
+ "embed_dim": 256,
6
+ "num_heads": 8,
7
+ "output_dim": 128,
8
+ "dropout_rate": 0.0
9
+ },
10
+ "qwen_model_name_or_path": "qwen_generator/qwen_model",
11
+ "qwen_tokenizer_path": "qwen_generator/qwen_tokenizer",
12
+ "top_k_buckets": 2,
13
+ "top_k_items_per_bucket": 1
14
+ }
qwen_generator/qwen_model/config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "eos_token_id": 151645,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 896,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 4864,
12
+ "max_position_embeddings": 32768,
13
+ "max_window_layers": 21,
14
+ "model_type": "qwen2",
15
+ "num_attention_heads": 14,
16
+ "num_hidden_layers": 24,
17
+ "num_key_value_heads": 2,
18
+ "rms_norm_eps": 1e-06,
19
+ "rope_scaling": null,
20
+ "rope_theta": 1000000.0,
21
+ "sliding_window": 32768,
22
+ "tie_word_embeddings": true,
23
+ "torch_dtype": "bfloat16",
24
+ "transformers_version": "4.51.3",
25
+ "use_cache": true,
26
+ "use_sliding_window": false,
27
+ "vocab_size": 151936
28
+ }
qwen_generator/qwen_model/generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.1,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "4.51.3"
14
+ }
qwen_generator/qwen_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdf756fa7fcbe7404d5c60e26bff1a0c8b8aa1f72ced49e7dd0210fe288fb7fe
3
+ size 988097824
qwen_generator/qwen_tokenizer/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
qwen_generator/qwen_tokenizer/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
qwen_generator/qwen_tokenizer/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
+ }
qwen_generator/qwen_tokenizer/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b2690ebfca099be3e2dde9b9d351dad1c92c6db33c695d5c81098020db9ec16
3
+ size 11422162
qwen_generator/qwen_tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# 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>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\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\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 131072,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
qwen_generator/qwen_tokenizer/vocab.json ADDED
The diff for this file is too large to render. See raw diff