Eti Zymatica commited on
Commit
cdddfb8
·
verified ·
1 Parent(s): 794d7ac

Publish UFO Go framework implementation

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
decode_tokenizer.go ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Watermark: ip zymatica.space
2
+ // Go UFO Tokenizer Reconstruction Engine
3
+
4
+ package main
5
+
6
+ import (
7
+ "bufio"
8
+ "encoding/binary"
9
+ "fmt"
10
+ "io"
11
+ "os"
12
+ "path/filepath"
13
+ "strings"
14
+ )
15
+
16
+ // ReadVarint reads a variable-length integer from data at pos
17
+ func ReadVarint(data []byte, pos *int) int {
18
+ val := 0
19
+ shift := uint(0)
20
+ for {
21
+ if *pos >= len(data) {
22
+ break
23
+ }
24
+ b := data[*pos]
25
+ *pos++
26
+ val |= int(b&0x7F) << shift
27
+ if (b & 0x80) == 0 {
28
+ break
29
+ }
30
+ shift += 7
31
+ }
32
+ return val
33
+ }
34
+
35
+ // DecompressVocab restores prefix-suffix vocabulary bytes to raw tokens
36
+ func DecompressVocab(data []byte, numTokens int) [][]byte {
37
+ tokens := make([][]byte, 0, numTokens)
38
+ pos := 0
39
+ var prev []byte
40
+ for i := 0; i < numTokens; i++ {
41
+ if pos >= len(data) {
42
+ break
43
+ }
44
+ common := ReadVarint(data, &pos)
45
+ suffixLen := ReadVarint(data, &pos)
46
+ if pos+suffixLen > len(data) {
47
+ break
48
+ }
49
+ suffix := data[pos : pos+suffixLen]
50
+ pos += suffixLen
51
+
52
+ t := make([]byte, common+len(suffix))
53
+ if common > len(prev) {
54
+ common = len(prev)
55
+ }
56
+ copy(t[:common], prev[:common])
57
+ copy(t[common:], suffix)
58
+ tokens = append(tokens, t)
59
+ prev = t
60
+ }
61
+ return tokens
62
+ }
63
+
64
+ // DecompressMerges restores 6-byte merge index pairs to u32 pairs
65
+ func DecompressMerges(data []byte) [][2]uint32 {
66
+ numMerges := len(data) / 6
67
+ merges := make([][2]uint32, 0, numMerges)
68
+ for i := 0; i < numMerges; i++ {
69
+ offset := i * 6
70
+ idx0 := (uint32(data[offset]) << 16) | (uint32(data[offset+1]) << 8) | uint32(data[offset+2])
71
+ idx1 := (uint32(data[offset+3]) << 16) | (uint32(data[offset+4]) << 8) | uint32(data[offset+5])
72
+ merges = append(merges, [2]uint32{idx0, idx1})
73
+ }
74
+ return merges
75
+ }
76
+
77
+ // Escape raw byte token for JSON formatting
78
+ func escapeJsonString(token []byte) string {
79
+ var sb strings.Builder
80
+ for _, b := range token {
81
+ switch b {
82
+ case '"':
83
+ sb.WriteString(`\"`)
84
+ case '\\':
85
+ sb.WriteString(`\\`)
86
+ case '\n':
87
+ sb.WriteString(`\n`)
88
+ case '\r':
89
+ sb.WriteString(`\r`)
90
+ case '\t':
91
+ sb.WriteString(`\t`)
92
+ default:
93
+ if b < 0x20 {
94
+ sb.WriteString(fmt.Sprintf(`\u%04x`, b))
95
+ } else {
96
+ sb.WriteByte(b)
97
+ }
98
+ }
99
+ }
100
+ return sb.String()
101
+ }
102
+
103
+ func main() {
104
+ fmt.Println("=========================================================")
105
+ fmt.Println(" GO UFO TOKENIZER DECODER & RECONSTRUCTOR")
106
+ fmt.Println(" Watermark: ip zymatica.space")
107
+ fmt.Println("=========================================================")
108
+
109
+ // Read decompressed payload
110
+ decompFile := "../qwen-3.5-0.8b-28chirps-tokenizer.decompressed"
111
+ decompressed, err := os.ReadFile(decompFile)
112
+ if err != nil {
113
+ fmt.Printf("[-] Error opening decompressed payload file: %v\n", err)
114
+ os.Exit(1)
115
+ }
116
+ fmt.Printf("[+] Loaded decompressed capsule payload: %d bytes.\n", len(decompressed))
117
+
118
+ // Verify Magic Header and Mode
119
+ pos := 0
120
+ if decompressed[pos] != 0xC5 || decompressed[pos+1] != 0x54 || decompressed[pos+2] != 0x4B {
121
+ fmt.Println("[-] Error: Invalid magic header.")
122
+ os.Exit(1)
123
+ }
124
+ pos += 3
125
+ mode := decompressed[pos]
126
+ pos += 1
127
+ fmt.Printf(" Magic bytes verified. Mode: Mode %d\n", mode)
128
+
129
+ if mode != 1 {
130
+ fmt.Println("[-] Error: Only Mode 1 (Absolute) is supported by Go local decoder.")
131
+ os.Exit(1)
132
+ }
133
+
134
+ // Skip config block
135
+ compConfigLen := int(binary.BigEndian.Uint32(decompressed[pos : pos+4]))
136
+ pos += 4
137
+ fmt.Printf(" Skipping config block of length: %d bytes.\n", compConfigLen)
138
+ pos += compConfigLen
139
+
140
+ // Read Vocab
141
+ vocabNum := int(binary.BigEndian.Uint32(decompressed[pos : pos+4]))
142
+ pos += 4
143
+ vocabLen := int(binary.BigEndian.Uint32(decompressed[pos : pos+4]))
144
+ pos += 4
145
+ fmt.Printf(" Reading vocabulary tokens: %d items, data size: %d bytes.\n", vocabNum, vocabLen)
146
+
147
+ vocabData := decompressed[pos : pos+vocabLen]
148
+ pos += vocabLen
149
+
150
+ // Decompress Vocab using UFO algorithms
151
+ restoredVocab := DecompressVocab(vocabData, vocabNum)
152
+ fmt.Printf("[+] Reconstructed vocabulary: %d tokens.\n", len(restoredVocab))
153
+
154
+ // Read Merges
155
+ mergesNum := int(binary.BigEndian.Uint32(decompressed[pos : pos+4]))
156
+ pos += 4
157
+ fmt.Printf(" Reading merges block: %d pairs.\n", mergesNum)
158
+
159
+ mergesData := decompressed[pos : pos+mergesNum*6]
160
+ pos += mergesNum * 6
161
+
162
+ // Decompress Merges using UFO algorithms
163
+ restoredMerges := DecompressMerges(mergesData)
164
+ fmt.Printf("[+] Reconstructed merges: %d pairs.\n", len(restoredMerges))
165
+
166
+ // Write vocab.json using buffered I/O
167
+ vocabFile := "vocab.json"
168
+ outVocab, err := os.Create(vocabFile)
169
+ if err != nil {
170
+ fmt.Printf("[-] Error creating file %s: %v\n", vocabFile, err)
171
+ os.Exit(1)
172
+ }
173
+ defer outVocab.Close()
174
+ writer := bufio.NewWriter(outVocab)
175
+ writer.WriteString("{\n")
176
+ for i := 0; i < len(restoredVocab); i++ {
177
+ escaped := escapeJsonString(restoredVocab[i])
178
+ if i < len(restoredVocab)-1 {
179
+ writer.WriteString(fmt.Sprintf(" \"%s\": %d,\n", escaped, i))
180
+ } else {
181
+ writer.WriteString(fmt.Sprintf(" \"%s\": %d\n", escaped, i))
182
+ }
183
+ }
184
+ writer.WriteString("}\n")
185
+ writer.Flush()
186
+ fmt.Printf("[+] Saved reconstructed %s to current directory.\n", vocabFile)
187
+
188
+ // Write merges.txt using buffered I/O
189
+ mergesFile := "merges.txt"
190
+ outMerges, err := os.Create(mergesFile)
191
+ if err != nil {
192
+ fmt.Printf("[-] Error creating file %s: %v\n", mergesFile, err)
193
+ os.Exit(1)
194
+ }
195
+ defer outMerges.Close()
196
+ writerMerges := bufio.NewWriter(outMerges)
197
+ for _, pair := range restoredMerges {
198
+ t0 := restoredVocab[pair[0]]
199
+ t1 := restoredVocab[pair[1]]
200
+ writerMerges.Write(t0)
201
+ writerMerges.WriteByte(' ')
202
+ writerMerges.Write(t1)
203
+ writerMerges.WriteByte('\n')
204
+ }
205
+ writerMerges.Flush()
206
+ fmt.Printf("[+] Saved reconstructed %s to current directory.\n", mergesFile)
207
+
208
+ // Copy config files from local models directory
209
+ fmt.Println(" Copying tokenizer configuration files...")
210
+ copyFile("j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json", "/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json", "tokenizer_config.json")
211
+ copyFile("j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json", "/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json", "tokenizer.json")
212
+
213
+ fmt.Println("=========================================================")
214
+ fmt.Println(" GO DECODER SUCCESSFUL!")
215
+ fmt.Println("=========================================================")
216
+ }
217
+
218
+ // Copy file helper
219
+ func copyFile(src, fallback, dst string) {
220
+ targetSrc := src
221
+ if _, err := os.Stat(targetSrc); os.IsNotExist(err) {
222
+ targetSrc = fallback
223
+ }
224
+ if _, err := os.Stat(targetSrc); os.IsNotExist(err) {
225
+ return
226
+ }
227
+ in, err := os.Open(targetSrc)
228
+ if err != nil {
229
+ return
230
+ }
231
+ defer in.Close()
232
+ out, err := os.Create(dst)
233
+ if err != nil {
234
+ return
235
+ }
236
+ defer out.Close()
237
+ io.Copy(out, in)
238
+ fmt.Printf("[+] Copied %s to current directory.\n", filepath.Base(targetSrc))
239
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42
3
+ size 12807982
tokenizer_coder_test.go ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package ufo
2
+
3
+ import (
4
+ "bytes"
5
+ "fmt"
6
+ "testing"
7
+ )
8
+
9
+ func TestTokenizerCoder(t *testing.T) {
10
+ fmt.Println("=========================================================")
11
+ fmt.Println(" RUNNING GO UFO TOKENIZER CODER VERIFICATION")
12
+ fmt.Println(" Watermark: ip zymatica.space")
13
+ fmt.Println("=========================================================")
14
+
15
+ // 1. Test Vocab Coder
16
+ fmt.Println("\n[Test 1] Prefix-Suffix Vocab Coder...")
17
+ originalVocab := [][]byte{
18
+ []byte("hello"),
19
+ []byte("hell"),
20
+ []byte("heaven"),
21
+ []byte("heavy"),
22
+ []byte("world"),
23
+ []byte("word"),
24
+ []byte("work"),
25
+ []byte("worker"),
26
+ []byte("working"),
27
+ }
28
+
29
+ compressedVocab := CompressVocab(originalVocab)
30
+ fmt.Printf(" Original vocab items: %d\n", len(originalVocab))
31
+ fmt.Printf(" Compressed vocab size: %d bytes\n", len(compressedVocab))
32
+
33
+ restoredVocab := DecompressVocab(compressedVocab, len(originalVocab))
34
+ fmt.Printf(" Restored vocab items: %d\n", len(restoredVocab))
35
+
36
+ if len(originalVocab) != len(restoredVocab) {
37
+ t.Fatalf("Vocab length mismatch: expected %d, got %d", len(originalVocab), len(restoredVocab))
38
+ }
39
+ for i := range originalVocab {
40
+ if !bytes.Equal(originalVocab[i], restoredVocab[i]) {
41
+ t.Fatalf("Vocab item mismatch at index %d: expected %s, got %s", i, originalVocab[i], restoredVocab[i])
42
+ }
43
+ }
44
+ fmt.Println(" [+] Vocab round-trip: SUCCESS (100% Match)")
45
+
46
+ // 2. Test BPE Merges Coder
47
+ fmt.Println("\n[Test 2] BPE Merges Binary Index Coder...")
48
+ originalMerges := [][2]uint32{
49
+ {1015, 2030},
50
+ {45, 12},
51
+ {16777215, 50000},
52
+ {0, 1},
53
+ {100000, 200000},
54
+ }
55
+
56
+ compressedMerges := CompressMerges(originalMerges)
57
+ fmt.Printf(" Original merges items: %d\n", len(originalMerges))
58
+ fmt.Printf(" Compressed merges size: %d bytes\n", len(compressedMerges))
59
+
60
+ restoredMerges := DecompressMerges(compressedMerges)
61
+ fmt.Printf(" Restored merges items: %d\n", len(restoredMerges))
62
+
63
+ if len(originalMerges) != len(restoredMerges) {
64
+ t.Fatalf("Merges length mismatch: expected %d, got %d", len(originalMerges), len(restoredMerges))
65
+ }
66
+ for i := range originalMerges {
67
+ if originalMerges[i] != restoredMerges[i] {
68
+ t.Fatalf("Merges item mismatch at index %d: expected %v, got %v", i, originalMerges[i], restoredMerges[i])
69
+ }
70
+ }
71
+ fmt.Println(" [+] Merges round-trip: SUCCESS (100% Match)")
72
+
73
+ // 3. Test XOR-FEC Parity
74
+ fmt.Println("\n[Test 3] XOR-FEC Parity Calculation...")
75
+ c1 := []byte{0xAA, 0xBB, 0xCC, 0xDD}
76
+ c2 := []byte{0x11, 0x22, 0x33, 0x44}
77
+ c3 := []byte{0x55, 0x66, 0x77, 0x88}
78
+ chunks := [][]byte{c1, c2, c3}
79
+
80
+ parity := ComputeXorFecParity(chunks, 4)
81
+ expectedParity := []byte{
82
+ 0xAA ^ 0x11 ^ 0x55,
83
+ 0xBB ^ 0x22 ^ 0x66,
84
+ 0xCC ^ 0x33 ^ 0x77,
85
+ 0xDD ^ 0x44 ^ 0x88,
86
+ }
87
+
88
+ if !bytes.Equal(parity, expectedParity) {
89
+ t.Fatalf("Parity mismatch: expected %v, got %v", expectedParity, parity)
90
+ }
91
+ fmt.Println(" [+] XOR-FEC computation: SUCCESS")
92
+
93
+ fmt.Println("\n=========================================================")
94
+ fmt.Println(" ALL GO TESTS PASSED SUCCESSFULLY!")
95
+ fmt.Println("=========================================================")
96
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "248044": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "248045": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "248046": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "248047": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "248048": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "248049": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "248050": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "248051": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "248052": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "248053": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "248054": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "248055": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "248056": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "248057": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "248058": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "248059": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "248060": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "248061": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "248062": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "248063": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "248064": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "248065": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "248066": {
181
+ "content": "<tool_response>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "248067": {
189
+ "content": "</tool_response>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "248068": {
197
+ "content": "<think>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "248069": {
205
+ "content": "</think>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "248070": {
213
+ "content": "<|audio_start|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "248071": {
221
+ "content": "<|audio_end|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "248072": {
229
+ "content": "<tts_pad>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "248073": {
237
+ "content": "<tts_text_bos>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "248074": {
245
+ "content": "<tts_text_eod>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "248075": {
253
+ "content": "<tts_text_bos_single>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "248076": {
261
+ "content": "<|audio_pad|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ }
268
+ },
269
+ "additional_special_tokens": [
270
+ "<|im_start|>",
271
+ "<|im_end|>",
272
+ "<|object_ref_start|>",
273
+ "<|object_ref_end|>",
274
+ "<|box_start|>",
275
+ "<|box_end|>",
276
+ "<|quad_start|>",
277
+ "<|quad_end|>",
278
+ "<|vision_start|>",
279
+ "<|vision_end|>",
280
+ "<|vision_pad|>",
281
+ "<|image_pad|>",
282
+ "<|video_pad|>"
283
+ ],
284
+ "bos_token": null,
285
+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\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 {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is true %}\n {{- '<think>\\n' }}\n {%- else %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
286
+ "clean_up_tokenization_spaces": false,
287
+ "eos_token": "<|im_end|>",
288
+ "errors": "replace",
289
+ "model_max_length": 262144,
290
+ "pad_token": "<|endoftext|>",
291
+ "split_special_tokens": false,
292
+ "tokenizer_class": "Qwen2Tokenizer",
293
+ "unk_token": null,
294
+ "add_bos_token": false,
295
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
296
+ "extra_special_tokens": {
297
+ "audio_bos_token": "<|audio_start|>",
298
+ "audio_eos_token": "<|audio_end|>",
299
+ "audio_token": "<|audio_pad|>",
300
+ "image_token": "<|image_pad|>",
301
+ "video_token": "<|video_pad|>",
302
+ "vision_bos_token": "<|vision_start|>",
303
+ "vision_eos_token": "<|vision_end|>"
304
+ }
305
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff