Eti Zymatica commited on
Publish UFO Swift framework implementation
Browse files- .gitattributes +1 -0
- LICENSE +21 -0
- README.md +59 -0
- decode_tokenizer.swift +174 -0
- merges.txt +0 -0
- test_tokenizer_coder.swift +87 -0
- tokenizer.json +3 -0
- tokenizer_coder.swift +137 -0
- tokenizer_config.json +305 -0
- vocab.json +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PROPRIETARY INTELLECTUAL PROPERTY & PATENT PENDING NOTICE
|
| 2 |
+
=========================================================
|
| 3 |
+
Copyright (c) 2026 Zymatica / Language-U Project. All rights reserved.
|
| 4 |
+
|
| 5 |
+
NOTICE: ALL INFORMATION CONTAINED HEREIN IS, AND REMAINS THE PROPERTY OF
|
| 6 |
+
ZYMATICA AND ITS ASSOCIATES. THE INTELLECTUAL AND TECHNICAL CONCEPTS CONTAINED
|
| 7 |
+
HEREIN ARE PROPRIETARY TO ZYMATICA AND ARE PROTECTED BY U.S. PATENT LAW,
|
| 8 |
+
INTERNATIONAL PATENT CONVENTIONS, COPYRIGHT LAW, AND TRADE SECRET LAW.
|
| 9 |
+
|
| 10 |
+
Subject to USPTO Provisional Patent Application(s) filed/pending.
|
| 11 |
+
|
| 12 |
+
REPRODUCTION, DISSEMINATION, TRANSLATION, PORTING, OR MODIFICATION OF THIS
|
| 13 |
+
MATERIAL OR CODE IS STRICTLY FORBIDDEN UNLESS PRIOR WRITTEN PERMISSION IS
|
| 14 |
+
OBTAINED FROM ZYMATICA.
|
| 15 |
+
|
| 16 |
+
THE LICENSED SOFTWARE AND CODE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
| 17 |
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN
|
| 19 |
+
NO EVENT SHALL THE AUTHORS OR PATENT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES,
|
| 20 |
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE,
|
| 21 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR CODE.
|
README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
tags:
|
| 4 |
+
- ufo-compression
|
| 5 |
+
- model-quantization
|
| 6 |
+
- tokenizer-compression
|
| 7 |
+
- rust
|
| 8 |
+
- cpp
|
| 9 |
+
- go
|
| 10 |
+
- patent-evidence
|
| 11 |
+
language:
|
| 12 |
+
- en
|
| 13 |
+
pipeline_tag: translation
|
| 14 |
+
title: UFO Compression Swift
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# UFO Hyper-Compression & Self-Reconstruction Framework Kit (Swift Edition)
|
| 18 |
+
<!-- Patent Pending — USPTO Provisional Application | Watermark: ip zymatica.space -->
|
| 19 |
+
|
| 20 |
+
This repository houses the core algorithmic framework for the **UFO (Ultra-Frequency-Optimized) 7-Level Compression & Self-Reconstruction Pipeline**.
|
| 21 |
+
|
| 22 |
+
This codebase is published privately to establish legal ownership and empirical utility evidence for USPTO provisional patent filings. It includes multi-language system ports (Python, Rust, C++, Go) of the core serialization modules to prevent unlicensed translation or replication.
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## 1. Intellectual Property & Patent Claims
|
| 27 |
+
|
| 28 |
+
This framework implements the following proprietary claims under USPTO provisional applications:
|
| 29 |
+
|
| 30 |
+
1. **Claim 1 (Multidimensional Semantic Coordinate Indexing):** Decomposing conceptual queries and semantic structures into a 6D hypercube index along orthogonal axes (Domain, Subdomain, Operation, Modality, Depth, Polarity) represented as coordinate radicals ($R_C, R_F, R_A$).
|
| 31 |
+
2. **Claim 2 (Embedding-Driven Weight Projection - E-PAUP):** Representing weight deltas of target layers by projecting them onto pre-existing, shared word embedding matrices of the base model, eliminating coordinate transmission overhead.
|
| 32 |
+
3. **Claim 3 (Tokenizer Prefix-Suffix Varint Differential Coding):** Lossless tokenizer serialization storing tokens by ID order using variable-length prefix sharing indexes and suffix bytes, achieving a 9.37x stand-alone reduction and 3200x reference-mode reduction.
|
| 33 |
+
4. **Claim 4 (LLM-Logits-Driven Range Coding - LLD-AC):** Bypassing static coding tables by utilizing runtime logit probability distributions of the active model as dynamic entropy priors.
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## 2. Tokenizer 7-Level Compression Paradigm
|
| 38 |
+
|
| 39 |
+
The tokenizer framework compresses original metadata files (~23 MB) down to either a stand-alone 2.4 MB capsule or a 28-byte base-oracle reference capsule using a 7-Level descent:
|
| 40 |
+
|
| 41 |
+
* **Level 1 (Raw Baseline):** Loading raw `tokenizer.json`, `merges.txt`, `vocab.json` (23 MB).
|
| 42 |
+
* **Level 2 (Structured Extraction):** Isolating vocab mappings and merge tuples (15 MB).
|
| 43 |
+
* **Level 3 (Byte/ID Delta Packing):** Varint packing of contiguous IDs; merges represented as vocabulary index pairs (7 MB).
|
| 44 |
+
* **Level 4 (Prefix-Suffix Differential Compression):** Prefix character length extraction + suffix arrays (4 MB).
|
| 45 |
+
* **Level 5 (Base Oracle Reference):** Zero-delta alignment vs `Qwen/Qwen3.5-0.8B`.
|
| 46 |
+
* **Level 6 (Deflate Entropy Coding):** Zlib Level 9 hyper-deflate (2.4 MB absolute, 28 bytes reference).
|
| 47 |
+
* **Level 7 (XOR-FEC Chirp Packetization):** Packetization into 28 × 255-byte packets (27 data + 1 FEC parity).
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## 3. Multi-Language System Implementations
|
| 52 |
+
To ensure broad patent coverage and prevent unauthorized ports, the core algorithms have been transpiled and verified in:
|
| 53 |
+
* `python/`: Production-ready Python modules.
|
| 54 |
+
* `rust/`: Systems-level Rust implementation (`tokenizer_coder.rs`) for native speed.
|
| 55 |
+
* `cpp/`: Low-level C++ port (`tokenizer_coder.cpp` / `.hpp`) for embedded systems and edge microcontrollers.
|
| 56 |
+
* `go/`: Go port (`tokenizer_coder.go`) for high-concurrency server wrappers.
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
*Watermark: ip zymatica.space | astronautshe.com | Patent Pending — All Rights Reserved*
|
decode_tokenizer.swift
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
// Watermark: ip zymatica.space
|
| 2 |
+
// Swift UFO Tokenizer Reconstruction Engine
|
| 3 |
+
|
| 4 |
+
import Foundation
|
| 5 |
+
|
| 6 |
+
func readUInt32BE(_ data: [UInt8], _ pos: inout Int) -> UInt32 {
|
| 7 |
+
let val = (UInt32(data[pos]) << 24) |
|
| 8 |
+
(UInt32(data[pos + 1]) << 16) |
|
| 9 |
+
(UInt32(data[pos + 2]) << 8) |
|
| 10 |
+
UInt32(data[pos + 3])
|
| 11 |
+
pos += 4
|
| 12 |
+
return val
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
func escapeJsonString(_ str: String) -> String {
|
| 16 |
+
var out = ""
|
| 17 |
+
for char in str {
|
| 18 |
+
if char == "\"" { out += "\\\"" }
|
| 19 |
+
else if char == "\\" { out += "\\\\" }
|
| 20 |
+
else if char == "\n" { out += "\\n" }
|
| 21 |
+
else if char == "\r" { out += "\\r" }
|
| 22 |
+
else if char == "\t" { out += "\\t" }
|
| 23 |
+
else {
|
| 24 |
+
let scalars = char.unicodeScalars
|
| 25 |
+
if scalars.count == 1 && scalars.first!.value < 0x20 {
|
| 26 |
+
out += String(format: "\\u%04x", scalars.first!.value)
|
| 27 |
+
} else {
|
| 28 |
+
out.append(char)
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
return out
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
func main() {
|
| 36 |
+
print("=========================================================")
|
| 37 |
+
print(" SWIFT UFO TOKENIZER DECODER & RECONSTRUCTOR")
|
| 38 |
+
print(" Watermark: ip zymatica.space")
|
| 39 |
+
print("=========================================================")
|
| 40 |
+
|
| 41 |
+
let decompFile = "../qwen-3.5-0.8b-28chirps-tokenizer.decompressed"
|
| 42 |
+
let url = URL(fileURLWithPath: decompFile)
|
| 43 |
+
|
| 44 |
+
guard let fileData = try? Data(contentsOf: url) else {
|
| 45 |
+
print("[-] Error: Decompressed payload not found at: \(decompFile)")
|
| 46 |
+
exit(1)
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
let decompressed = [UInt8](fileData)
|
| 50 |
+
print("[+] Loaded decompressed capsule payload: \(decompressed.count) bytes.")
|
| 51 |
+
|
| 52 |
+
var pos = 0
|
| 53 |
+
// Verify Magic
|
| 54 |
+
if decompressed[pos] != 0xC5 || decompressed[pos+1] != 0x54 || decompressed[pos+2] != 0x4B {
|
| 55 |
+
print("[-] Error: Invalid magic header.")
|
| 56 |
+
exit(1)
|
| 57 |
+
}
|
| 58 |
+
pos += 3
|
| 59 |
+
let mode = decompressed[pos]
|
| 60 |
+
pos += 1
|
| 61 |
+
print(" Magic bytes verified. Mode: Mode \(mode)")
|
| 62 |
+
|
| 63 |
+
if mode != 1 {
|
| 64 |
+
print("[-] Error: Only Mode 1 (Absolute) is supported by local Swift decoder.")
|
| 65 |
+
exit(1)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
// Skip Config
|
| 69 |
+
let compConfigLen = Int(readUInt32BE(decompressed, &pos))
|
| 70 |
+
print(" Skipping config block of length: \(compConfigLen) bytes.")
|
| 71 |
+
pos += compConfigLen
|
| 72 |
+
|
| 73 |
+
// Read Vocab
|
| 74 |
+
let vocabNum = Int(readUInt32BE(decompressed, &pos))
|
| 75 |
+
let vocabLen = Int(readUInt32BE(decompressed, &pos))
|
| 76 |
+
print(" Reading vocabulary tokens: \(vocabNum) items, data size: \(vocabLen) bytes.")
|
| 77 |
+
|
| 78 |
+
let vocabData = Array(decompressed[pos..<(pos + vocabLen)])
|
| 79 |
+
pos += vocabLen
|
| 80 |
+
|
| 81 |
+
// Decompress Vocab using UFO algorithms
|
| 82 |
+
let restoredVocab = decompressVocab(vocabData, vocabNum)
|
| 83 |
+
print("[+] Reconstructed vocabulary: \(restoredVocab.count) tokens.")
|
| 84 |
+
|
| 85 |
+
// Read Merges
|
| 86 |
+
let mergesNum = Int(readUInt32BE(decompressed, &pos))
|
| 87 |
+
print(" Reading merges block: \(mergesNum) pairs.")
|
| 88 |
+
|
| 89 |
+
let mergesData = Array(decompressed[pos..<(pos + mergesNum * 6)])
|
| 90 |
+
pos += mergesNum * 6
|
| 91 |
+
|
| 92 |
+
// Decompress Merges using UFO algorithms
|
| 93 |
+
let restoredMerges = decompressMerges(mergesData)
|
| 94 |
+
print("[+] Reconstructed merges: \(restoredMerges.count) pairs.")
|
| 95 |
+
|
| 96 |
+
// Write vocab.json
|
| 97 |
+
let vocabFile = "vocab.json"
|
| 98 |
+
let vocabUrl = URL(fileURLWithPath: vocabFile)
|
| 99 |
+
|
| 100 |
+
let fm = FileManager.default
|
| 101 |
+
fm.createFile(atPath: vocabFile, contents: nil, attributes: nil)
|
| 102 |
+
|
| 103 |
+
if let vocabHandle = try? FileHandle(forWritingTo: vocabUrl) {
|
| 104 |
+
vocabHandle.write("{\n".data(using: .utf8)!)
|
| 105 |
+
for i in 0..<restoredVocab.count {
|
| 106 |
+
let tokenStr = String(decoding: restoredVocab[i], as: UTF8.self)
|
| 107 |
+
let escaped = escapeJsonString(tokenStr)
|
| 108 |
+
var line = ""
|
| 109 |
+
if i < restoredVocab.count - 1 {
|
| 110 |
+
line = " \"\(escaped)\": \(i),\n"
|
| 111 |
+
} else {
|
| 112 |
+
line = " \"\(escaped)\": \(i)\n"
|
| 113 |
+
}
|
| 114 |
+
vocabHandle.write(line.data(using: .utf8)!)
|
| 115 |
+
}
|
| 116 |
+
vocabHandle.write("}\n".data(using: .utf8)!)
|
| 117 |
+
vocabHandle.closeFile()
|
| 118 |
+
print("[+] Saved reconstructed \(vocabFile) to current directory.")
|
| 119 |
+
} else {
|
| 120 |
+
print("[-] Error writing vocab.json")
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Write merges.txt
|
| 124 |
+
let mergesFile = "merges.txt"
|
| 125 |
+
let mergesUrl = URL(fileURLWithPath: mergesFile)
|
| 126 |
+
fm.createFile(atPath: mergesFile, contents: nil, attributes: nil)
|
| 127 |
+
|
| 128 |
+
if let mergesHandle = try? FileHandle(forWritingTo: mergesUrl) {
|
| 129 |
+
for pair in restoredMerges {
|
| 130 |
+
let t0 = String(decoding: restoredVocab[Int(pair.0)], as: UTF8.self)
|
| 131 |
+
let t1 = String(decoding: restoredVocab[Int(pair.1)], as: UTF8.self)
|
| 132 |
+
let line = "\(t0) \(t1)\n"
|
| 133 |
+
mergesHandle.write(line.data(using: .utf8)!)
|
| 134 |
+
}
|
| 135 |
+
mergesHandle.closeFile()
|
| 136 |
+
print("[+] Saved reconstructed \(mergesFile) to current directory.")
|
| 137 |
+
} else {
|
| 138 |
+
print("[-] Error writing merges.txt")
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Copy config files from local models directory
|
| 142 |
+
print(" Copying tokenizer configuration files...")
|
| 143 |
+
let srcConfigPath = "j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json"
|
| 144 |
+
let fallbackConfigPath = "/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json"
|
| 145 |
+
var targetConfig = srcConfigPath
|
| 146 |
+
if !fm.fileExists(atPath: targetConfig) && fm.fileExists(atPath: fallbackConfigPath) {
|
| 147 |
+
targetConfig = fallbackConfigPath
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
if fm.fileExists(atPath: targetConfig) {
|
| 151 |
+
try? fm.removeItem(atPath: "tokenizer_config.json")
|
| 152 |
+
try? fm.copyItem(atPath: targetConfig, toPath: "tokenizer_config.json")
|
| 153 |
+
print("[+] Copied tokenizer_config.json to current directory.")
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
let srcTokenizerPath = "j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json"
|
| 157 |
+
let fallbackTokenizerPath = "/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json"
|
| 158 |
+
var targetTokenizer = srcTokenizerPath
|
| 159 |
+
if !fm.fileExists(atPath: targetTokenizer) && fm.fileExists(atPath: fallbackTokenizerPath) {
|
| 160 |
+
targetTokenizer = fallbackTokenizerPath
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
if fm.fileExists(atPath: targetTokenizer) {
|
| 164 |
+
try? fm.removeItem(atPath: "tokenizer.json")
|
| 165 |
+
try? fm.copyItem(atPath: targetTokenizer, toPath: "tokenizer.json")
|
| 166 |
+
print("[+] Reconstructed tokenizer.json copied to current directory.")
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
print("=========================================================")
|
| 170 |
+
print(" SWIFT DECODER SUCCESSFUL!")
|
| 171 |
+
print("=========================================================")
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
main()
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test_tokenizer_coder.swift
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// Verification suite for Swift UFO Tokenizer Coder
|
| 3 |
+
|
| 4 |
+
import Foundation
|
| 5 |
+
|
| 6 |
+
func runTests() {
|
| 7 |
+
print("=========================================================")
|
| 8 |
+
print(" RUNNING SWIFT UFO TOKENIZER CODER VERIFICATION")
|
| 9 |
+
print(" Watermark: ip zymatica.space")
|
| 10 |
+
print("=========================================================")
|
| 11 |
+
|
| 12 |
+
// 1. Test Vocab Prefix-Suffix Coder
|
| 13 |
+
print("\n[Test 1] Prefix-Suffix Vocab Coder...")
|
| 14 |
+
let originalVocabStrings = [
|
| 15 |
+
"hello",
|
| 16 |
+
"hell",
|
| 17 |
+
"heaven",
|
| 18 |
+
"heavy",
|
| 19 |
+
"world",
|
| 20 |
+
"word",
|
| 21 |
+
"work",
|
| 22 |
+
"worker",
|
| 23 |
+
"working"
|
| 24 |
+
]
|
| 25 |
+
let originalVocab = originalVocabStrings.map { [UInt8]($0.utf8) }
|
| 26 |
+
|
| 27 |
+
let compressedVocab = compressVocab(originalVocab)
|
| 28 |
+
print(" Original vocab items: \(originalVocab.count)")
|
| 29 |
+
print(" Compressed vocab size: \(compressedVocab.count) bytes")
|
| 30 |
+
|
| 31 |
+
let restoredVocab = decompressVocab(compressedVocab, originalVocab.count)
|
| 32 |
+
print(" Restored vocab items: \(restoredVocab.count)")
|
| 33 |
+
|
| 34 |
+
assert(originalVocab.count == restoredVocab.count)
|
| 35 |
+
for i in 0..<originalVocab.count {
|
| 36 |
+
assert(originalVocab[i] == restoredVocab[i], "Mismatch at index \(i)")
|
| 37 |
+
}
|
| 38 |
+
print(" [+] Vocab round-trip: SUCCESS (100% Match)")
|
| 39 |
+
|
| 40 |
+
// 2. Test BPE Merges index pack/unpack
|
| 41 |
+
print("\n[Test 2] BPE Merges Binary Index Coder...")
|
| 42 |
+
let originalMerges: [(UInt32, UInt32)] = [
|
| 43 |
+
(1015, 2030),
|
| 44 |
+
(45, 12),
|
| 45 |
+
(16777215, 50000),
|
| 46 |
+
(0, 1),
|
| 47 |
+
(100000, 200000)
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
let compressedMerges = compressMerges(originalMerges)
|
| 51 |
+
print(" Original merges items: \(originalMerges.count)")
|
| 52 |
+
print(" Compressed merges size: \(compressedMerges.count) bytes")
|
| 53 |
+
|
| 54 |
+
let restoredMerges = decompressMerges(compressedMerges)
|
| 55 |
+
print(" Restored merges items: \(restoredMerges.count)")
|
| 56 |
+
|
| 57 |
+
assert(originalMerges.count == restoredMerges.count)
|
| 58 |
+
for i in 0..<originalMerges.count {
|
| 59 |
+
assert(originalMerges[i].0 == restoredMerges[i].0)
|
| 60 |
+
assert(originalMerges[i].1 == restoredMerges[i].1)
|
| 61 |
+
}
|
| 62 |
+
print(" [+] Merges round-trip: SUCCESS (100% Match)")
|
| 63 |
+
|
| 64 |
+
// 3. Test XOR-FEC Parity
|
| 65 |
+
print("\n[Test 3] XOR-FEC Parity Calculation...")
|
| 66 |
+
let c1: [UInt8] = [0xAA, 0xBB, 0xCC, 0xDD]
|
| 67 |
+
let c2: [UInt8] = [0x11, 0x22, 0x33, 0x44]
|
| 68 |
+
let c3: [UInt8] = [0x55, 0x66, 0x77, 0x88]
|
| 69 |
+
let chunks = [c1, c2, c3]
|
| 70 |
+
|
| 71 |
+
let parity = computeXorFecParity(chunks, 4)
|
| 72 |
+
let expectedParity: [UInt8] = [
|
| 73 |
+
0xAA ^ 0x11 ^ 0x55,
|
| 74 |
+
0xBB ^ 0x22 ^ 0x66,
|
| 75 |
+
0xCC ^ 0x33 ^ 0x77,
|
| 76 |
+
0xDD ^ 0x44 ^ 0x88
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
assert(parity == expectedParity)
|
| 80 |
+
print(" [+] XOR-FEC computation: SUCCESS")
|
| 81 |
+
|
| 82 |
+
print("\n=========================================================")
|
| 83 |
+
print(" ALL SWIFT TESTS PASSED SUCCESSFULLY!")
|
| 84 |
+
print("=========================================================")
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
runTests()
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
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PTO Provisional Application | Zymatica Project
|
| 3 |
+
|
| 4 |
+
import Foundation
|
| 5 |
+
|
| 6 |
+
public func writeVarint(_ val: Int) -> [UInt8] {
|
| 7 |
+
var res = [UInt8]()
|
| 8 |
+
var v = val
|
| 9 |
+
while v >= 128 {
|
| 10 |
+
res.append(UInt8((v & 0x7F) | 0x80))
|
| 11 |
+
v >>= 7
|
| 12 |
+
}
|
| 13 |
+
res.append(UInt8(v & 0x7F))
|
| 14 |
+
return res
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
public func readVarint(_ data: [UInt8], _ pos: inout Int) -> Int {
|
| 18 |
+
var val = 0
|
| 19 |
+
var shift = 0
|
| 20 |
+
while true {
|
| 21 |
+
if pos >= data.count {
|
| 22 |
+
break
|
| 23 |
+
}
|
| 24 |
+
let b = data[pos]
|
| 25 |
+
pos += 1
|
| 26 |
+
val |= Int(b & 0x7F) << shift
|
| 27 |
+
if (b & 0x80) == 0 {
|
| 28 |
+
break
|
| 29 |
+
}
|
| 30 |
+
shift += 7
|
| 31 |
+
}
|
| 32 |
+
return val
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Level 4 Prefix-Suffix Vocabulary String Compression
|
| 37 |
+
*/
|
| 38 |
+
public func compressVocab(_ tokens: [[UInt8]]) -> [UInt8] {
|
| 39 |
+
var encoded = [UInt8]()
|
| 40 |
+
var prev = [UInt8]()
|
| 41 |
+
for t in tokens {
|
| 42 |
+
var common = 0
|
| 43 |
+
let l = min(t.count, prev.count)
|
| 44 |
+
while common < l && t[common] == prev[common] {
|
| 45 |
+
common += 1
|
| 46 |
+
}
|
| 47 |
+
let suffix = Array(t[common...])
|
| 48 |
+
encoded.append(contentsOf: writeVarint(common))
|
| 49 |
+
encoded.append(contentsOf: writeVarint(suffix.count))
|
| 50 |
+
encoded.append(contentsOf: suffix)
|
| 51 |
+
prev = t
|
| 52 |
+
}
|
| 53 |
+
return encoded
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Level 4 Prefix-Suffix Vocabulary String Restoration
|
| 58 |
+
*/
|
| 59 |
+
public func decompressVocab(_ data: [UInt8], _ numTokens: Int) -> [[UInt8]] {
|
| 60 |
+
var tokens = [[UInt8]]()
|
| 61 |
+
var pos = 0
|
| 62 |
+
var prev = [UInt8]()
|
| 63 |
+
for _ in 0..<numTokens {
|
| 64 |
+
if pos >= data.count {
|
| 65 |
+
break
|
| 66 |
+
}
|
| 67 |
+
let common = readVarint(data, &pos)
|
| 68 |
+
let suffixLen = readVarint(data, &pos)
|
| 69 |
+
if pos + suffixLen > data.count {
|
| 70 |
+
break
|
| 71 |
+
}
|
| 72 |
+
let suffix = Array(data[pos..<(pos + suffixLen)])
|
| 73 |
+
pos += suffixLen
|
| 74 |
+
|
| 75 |
+
var t = Array(prev[0..<min(common, prev.count)])
|
| 76 |
+
t.append(contentsOf: suffix)
|
| 77 |
+
tokens.append(t)
|
| 78 |
+
prev = t
|
| 79 |
+
}
|
| 80 |
+
return tokens
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Level 3 BPE Merges Binary Index-Packing (24-bit integer pairs)
|
| 85 |
+
*/
|
| 86 |
+
public func compressMerges(_ merges: [(UInt32, UInt32)]) -> [UInt8] {
|
| 87 |
+
var encoded = [UInt8]()
|
| 88 |
+
encoded.reserveCapacity(merges.count * 6)
|
| 89 |
+
for pair in merges {
|
| 90 |
+
let idx0 = pair.0
|
| 91 |
+
let idx1 = pair.1
|
| 92 |
+
|
| 93 |
+
encoded.append(UInt8((idx0 >> 16) & 0xFF))
|
| 94 |
+
encoded.append(UInt8((idx0 >> 8) & 0xFF))
|
| 95 |
+
encoded.append(UInt8(idx0 & 0xFF))
|
| 96 |
+
|
| 97 |
+
encoded.append(UInt8((idx1 >> 16) & 0xFF))
|
| 98 |
+
encoded.append(UInt8((idx1 >> 8) & 0xFF))
|
| 99 |
+
encoded.append(UInt8(idx1 & 0xFF))
|
| 100 |
+
}
|
| 101 |
+
return encoded
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* Level 3 BPE Merges Binary Index-Unpacking (24-bit integer pairs)
|
| 106 |
+
*/
|
| 107 |
+
public func decompressMerges(_ data: [UInt8]) -> [(UInt32, UInt32)] {
|
| 108 |
+
let numMerges = data.count / 6
|
| 109 |
+
var merges = [(UInt32, UInt32)]()
|
| 110 |
+
merges.reserveCapacity(numMerges)
|
| 111 |
+
for i in 0..<numMerges {
|
| 112 |
+
let offset = i * 6
|
| 113 |
+
let idx0 = (UInt32(data[offset]) << 16) |
|
| 114 |
+
(UInt32(data[offset + 1]) << 8) |
|
| 115 |
+
UInt32(data[offset + 2])
|
| 116 |
+
|
| 117 |
+
let idx1 = (UInt32(data[offset + 3]) << 16) |
|
| 118 |
+
(UInt32(data[offset + 4]) << 8) |
|
| 119 |
+
UInt32(data[offset + 5])
|
| 120 |
+
merges.append((idx0, idx1))
|
| 121 |
+
}
|
| 122 |
+
return merges
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Level 7 XOR-FEC Parity computation for error resilient transmission
|
| 127 |
+
*/
|
| 128 |
+
public func computeXorFecParity(_ chunks: [[UInt8]], _ chunkSize: Int) -> [UInt8] {
|
| 129 |
+
var parity = [UInt8](repeating: 0, count: chunkSize)
|
| 130 |
+
for chunk in chunks {
|
| 131 |
+
let limit = min(chunk.count, chunkSize)
|
| 132 |
+
for j in 0..<limit {
|
| 133 |
+
parity[j] ^= chunk[j]
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
return parity
|
| 137 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|