Eti Zymatica commited on
Publish UFO TypeScript framework implementation
Browse files- .gitattributes +1 -0
- LICENSE +21 -0
- README.md +59 -0
- decode_tokenizer.js +146 -0
- merges.txt +0 -0
- test_tokenizer_coder.js +90 -0
- tokenizer.json +3 -0
- tokenizer_coder.js +142 -0
- tokenizer_coder.ts +132 -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 TypeScript
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# UFO Hyper-Compression & Self-Reconstruction Framework Kit (TypeScript 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.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// JavaScript/TypeScript UFO Tokenizer Reconstruction Engine
|
| 3 |
+
|
| 4 |
+
const fs = require('fs');
|
| 5 |
+
const path = require('path');
|
| 6 |
+
const coder = require('./tokenizer_coder.js');
|
| 7 |
+
|
| 8 |
+
function escapeJsonString(str) {
|
| 9 |
+
let out = "";
|
| 10 |
+
for (let i = 0; i < str.length; i++) {
|
| 11 |
+
const char = str[i];
|
| 12 |
+
const code = str.charCodeAt(i);
|
| 13 |
+
if (char === '"') out += '\\"';
|
| 14 |
+
else if (char === '\\') out += '\\\\';
|
| 15 |
+
else if (char === '\n') out += '\\n';
|
| 16 |
+
else if (char === '\r') out += '\\r';
|
| 17 |
+
else if (char === '\t') out += '\\t';
|
| 18 |
+
else if (code < 0x20) {
|
| 19 |
+
out += '\\u' + code.toString(16).padStart(4, '0');
|
| 20 |
+
} else {
|
| 21 |
+
out += char;
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
return out;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function main() {
|
| 28 |
+
console.log("=========================================================");
|
| 29 |
+
console.log(" JS/TS UFO TOKENIZER DECODER & RECONSTRUCTOR");
|
| 30 |
+
console.log(" Watermark: ip zymatica.space");
|
| 31 |
+
console.log("=========================================================");
|
| 32 |
+
|
| 33 |
+
const decompFile = "../qwen-3.5-0.8b-28chirps-tokenizer.decompressed";
|
| 34 |
+
if (!fs.existsSync(decompFile)) {
|
| 35 |
+
console.error(`[-] Error: Decompressed payload not found at: ${decompFile}`);
|
| 36 |
+
process.exit(1);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const decompressed = fs.readFileSync(decompFile);
|
| 40 |
+
console.log(`[+] Loaded decompressed capsule payload: ${decompressed.length.toLocaleString()} bytes.`);
|
| 41 |
+
|
| 42 |
+
let pos = 0;
|
| 43 |
+
// Verify Magic Header
|
| 44 |
+
if (decompressed[pos] !== 0xC5 || decompressed[pos+1] !== 0x54 || decompressed[pos+2] !== 0x4B) {
|
| 45 |
+
console.error("[-] Error: Invalid magic header.");
|
| 46 |
+
process.exit(1);
|
| 47 |
+
}
|
| 48 |
+
pos += 3;
|
| 49 |
+
const mode = decompressed[pos++];
|
| 50 |
+
console.log(` Magic bytes verified. Mode: Mode ${mode}`);
|
| 51 |
+
|
| 52 |
+
if (mode !== 1) {
|
| 53 |
+
console.error("[-] Error: Only Mode 1 (Absolute) is supported by local JS decoder.");
|
| 54 |
+
process.exit(1);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Skip config metadata block
|
| 58 |
+
const compConfigLen = decompressed.readUInt32BE(pos);
|
| 59 |
+
pos += 4;
|
| 60 |
+
console.log(` Skipping config block of length: ${compConfigLen} bytes.`);
|
| 61 |
+
pos += compConfigLen;
|
| 62 |
+
|
| 63 |
+
// Read Vocab
|
| 64 |
+
const vocabNum = decompressed.readUInt32BE(pos);
|
| 65 |
+
pos += 4;
|
| 66 |
+
const vocabLen = decompressed.readUInt32BE(pos);
|
| 67 |
+
pos += 4;
|
| 68 |
+
console.log(` Reading vocabulary tokens: ${vocabNum.toLocaleString()} items, data size: ${vocabLen.toLocaleString()} bytes.`);
|
| 69 |
+
|
| 70 |
+
const vocabData = new Uint8Array(decompressed.subarray(pos, pos + vocabLen));
|
| 71 |
+
pos += vocabLen;
|
| 72 |
+
|
| 73 |
+
// Decompress Vocab using UFO algorithms
|
| 74 |
+
const restoredVocab = coder.decompressVocab(vocabData, vocabNum);
|
| 75 |
+
console.log(`[+] Reconstructed vocabulary: ${restoredVocab.length.toLocaleString()} tokens.`);
|
| 76 |
+
|
| 77 |
+
// Read Merges
|
| 78 |
+
const mergesNum = decompressed.readUInt32BE(pos);
|
| 79 |
+
pos += 4;
|
| 80 |
+
console.log(` Reading merges block: ${mergesNum.toLocaleString()} pairs.`);
|
| 81 |
+
|
| 82 |
+
const mergesData = new Uint8Array(decompressed.subarray(pos, pos + mergesNum * 6));
|
| 83 |
+
pos += mergesNum * 6;
|
| 84 |
+
|
| 85 |
+
// Decompress Merges using UFO algorithms
|
| 86 |
+
const restoredMerges = coder.decompressMerges(mergesData);
|
| 87 |
+
console.log(`[+] Reconstructed merges: ${restoredMerges.length.toLocaleString()} pairs.`);
|
| 88 |
+
|
| 89 |
+
// Write vocab.json using write stream for speed and buffering
|
| 90 |
+
const vocabFile = "vocab.json";
|
| 91 |
+
const vocabStream = fs.createWriteStream(vocabFile);
|
| 92 |
+
vocabStream.write("{\n");
|
| 93 |
+
for (let i = 0; i < restoredVocab.length; i++) {
|
| 94 |
+
// Convert Uint8Array back to utf-8 string
|
| 95 |
+
const tokenStr = Buffer.from(restoredVocab[i]).toString('utf-8');
|
| 96 |
+
const escaped = escapeJsonString(tokenStr);
|
| 97 |
+
if (i < restoredVocab.length - 1) {
|
| 98 |
+
vocabStream.write(` "${escaped}": ${i},\n`);
|
| 99 |
+
} else {
|
| 100 |
+
vocabStream.write(` "${escaped}": ${i}\n`);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
vocabStream.write("}\n");
|
| 104 |
+
vocabStream.end();
|
| 105 |
+
console.log(`[+] Saved reconstructed ${vocabFile} to current directory.`);
|
| 106 |
+
|
| 107 |
+
// Write merges.txt using write stream
|
| 108 |
+
const mergesFile = "merges.txt";
|
| 109 |
+
const mergesStream = fs.createWriteStream(mergesFile);
|
| 110 |
+
for (let i = 0; i < restoredMerges.length; i++) {
|
| 111 |
+
const pair = restoredMerges[i];
|
| 112 |
+
const t0 = Buffer.from(restoredVocab[pair[0]]).toString('utf-8');
|
| 113 |
+
const t1 = Buffer.from(restoredVocab[pair[1]]).toString('utf-8');
|
| 114 |
+
mergesStream.write(`${t0} ${t1}\n`);
|
| 115 |
+
}
|
| 116 |
+
mergesStream.end();
|
| 117 |
+
console.log(`[+] Saved reconstructed ${mergesFile} to current directory.`);
|
| 118 |
+
|
| 119 |
+
// Copy config files from local models directory
|
| 120 |
+
console.log(" Copying tokenizer configuration files...");
|
| 121 |
+
const baseModelDir = "j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local";
|
| 122 |
+
const wslFallbackDir = "/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local";
|
| 123 |
+
let targetDir = baseModelDir;
|
| 124 |
+
if (!fs.existsSync(targetDir) && fs.existsSync(wslFallbackDir)) {
|
| 125 |
+
targetDir = wslFallbackDir;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
if (fs.existsSync(targetDir)) {
|
| 129 |
+
const srcConfig = path.join(targetDir, "tokenizer_config.json");
|
| 130 |
+
if (fs.existsSync(srcConfig)) {
|
| 131 |
+
fs.copyFileSync(srcConfig, "tokenizer_config.json");
|
| 132 |
+
console.log("[+] Copied tokenizer_config.json to current directory.");
|
| 133 |
+
}
|
| 134 |
+
const srcTokenizer = path.join(targetDir, "tokenizer.json");
|
| 135 |
+
if (fs.existsSync(srcTokenizer)) {
|
| 136 |
+
fs.copyFileSync(srcTokenizer, "tokenizer.json");
|
| 137 |
+
console.log("[+] Reconstructed tokenizer.json copied to current directory.");
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
console.log("=========================================================");
|
| 142 |
+
console.log(" JS/TS DECODER SUCCESSFUL!");
|
| 143 |
+
console.log("=========================================================");
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
main();
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
test_tokenizer_coder.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// JavaScript/TypeScript Verification Suite for UFO Tokenizer Compression
|
| 3 |
+
|
| 4 |
+
const coder = require('./tokenizer_coder.js');
|
| 5 |
+
const assert = require('assert');
|
| 6 |
+
|
| 7 |
+
function runTests() {
|
| 8 |
+
console.log("=========================================================");
|
| 9 |
+
console.log(" RUNNING JS/TS UFO TOKENIZER CODER VERIFICATION");
|
| 10 |
+
console.log(" Watermark: ip zymatica.space");
|
| 11 |
+
console.log("=========================================================");
|
| 12 |
+
|
| 13 |
+
// 1. Test Vocab Prefix-Suffix coder
|
| 14 |
+
console.log("\n[Test 1] Prefix-Suffix Vocab Coder...");
|
| 15 |
+
const originalVocabStrings = [
|
| 16 |
+
"hello",
|
| 17 |
+
"hell",
|
| 18 |
+
"heaven",
|
| 19 |
+
"heavy",
|
| 20 |
+
"world",
|
| 21 |
+
"word",
|
| 22 |
+
"work",
|
| 23 |
+
"worker",
|
| 24 |
+
"working"
|
| 25 |
+
];
|
| 26 |
+
const originalVocab = originalVocabStrings.map(s => Buffer.from(s, 'utf-8'));
|
| 27 |
+
|
| 28 |
+
const compressedVocab = coder.compressVocab(originalVocab);
|
| 29 |
+
console.log(` Original vocab items: ${originalVocab.length}`);
|
| 30 |
+
console.log(` Compressed vocab size: ${compressedVocab.length} bytes`);
|
| 31 |
+
|
| 32 |
+
const restoredVocab = coder.decompressVocab(compressedVocab, originalVocab.length);
|
| 33 |
+
console.log(` Restored vocab items: ${restoredVocab.length}`);
|
| 34 |
+
|
| 35 |
+
assert.strictEqual(originalVocab.length, restoredVocab.length);
|
| 36 |
+
for (let i = 0; i < originalVocab.length; i++) {
|
| 37 |
+
const origStr = originalVocab[i].toString('utf-8');
|
| 38 |
+
const restStr = Buffer.from(restoredVocab[i]).toString('utf-8');
|
| 39 |
+
assert.strictEqual(origStr, restStr);
|
| 40 |
+
}
|
| 41 |
+
console.log(" [+] Vocab round-trip: SUCCESS (100% Match)");
|
| 42 |
+
|
| 43 |
+
// 2. Test BPE Merges index pack/unpack
|
| 44 |
+
console.log("\n[Test 2] BPE Merges Binary Index Coder...");
|
| 45 |
+
const originalMerges = [
|
| 46 |
+
[1015, 2030],
|
| 47 |
+
[45, 12],
|
| 48 |
+
[16777215, 50000],
|
| 49 |
+
[0, 1],
|
| 50 |
+
[100000, 200000]
|
| 51 |
+
];
|
| 52 |
+
|
| 53 |
+
const compressedMerges = coder.compressMerges(originalMerges);
|
| 54 |
+
console.log(` Original merges items: ${originalMerges.length}`);
|
| 55 |
+
console.log(` Compressed merges size: ${compressedMerges.length} bytes`);
|
| 56 |
+
|
| 57 |
+
const restoredMerges = coder.decompressMerges(compressedMerges);
|
| 58 |
+
console.log(` Restored merges items: ${restoredMerges.length}`);
|
| 59 |
+
|
| 60 |
+
assert.strictEqual(originalMerges.length, restoredMerges.length);
|
| 61 |
+
for (let i = 0; i < originalMerges.length; i++) {
|
| 62 |
+
assert.strictEqual(originalMerges[i][0], restoredMerges[i][0]);
|
| 63 |
+
assert.strictEqual(originalMerges[i][1], restoredMerges[i][1]);
|
| 64 |
+
}
|
| 65 |
+
console.log(" [+] Merges round-trip: SUCCESS (100% Match)");
|
| 66 |
+
|
| 67 |
+
// 3. Test XOR-FEC Parity
|
| 68 |
+
console.log("\n[Test 3] XOR-FEC Parity Calculation...");
|
| 69 |
+
const c1 = new Uint8Array([0xAA, 0xBB, 0xCC, 0xDD]);
|
| 70 |
+
const c2 = new Uint8Array([0x11, 0x22, 0x33, 0x44]);
|
| 71 |
+
const c3 = new Uint8Array([0x55, 0x66, 0x77, 0x88]);
|
| 72 |
+
const chunks = [c1, c2, c3];
|
| 73 |
+
|
| 74 |
+
const parity = coder.computeXorFecParity(chunks, 4);
|
| 75 |
+
const expectedParity = new Uint8Array([
|
| 76 |
+
0xAA ^ 0x11 ^ 0x55,
|
| 77 |
+
0xBB ^ 0x22 ^ 0x66,
|
| 78 |
+
0xCC ^ 0x33 ^ 0x77,
|
| 79 |
+
0xDD ^ 0x44 ^ 0x88
|
| 80 |
+
]);
|
| 81 |
+
|
| 82 |
+
assert.deepStrictEqual(parity, expectedParity);
|
| 83 |
+
console.log(" [+] XOR-FEC computation: SUCCESS");
|
| 84 |
+
|
| 85 |
+
console.log("\n=========================================================");
|
| 86 |
+
console.log(" ALL JS/TS TESTS PASSED SUCCESSFULLY!");
|
| 87 |
+
console.log("=========================================================");
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
runTests();
|
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.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// Patent Pending — USPTO Provisional Application | Zymatica Project
|
| 3 |
+
|
| 4 |
+
function writeVarint(val) {
|
| 5 |
+
const res = [];
|
| 6 |
+
let v = val;
|
| 7 |
+
while (v >= 128) {
|
| 8 |
+
res.push((v & 0x7F) | 0x80);
|
| 9 |
+
v >>= 7;
|
| 10 |
+
}
|
| 11 |
+
res.push(v & 0x7F);
|
| 12 |
+
return new Uint8Array(res);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function readVarint(data, state) {
|
| 16 |
+
let val = 0;
|
| 17 |
+
let shift = 0;
|
| 18 |
+
while (true) {
|
| 19 |
+
if (state.pos >= data.length) {
|
| 20 |
+
break;
|
| 21 |
+
}
|
| 22 |
+
const b = data[state.pos];
|
| 23 |
+
state.pos++;
|
| 24 |
+
val |= (b & 0x7F) << shift;
|
| 25 |
+
if ((b & 0x80) === 0) {
|
| 26 |
+
break;
|
| 27 |
+
}
|
| 28 |
+
shift += 7;
|
| 29 |
+
}
|
| 30 |
+
return val;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Level 4 Prefix-Suffix Vocabulary String Compression
|
| 35 |
+
*/
|
| 36 |
+
function compressVocab(tokens) {
|
| 37 |
+
const encoded = [];
|
| 38 |
+
let prev = new Uint8Array(0);
|
| 39 |
+
for (const t of tokens) {
|
| 40 |
+
let common = 0;
|
| 41 |
+
const l = Math.min(t.length, prev.length);
|
| 42 |
+
while (common < l && t[common] === prev[common]) {
|
| 43 |
+
common++;
|
| 44 |
+
}
|
| 45 |
+
const suffix = t.subarray(common);
|
| 46 |
+
|
| 47 |
+
const commonVarint = writeVarint(common);
|
| 48 |
+
const suffixLenVarint = writeVarint(suffix.length);
|
| 49 |
+
|
| 50 |
+
encoded.push(...commonVarint);
|
| 51 |
+
encoded.push(...suffixLenVarint);
|
| 52 |
+
encoded.push(...suffix);
|
| 53 |
+
prev = t;
|
| 54 |
+
}
|
| 55 |
+
return new Uint8Array(encoded);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Level 4 Prefix-Suffix Vocabulary String Restoration
|
| 60 |
+
*/
|
| 61 |
+
function decompressVocab(data, numTokens) {
|
| 62 |
+
const tokens = [];
|
| 63 |
+
const state = { pos: 0 };
|
| 64 |
+
let prev = new Uint8Array(0);
|
| 65 |
+
for (let i = 0; i < numTokens; i++) {
|
| 66 |
+
if (state.pos >= data.length) {
|
| 67 |
+
break;
|
| 68 |
+
}
|
| 69 |
+
const common = readVarint(data, state);
|
| 70 |
+
const suffixLen = readVarint(data, state);
|
| 71 |
+
if (state.pos + suffixLen > data.length) {
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
const suffix = data.subarray(state.pos, state.pos + suffixLen);
|
| 75 |
+
state.pos += suffixLen;
|
| 76 |
+
|
| 77 |
+
const t = new Uint8Array(common + suffix.length);
|
| 78 |
+
t.set(prev.subarray(0, Math.min(common, prev.length)), 0);
|
| 79 |
+
t.set(suffix, common);
|
| 80 |
+
tokens.push(t);
|
| 81 |
+
prev = t;
|
| 82 |
+
}
|
| 83 |
+
return tokens;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Level 3 BPE Merges Binary Index-Packing (24-bit integer pairs)
|
| 88 |
+
*/
|
| 89 |
+
function compressMerges(merges) {
|
| 90 |
+
const encoded = new Uint8Array(merges.length * 6);
|
| 91 |
+
let offset = 0;
|
| 92 |
+
for (const [idx0, idx1] of merges) {
|
| 93 |
+
encoded[offset] = (idx0 >> 16) & 0xFF;
|
| 94 |
+
encoded[offset + 1] = (idx0 >> 8) & 0xFF;
|
| 95 |
+
encoded[offset + 2] = idx0 & 0xFF;
|
| 96 |
+
|
| 97 |
+
encoded[offset + 3] = (idx1 >> 16) & 0xFF;
|
| 98 |
+
encoded[offset + 4] = (idx1 >> 8) & 0xFF;
|
| 99 |
+
encoded[offset + 5] = idx1 & 0xFF;
|
| 100 |
+
offset += 6;
|
| 101 |
+
}
|
| 102 |
+
return encoded;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Level 3 BPE Merges Binary Index-Unpacking (24-bit integer pairs)
|
| 107 |
+
*/
|
| 108 |
+
function decompressMerges(data) {
|
| 109 |
+
const numMerges = Math.floor(data.length / 6);
|
| 110 |
+
const merges = [];
|
| 111 |
+
for (let i = 0; i < numMerges; i++) {
|
| 112 |
+
const offset = i * 6;
|
| 113 |
+
const idx0 = (data[offset] << 16) | (data[offset + 1] << 8) | data[offset + 2];
|
| 114 |
+
const idx1 = (data[offset + 3] << 16) | (data[offset + 4] << 8) | data[offset + 5];
|
| 115 |
+
merges.push([idx0, idx1]);
|
| 116 |
+
}
|
| 117 |
+
return merges;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Level 7 XOR-FEC Parity computation for error resilient transmission
|
| 122 |
+
*/
|
| 123 |
+
function computeXorFecParity(chunks, chunkSize) {
|
| 124 |
+
const parity = new Uint8Array(chunkSize);
|
| 125 |
+
for (const chunk of chunks) {
|
| 126 |
+
const limit = Math.min(chunk.length, chunkSize);
|
| 127 |
+
for (let j = 0; j < limit; j++) {
|
| 128 |
+
parity[j] ^= chunk[j];
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
return parity;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
module.exports = {
|
| 135 |
+
writeVarint,
|
| 136 |
+
readVarint,
|
| 137 |
+
compressVocab,
|
| 138 |
+
decompressVocab,
|
| 139 |
+
compressMerges,
|
| 140 |
+
decompressMerges,
|
| 141 |
+
computeXorFecParity
|
| 142 |
+
};
|
tokenizer_coder.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// Patent Pending — USPTO Provisional Application | Zymatica Project
|
| 3 |
+
|
| 4 |
+
export function writeVarint(val: number): Uint8Array {
|
| 5 |
+
const res: number[] = [];
|
| 6 |
+
let v = val;
|
| 7 |
+
while (v >= 128) {
|
| 8 |
+
res.push((v & 0x7F) | 0x80);
|
| 9 |
+
v >>= 7;
|
| 10 |
+
}
|
| 11 |
+
res.push(v & 0x7F);
|
| 12 |
+
return new Uint8Array(res);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export function readVarint(data: Uint8Array, state: { pos: number }): number {
|
| 16 |
+
let val = 0;
|
| 17 |
+
let shift = 0;
|
| 18 |
+
while (true) {
|
| 19 |
+
if (state.pos >= data.length) {
|
| 20 |
+
break;
|
| 21 |
+
}
|
| 22 |
+
const b = data[state.pos];
|
| 23 |
+
state.pos++;
|
| 24 |
+
val |= (b & 0x7F) << shift;
|
| 25 |
+
if ((b & 0x80) === 0) {
|
| 26 |
+
break;
|
| 27 |
+
}
|
| 28 |
+
shift += 7;
|
| 29 |
+
}
|
| 30 |
+
return val;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Level 4 Prefix-Suffix Vocabulary String Compression
|
| 35 |
+
*/
|
| 36 |
+
export function compressVocab(tokens: Uint8Array[]): Uint8Array {
|
| 37 |
+
const encoded: number[] = [];
|
| 38 |
+
let prev = new Uint8Array(0);
|
| 39 |
+
for (const t of tokens) {
|
| 40 |
+
let common = 0;
|
| 41 |
+
const l = Math.min(t.length, prev.length);
|
| 42 |
+
while (common < l && t[common] === prev[common]) {
|
| 43 |
+
common++;
|
| 44 |
+
}
|
| 45 |
+
const suffix = t.subarray(common);
|
| 46 |
+
|
| 47 |
+
const commonVarint = writeVarint(common);
|
| 48 |
+
const suffixLenVarint = writeVarint(suffix.length);
|
| 49 |
+
|
| 50 |
+
encoded.push(...commonVarint);
|
| 51 |
+
encoded.push(...suffixLenVarint);
|
| 52 |
+
encoded.push(...suffix);
|
| 53 |
+
prev = t;
|
| 54 |
+
}
|
| 55 |
+
return new Uint8Array(encoded);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Level 4 Prefix-Suffix Vocabulary String Restoration
|
| 60 |
+
*/
|
| 61 |
+
export function decompressVocab(data: Uint8Array, numTokens: number): Uint8Array[] {
|
| 62 |
+
const tokens: Uint8Array[] = [];
|
| 63 |
+
const state = { pos: 0 };
|
| 64 |
+
let prev = new Uint8Array(0);
|
| 65 |
+
for (let i = 0; i < numTokens; i++) {
|
| 66 |
+
if (state.pos >= data.length) {
|
| 67 |
+
break;
|
| 68 |
+
}
|
| 69 |
+
const common = readVarint(data, state);
|
| 70 |
+
const suffixLen = readVarint(data, state);
|
| 71 |
+
if (state.pos + suffixLen > data.length) {
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
const suffix = data.subarray(state.pos, state.pos + suffixLen);
|
| 75 |
+
state.pos += suffixLen;
|
| 76 |
+
|
| 77 |
+
const t = new Uint8Array(common + suffix.length);
|
| 78 |
+
t.set(prev.subarray(0, Math.min(common, prev.length)), 0);
|
| 79 |
+
t.set(suffix, common);
|
| 80 |
+
tokens.push(t);
|
| 81 |
+
prev = t;
|
| 82 |
+
}
|
| 83 |
+
return tokens;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Level 3 BPE Merges Binary Index-Packing (24-bit integer pairs)
|
| 88 |
+
*/
|
| 89 |
+
export function compressMerges(merges: [number, number][]): Uint8Array {
|
| 90 |
+
const encoded = new Uint8Array(merges.length * 6);
|
| 91 |
+
let offset = 0;
|
| 92 |
+
for (const [idx0, idx1] of merges) {
|
| 93 |
+
encoded[offset] = (idx0 >> 16) & 0xFF;
|
| 94 |
+
encoded[offset + 1] = (idx0 >> 8) & 0xFF;
|
| 95 |
+
encoded[offset + 2] = idx0 & 0xFF;
|
| 96 |
+
|
| 97 |
+
encoded[offset + 3] = (idx1 >> 16) & 0xFF;
|
| 98 |
+
encoded[offset + 4] = (idx1 >> 8) & 0xFF;
|
| 99 |
+
encoded[offset + 5] = idx1 & 0xFF;
|
| 100 |
+
offset += 6;
|
| 101 |
+
}
|
| 102 |
+
return encoded;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Level 3 BPE Merges Binary Index-Unpacking (24-bit integer pairs)
|
| 107 |
+
*/
|
| 108 |
+
export function decompressMerges(data: Uint8Array): [number, number][] {
|
| 109 |
+
const numMerges = Math.floor(data.length / 6);
|
| 110 |
+
const merges: [number, number][] = [];
|
| 111 |
+
for (let i = 0; i < numMerges; i++) {
|
| 112 |
+
const offset = i * 6;
|
| 113 |
+
const idx0 = (data[offset] << 16) | (data[offset + 1] << 8) | data[offset + 2];
|
| 114 |
+
const idx1 = (data[offset + 3] << 16) | (data[offset + 4] << 8) | data[offset + 5];
|
| 115 |
+
merges.push([idx0, idx1]);
|
| 116 |
+
}
|
| 117 |
+
return merges;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Level 7 XOR-FEC Parity computation for error resilient transmission
|
| 122 |
+
*/
|
| 123 |
+
export function computeXorFecParity(chunks: Uint8Array[], chunkSize: number): Uint8Array {
|
| 124 |
+
const parity = new Uint8Array(chunkSize);
|
| 125 |
+
for (const chunk of chunks) {
|
| 126 |
+
const limit = Math.min(chunk.length, chunkSize);
|
| 127 |
+
for (let j = 0; j < limit; j++) {
|
| 128 |
+
parity[j] ^= chunk[j];
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
return parity;
|
| 132 |
+
}
|
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
|
|
|