Eti Zymatica commited on
Publish UFO Java framework implementation
Browse files- .gitattributes +1 -0
- DecodeTokenizer.java +148 -0
- LICENSE +21 -0
- README.md +59 -0
- TestTokenizerCoder.java +106 -0
- merges.txt +0 -0
- tokenizer.json +3 -0
- tokenizer_config.json +305 -0
- ufo/TokenizerCoder.java +153 -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
|
DecodeTokenizer.java
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// JVM UFO Tokenizer Reconstruction Engine
|
| 3 |
+
|
| 4 |
+
import ufo.TokenizerCoder;
|
| 5 |
+
import java.io.*;
|
| 6 |
+
import java.nio.ByteBuffer;
|
| 7 |
+
import java.nio.charset.StandardCharsets;
|
| 8 |
+
import java.nio.file.Files;
|
| 9 |
+
import java.nio.file.Path;
|
| 10 |
+
import java.nio.file.Paths;
|
| 11 |
+
import java.util.List;
|
| 12 |
+
|
| 13 |
+
public class DecodeTokenizer {
|
| 14 |
+
|
| 15 |
+
private static String escapeJsonString(String str) {
|
| 16 |
+
StringBuilder sb = new StringBuilder();
|
| 17 |
+
for (int i = 0; i < str.length(); i++) {
|
| 18 |
+
char c = str.charAt(i);
|
| 19 |
+
if (c == '"') sb.append("\\\"");
|
| 20 |
+
else if (c == '\\') sb.append("\\\\");
|
| 21 |
+
else if (c == '\n') sb.append("\\n");
|
| 22 |
+
else if (c == '\r') sb.append("\\r");
|
| 23 |
+
else if (c == '\t') sb.append("\\t");
|
| 24 |
+
else if (c < 0x20) {
|
| 25 |
+
sb.append(String.format("\\u%04x", (int) c));
|
| 26 |
+
} else {
|
| 27 |
+
sb.append(c);
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
return sb.toString();
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
public static void main(String[] args) throws Exception {
|
| 34 |
+
System.out.println("=========================================================");
|
| 35 |
+
System.out.println(" JAVA UFO TOKENIZER DECODER & RECONSTRUCTOR");
|
| 36 |
+
System.out.println(" Watermark: ip zymatica.space");
|
| 37 |
+
System.out.println("=========================================================");
|
| 38 |
+
|
| 39 |
+
String decompFile = "../qwen-3.5-0.8b-28chirps-tokenizer.decompressed";
|
| 40 |
+
Path path = Paths.get(decompFile);
|
| 41 |
+
if (!Files.exists(path)) {
|
| 42 |
+
System.err.println("[-] Error: Decompressed payload not found at: " + decompFile);
|
| 43 |
+
System.exit(1);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
byte[] decompressed = Files.readAllBytes(path);
|
| 47 |
+
System.out.println("[+] Loaded decompressed capsule payload: " + String.format("%,d", decompressed.length) + " bytes.");
|
| 48 |
+
|
| 49 |
+
ByteBuffer buf = ByteBuffer.wrap(decompressed);
|
| 50 |
+
|
| 51 |
+
// Verify Magic
|
| 52 |
+
if (buf.get() != (byte)0xC5 || buf.get() != (byte)0x54 || buf.get() != (byte)0x4B) {
|
| 53 |
+
System.err.println("[-] Error: Invalid magic header.");
|
| 54 |
+
System.exit(1);
|
| 55 |
+
}
|
| 56 |
+
int mode = buf.get() & 0xFF;
|
| 57 |
+
System.out.println(" Magic bytes verified. Mode: Mode " + mode);
|
| 58 |
+
|
| 59 |
+
if (mode != 1) {
|
| 60 |
+
System.err.println("[-] Error: Only Mode 1 (Absolute) is supported by local Java decoder.");
|
| 61 |
+
System.exit(1);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Skip Config
|
| 65 |
+
int compConfigLen = buf.getInt();
|
| 66 |
+
System.out.println(" Skipping config block of length: " + compConfigLen + " bytes.");
|
| 67 |
+
buf.position(buf.position() + compConfigLen);
|
| 68 |
+
|
| 69 |
+
// Read Vocab
|
| 70 |
+
int vocabNum = buf.getInt();
|
| 71 |
+
int vocabLen = buf.getInt();
|
| 72 |
+
System.out.println(" Reading vocabulary tokens: " + String.format("%,d", vocabNum) + " items, data size: " + String.format("%,d", vocabLen) + " bytes.");
|
| 73 |
+
|
| 74 |
+
byte[] vocabData = new byte[vocabLen];
|
| 75 |
+
buf.get(vocabData);
|
| 76 |
+
|
| 77 |
+
// Decompress Vocab using UFO algorithms
|
| 78 |
+
List<byte[]> restoredVocab = TokenizerCoder.decompressVocab(vocabData, vocabNum);
|
| 79 |
+
System.out.println("[+] Reconstructed vocabulary: " + String.format("%,d", restoredVocab.size()) + " tokens.");
|
| 80 |
+
|
| 81 |
+
// Read Merges
|
| 82 |
+
int mergesNum = buf.getInt();
|
| 83 |
+
System.out.println(" Reading merges block: " + String.format("%,d", mergesNum) + " pairs.");
|
| 84 |
+
|
| 85 |
+
byte[] mergesData = new byte[mergesNum * 6];
|
| 86 |
+
buf.get(mergesData);
|
| 87 |
+
|
| 88 |
+
// Decompress Merges using UFO algorithms
|
| 89 |
+
List<int[]> restoredMerges = TokenizerCoder.decompressMerges(mergesData);
|
| 90 |
+
System.out.println("[+] Reconstructed merges: " + String.format("%,d", restoredMerges.size()) + " pairs.");
|
| 91 |
+
|
| 92 |
+
// Write vocab.json using BufferedWriter for speed
|
| 93 |
+
String vocabFile = "vocab.json";
|
| 94 |
+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(vocabFile))) {
|
| 95 |
+
writer.write("{\n");
|
| 96 |
+
for (int i = 0; i < restoredVocab.size(); i++) {
|
| 97 |
+
String tokenStr = new String(restoredVocab.get(i), StandardCharsets.UTF_8);
|
| 98 |
+
String escaped = escapeJsonString(tokenStr);
|
| 99 |
+
if (i < restoredVocab.size() - 1) {
|
| 100 |
+
writer.write(" \"" + escaped + "\": " + i + ",\n");
|
| 101 |
+
} else {
|
| 102 |
+
writer.write(" \"" + escaped + "\": " + i + "\n");
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
writer.write("}\n");
|
| 106 |
+
}
|
| 107 |
+
System.out.println("[+] Saved reconstructed " + vocabFile + " to current directory.");
|
| 108 |
+
|
| 109 |
+
// Write merges.txt using BufferedWriter
|
| 110 |
+
String mergesFile = "merges.txt";
|
| 111 |
+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(mergesFile))) {
|
| 112 |
+
for (int[] pair : restoredMerges) {
|
| 113 |
+
String t0 = new String(restoredVocab.get(pair[0]), StandardCharsets.UTF_8);
|
| 114 |
+
String t1 = new String(restoredVocab.get(pair[1]), StandardCharsets.UTF_8);
|
| 115 |
+
writer.write(t0 + " " + t1 + "\n");
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
System.out.println("[+] Saved reconstructed " + mergesFile + " to current directory.");
|
| 119 |
+
|
| 120 |
+
// Copy config files from local models directory
|
| 121 |
+
System.out.println(" Copying tokenizer configuration files...");
|
| 122 |
+
Path srcConfig = Paths.get("j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json");
|
| 123 |
+
Path fallbackConfig = Paths.get("/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer_config.json");
|
| 124 |
+
if (!Files.exists(srcConfig) && Files.exists(fallbackConfig)) {
|
| 125 |
+
srcConfig = fallbackConfig;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
if (Files.exists(srcConfig)) {
|
| 129 |
+
Files.copy(srcConfig, Paths.get("tokenizer_config.json"), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
| 130 |
+
System.out.println("[+] Copied tokenizer_config.json to current directory.");
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
Path srcTokenizer = Paths.get("j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json");
|
| 134 |
+
Path fallbackTokenizer = Paths.get("/mnt/j/Language-U/Language-U-V2/qwen-3.5-0.8b-local/tokenizer.json");
|
| 135 |
+
if (!Files.exists(srcTokenizer) && Files.exists(fallbackTokenizer)) {
|
| 136 |
+
srcTokenizer = fallbackTokenizer;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
if (Files.exists(srcTokenizer)) {
|
| 140 |
+
Files.copy(srcTokenizer, Paths.get("tokenizer.json"), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
| 141 |
+
System.out.println("[+] Reconstructed tokenizer.json copied to current directory.");
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
System.out.println("=========================================================");
|
| 145 |
+
System.out.println(" JAVA DECODER SUCCESSFUL!");
|
| 146 |
+
System.out.println("=========================================================");
|
| 147 |
+
}
|
| 148 |
+
}
|
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 Java
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# UFO Hyper-Compression & Self-Reconstruction Framework Kit (Java 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*
|
TestTokenizerCoder.java
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// Verification suite for JVM UFO Tokenizer Coder
|
| 3 |
+
|
| 4 |
+
import ufo.TokenizerCoder;
|
| 5 |
+
import java.nio.charset.StandardCharsets;
|
| 6 |
+
import java.util.ArrayList;
|
| 7 |
+
import java.util.Arrays;
|
| 8 |
+
import java.util.List;
|
| 9 |
+
|
| 10 |
+
public class TestTokenizerCoder {
|
| 11 |
+
public static void main(String[] args) {
|
| 12 |
+
System.out.println("=========================================================");
|
| 13 |
+
System.out.println(" RUNNING JAVA UFO TOKENIZER CODER VERIFICATION");
|
| 14 |
+
System.out.println(" Watermark: ip zymatica.space");
|
| 15 |
+
System.out.println("=========================================================");
|
| 16 |
+
|
| 17 |
+
// 1. Test Prefix-Suffix Vocab Compression & Decompression
|
| 18 |
+
System.out.println("\n[Test 1] Prefix-Suffix Vocab Coder...");
|
| 19 |
+
String[] originalVocabStrings = {
|
| 20 |
+
"hello",
|
| 21 |
+
"hell",
|
| 22 |
+
"heaven",
|
| 23 |
+
"heavy",
|
| 24 |
+
"world",
|
| 25 |
+
"word",
|
| 26 |
+
"work",
|
| 27 |
+
"worker",
|
| 28 |
+
"working"
|
| 29 |
+
};
|
| 30 |
+
List<byte[]> originalVocab = new ArrayList<>();
|
| 31 |
+
for (String s : originalVocabStrings) {
|
| 32 |
+
originalVocab.add(s.getBytes(StandardCharsets.UTF_8));
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
byte[] compressedVocab = TokenizerCoder.compressVocab(originalVocab);
|
| 36 |
+
System.out.println(" Original vocab items: " + originalVocab.size());
|
| 37 |
+
System.out.println(" Compressed vocab size: " + compressedVocab.length + " bytes");
|
| 38 |
+
|
| 39 |
+
List<byte[]> restoredVocab = TokenizerCoder.decompressVocab(compressedVocab, originalVocab.size());
|
| 40 |
+
System.out.println(" Restored vocab items: " + restoredVocab.size());
|
| 41 |
+
|
| 42 |
+
if (originalVocab.size() != restoredVocab.size()) {
|
| 43 |
+
throw new RuntimeException("Mismatch in vocab count!");
|
| 44 |
+
}
|
| 45 |
+
for (int i = 0; i < originalVocab.size(); i++) {
|
| 46 |
+
if (!Arrays.equals(originalVocab.get(i), restoredVocab.get(i))) {
|
| 47 |
+
throw new RuntimeException("Mismatch in vocab content at index " + i + "!");
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
System.out.println(" [+] Vocab round-trip: SUCCESS (100% Match)");
|
| 51 |
+
|
| 52 |
+
// 2. Test BPE Merges index pack/unpack
|
| 53 |
+
System.out.println("\n[Test 2] BPE Merges Binary Index Coder...");
|
| 54 |
+
List<int[]> originalMerges = new ArrayList<>();
|
| 55 |
+
originalMerges.add(new int[]{1015, 2030});
|
| 56 |
+
originalMerges.add(new int[]{45, 12});
|
| 57 |
+
originalMerges.add(new int[]{16777215, 50000});
|
| 58 |
+
originalMerges.add(new int[]{0, 1});
|
| 59 |
+
originalMerges.add(new int[]{100000, 200000});
|
| 60 |
+
|
| 61 |
+
byte[] compressedMerges = TokenizerCoder.compressMerges(originalMerges);
|
| 62 |
+
System.out.println(" Original merges items: " + originalMerges.size());
|
| 63 |
+
System.out.println(" Compressed merges size: " + compressedMerges.length + " bytes");
|
| 64 |
+
|
| 65 |
+
List<int[]> restoredMerges = TokenizerCoder.decompressMerges(compressedMerges);
|
| 66 |
+
System.out.println(" Restored merges items: " + restoredMerges.size());
|
| 67 |
+
|
| 68 |
+
if (originalMerges.size() != restoredMerges.size()) {
|
| 69 |
+
throw new RuntimeException("Mismatch in merges count!");
|
| 70 |
+
}
|
| 71 |
+
for (int i = 0; i < originalMerges.size(); i++) {
|
| 72 |
+
if (originalMerges.get(i)[0] != restoredMerges.get(i)[0] ||
|
| 73 |
+
originalMerges.get(i)[1] != restoredMerges.get(i)[1]) {
|
| 74 |
+
throw new RuntimeException("Mismatch in merges content at index " + i + "!");
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
System.out.println(" [+] Merges round-trip: SUCCESS (100% Match)");
|
| 78 |
+
|
| 79 |
+
// 3. Test XOR-FEC Parity
|
| 80 |
+
System.out.println("\n[Test 3] XOR-FEC Parity Calculation...");
|
| 81 |
+
byte[] c1 = {(byte)0xAA, (byte)0xBB, (byte)0xCC, (byte)0xDD};
|
| 82 |
+
byte[] c2 = {(byte)0x11, (byte)0x22, (byte)0x33, (byte)0x44};
|
| 83 |
+
byte[] c3 = {(byte)0x55, (byte)0x66, (byte)0x77, (byte)0x88};
|
| 84 |
+
List<byte[]> chunks = new ArrayList<>();
|
| 85 |
+
chunks.add(c1);
|
| 86 |
+
chunks.add(c2);
|
| 87 |
+
chunks.add(c3);
|
| 88 |
+
|
| 89 |
+
byte[] parity = TokenizerCoder.computeXorFecParity(chunks, 4);
|
| 90 |
+
byte[] expectedParity = {
|
| 91 |
+
(byte)(0xAA ^ 0x11 ^ 0x55),
|
| 92 |
+
(byte)(0xBB ^ 0x22 ^ 0x66),
|
| 93 |
+
(byte)(0xCC ^ 0x33 ^ 0x77),
|
| 94 |
+
(byte)(0xDD ^ 0x44 ^ 0x88)
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
if (!Arrays.equals(parity, expectedParity)) {
|
| 98 |
+
throw new RuntimeException("Mismatch in XOR-FEC parity!");
|
| 99 |
+
}
|
| 100 |
+
System.out.println(" [+] XOR-FEC computation: SUCCESS");
|
| 101 |
+
|
| 102 |
+
System.out.println("\n=========================================================");
|
| 103 |
+
System.out.println(" ALL JAVA TESTS PASSED SUCCESSFULLY!");
|
| 104 |
+
System.out.println("=========================================================");
|
| 105 |
+
}
|
| 106 |
+
}
|
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_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 |
+
}
|
ufo/TokenizerCoder.java
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Watermark: ip zymatica.space
|
| 2 |
+
// Patent Pending — USPTO Provisional Application | Zymatica Project
|
| 3 |
+
|
| 4 |
+
package ufo;
|
| 5 |
+
|
| 6 |
+
import java.io.ByteArrayOutputStream;
|
| 7 |
+
import java.util.ArrayList;
|
| 8 |
+
import java.util.List;
|
| 9 |
+
|
| 10 |
+
public class TokenizerCoder {
|
| 11 |
+
|
| 12 |
+
public static byte[] writeVarint(int val) {
|
| 13 |
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| 14 |
+
int v = val;
|
| 15 |
+
while (v >= 128) {
|
| 16 |
+
bos.write((v & 0x7F) | 0x80);
|
| 17 |
+
v >>>= 7;
|
| 18 |
+
}
|
| 19 |
+
bos.write(v & 0x7F);
|
| 20 |
+
return bos.toByteArray();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public static int readVarint(byte[] data, int[] state) {
|
| 24 |
+
int val = 0;
|
| 25 |
+
int shift = 0;
|
| 26 |
+
while (true) {
|
| 27 |
+
if (state[0] >= data.length) {
|
| 28 |
+
break;
|
| 29 |
+
}
|
| 30 |
+
byte b = data[state[0]];
|
| 31 |
+
state[0]++;
|
| 32 |
+
val |= (b & 0x7F) << shift;
|
| 33 |
+
if ((b & 0x80) == 0) {
|
| 34 |
+
break;
|
| 35 |
+
}
|
| 36 |
+
shift += 7;
|
| 37 |
+
}
|
| 38 |
+
return val;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Level 4 Prefix-Suffix Vocabulary String Compression
|
| 43 |
+
*/
|
| 44 |
+
public static byte[] compressVocab(List<byte[]> tokens) {
|
| 45 |
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| 46 |
+
byte[] prev = new byte[0];
|
| 47 |
+
for (byte[] t : tokens) {
|
| 48 |
+
int common = 0;
|
| 49 |
+
int l = Math.min(t.length, prev.length);
|
| 50 |
+
while (common < l && t[common] == prev[common]) {
|
| 51 |
+
common++;
|
| 52 |
+
}
|
| 53 |
+
int suffixLen = t.length - common;
|
| 54 |
+
byte[] suffix = new byte[suffixLen];
|
| 55 |
+
System.arraycopy(t, common, suffix, 0, suffixLen);
|
| 56 |
+
|
| 57 |
+
try {
|
| 58 |
+
bos.write(writeVarint(common));
|
| 59 |
+
bos.write(writeVarint(suffixLen));
|
| 60 |
+
bos.write(suffix);
|
| 61 |
+
} catch (Exception e) {
|
| 62 |
+
// Ignore
|
| 63 |
+
}
|
| 64 |
+
prev = t;
|
| 65 |
+
}
|
| 66 |
+
return bos.toByteArray();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Level 4 Prefix-Suffix Vocabulary String Restoration
|
| 71 |
+
*/
|
| 72 |
+
public static List<byte[]> decompressVocab(byte[] data, int numTokens) {
|
| 73 |
+
List<byte[]> tokens = new ArrayList<>(numTokens);
|
| 74 |
+
int[] state = new int[]{0};
|
| 75 |
+
byte[] prev = new byte[0];
|
| 76 |
+
for (int i = 0; i < numTokens; i++) {
|
| 77 |
+
if (state[0] >= data.length) {
|
| 78 |
+
break;
|
| 79 |
+
}
|
| 80 |
+
int common = readVarint(data, state);
|
| 81 |
+
int suffixLen = readVarint(data, state);
|
| 82 |
+
if (state[0] + suffixLen > data.length) {
|
| 83 |
+
break;
|
| 84 |
+
}
|
| 85 |
+
byte[] suffix = new byte[suffixLen];
|
| 86 |
+
System.arraycopy(data, state[0], suffix, 0, suffixLen);
|
| 87 |
+
state[0] += suffixLen;
|
| 88 |
+
|
| 89 |
+
byte[] t = new byte[common + suffixLen];
|
| 90 |
+
System.arraycopy(prev, 0, t, 0, Math.min(common, prev.length));
|
| 91 |
+
System.arraycopy(suffix, 0, t, common, suffixLen);
|
| 92 |
+
tokens.add(t);
|
| 93 |
+
prev = t;
|
| 94 |
+
}
|
| 95 |
+
return tokens;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Level 3 BPE Merges Binary Index-Packing (24-bit integer pairs)
|
| 100 |
+
*/
|
| 101 |
+
public static byte[] compressMerges(List<int[]> merges) {
|
| 102 |
+
byte[] encoded = new byte[merges.size() * 6];
|
| 103 |
+
int offset = 0;
|
| 104 |
+
for (int[] pair : merges) {
|
| 105 |
+
int idx0 = pair[0];
|
| 106 |
+
int int1 = pair[1];
|
| 107 |
+
|
| 108 |
+
encoded[offset] = (byte)((idx0 >> 16) & 0xFF);
|
| 109 |
+
encoded[offset + 1] = (byte)((idx0 >> 8) & 0xFF);
|
| 110 |
+
encoded[offset + 2] = (byte)(idx0 & 0xFF);
|
| 111 |
+
|
| 112 |
+
encoded[offset + 3] = (byte)((int1 >> 16) & 0xFF);
|
| 113 |
+
encoded[offset + 4] = (byte)((int1 >> 8) & 0xFF);
|
| 114 |
+
encoded[offset + 5] = (byte)(int1 & 0xFF);
|
| 115 |
+
offset += 6;
|
| 116 |
+
}
|
| 117 |
+
return encoded;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Level 3 BPE Merges Binary Index-Unpacking (24-bit integer pairs)
|
| 122 |
+
*/
|
| 123 |
+
public static List<int[]> decompressMerges(byte[] data) {
|
| 124 |
+
int numMerges = data.length / 6;
|
| 125 |
+
List<int[]> merges = new ArrayList<>(numMerges);
|
| 126 |
+
for (int i = 0; i < numMerges; i++) {
|
| 127 |
+
int offset = i * 6;
|
| 128 |
+
int idx0 = ((data[offset] & 0xFF) << 16) |
|
| 129 |
+
((data[offset + 1] & 0xFF) << 8) |
|
| 130 |
+
(data[offset + 2] & 0xFF);
|
| 131 |
+
|
| 132 |
+
int idx1 = ((data[offset + 3] & 0xFF) << 16) |
|
| 133 |
+
((data[offset + 4] & 0xFF) << 8) |
|
| 134 |
+
(data[offset + 5] & 0xFF);
|
| 135 |
+
merges.add(new int[]{idx0, idx1});
|
| 136 |
+
}
|
| 137 |
+
return merges;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Level 7 XOR-FEC Parity computation for error resilient transmission
|
| 142 |
+
*/
|
| 143 |
+
public static byte[] computeXorFecParity(List<byte[]> chunks, int chunkSize) {
|
| 144 |
+
byte[] parity = new byte[chunkSize];
|
| 145 |
+
for (byte[] chunk : chunks) {
|
| 146 |
+
int limit = Math.min(chunk.length, chunkSize);
|
| 147 |
+
for (int j = 0; j < limit; j++) {
|
| 148 |
+
parity[j] ^= chunk[j];
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
return parity;
|
| 152 |
+
}
|
| 153 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|