Use lossless output-major WebGPU repacker
Browse files- scripts/repack_escha.py +33 -9
scripts/repack_escha.py
CHANGED
|
@@ -18,11 +18,12 @@ import tempfile
|
|
| 18 |
from collections import defaultdict
|
| 19 |
from pathlib import Path
|
| 20 |
|
|
|
|
| 21 |
from huggingface_hub import HfApi
|
| 22 |
|
| 23 |
|
| 24 |
SOURCE_REPO = "EschaLabs/Qwen3.8-27B-Escha-W2"
|
| 25 |
-
DEFAULT_DEST = "ProCreations/Qwen3.8-27B-Escha-W2-WebGPU"
|
| 26 |
ALIGNMENT = 256
|
| 27 |
ROWS_PER_HEAD_PART = 15_520 # 79,462,400 int8 bytes: portable WebGPU binding
|
| 28 |
|
|
@@ -103,9 +104,28 @@ def write_group(
|
|
| 103 |
target.write(padding)
|
| 104 |
digest.update(padding)
|
| 105 |
offset = padded
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
key = spec["name"]
|
| 110 |
names.append(key)
|
| 111 |
entry = {
|
|
@@ -119,6 +139,8 @@ def write_group(
|
|
| 119 |
if "row_start" in spec:
|
| 120 |
entry["row_start"] = spec["row_start"]
|
| 121 |
entry["row_end"] = spec["row_end"]
|
|
|
|
|
|
|
| 122 |
manifest["tensors"][key] = entry
|
| 123 |
offset += slice_bytes
|
| 124 |
total += slice_bytes
|
|
@@ -163,13 +185,14 @@ Lossless browser-streaming container for
|
|
| 163 |
[`EschaLabs/Qwen3.8-27B-Escha-W2`](https://huggingface.co/EschaLabs/Qwen3.8-27B-Escha-W2),
|
| 164 |
used by [`ProCreations/Qwen3.8-27b-W2`](https://huggingface.co/spaces/ProCreations/Qwen3.8-27b-W2).
|
| 165 |
|
| 166 |
-
The original Escha 2/3-bit codes
|
| 167 |
-
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
- Source revision: `{source_revision}`
|
| 171 |
- Tensor bytes: `{total_bytes / 1e9:.2f} GB`
|
| 172 |
-
- Format: `escha-webgpu-pack-
|
| 173 |
"""
|
| 174 |
(root / "README.md").write_text(card, encoding="utf-8")
|
| 175 |
|
|
@@ -222,7 +245,8 @@ def main() -> None:
|
|
| 222 |
root = Path(tmp) / "pack"
|
| 223 |
root.mkdir(parents=True)
|
| 224 |
manifest = {
|
| 225 |
-
"format": "escha-webgpu-pack-
|
|
|
|
| 226 |
"source": SOURCE_REPO,
|
| 227 |
"source_revision": revision,
|
| 228 |
"alignment": ALIGNMENT,
|
|
|
|
| 18 |
from collections import defaultdict
|
| 19 |
from pathlib import Path
|
| 20 |
|
| 21 |
+
import numpy as np
|
| 22 |
from huggingface_hub import HfApi
|
| 23 |
|
| 24 |
|
| 25 |
SOURCE_REPO = "EschaLabs/Qwen3.8-27B-Escha-W2"
|
| 26 |
+
DEFAULT_DEST = "ProCreations/Qwen3.8-27B-Escha-W2-WebGPU-v2"
|
| 27 |
ALIGNMENT = 256
|
| 28 |
ROWS_PER_HEAD_PART = 15_520 # 79,462,400 int8 bytes: portable WebGPU binding
|
| 29 |
|
|
|
|
| 104 |
target.write(padding)
|
| 105 |
digest.update(padding)
|
| 106 |
offset = padded
|
| 107 |
+
output_major = source_name.endswith(".escha_code")
|
| 108 |
+
if output_major:
|
| 109 |
+
if meta["dtype"] != "I16" or len(shape) != 3:
|
| 110 |
+
raise RuntimeError(f"Unexpected Escha code tensor {source_name}: {meta}")
|
| 111 |
+
source_view = np.memmap(
|
| 112 |
+
source_dir / filename,
|
| 113 |
+
dtype="<i2",
|
| 114 |
+
mode="r",
|
| 115 |
+
offset=data_start + start,
|
| 116 |
+
shape=tuple(shape),
|
| 117 |
+
)
|
| 118 |
+
transposed = np.ascontiguousarray(source_view.transpose(1, 0, 2))
|
| 119 |
+
payload = transposed.tobytes()
|
| 120 |
+
if len(payload) != slice_bytes:
|
| 121 |
+
raise RuntimeError(f"Transposed size mismatch for {source_name}")
|
| 122 |
+
target.write(payload)
|
| 123 |
+
digest.update(payload)
|
| 124 |
+
del transposed, source_view, payload
|
| 125 |
+
else:
|
| 126 |
+
with (source_dir / filename).open("rb") as source:
|
| 127 |
+
source.seek(data_start + start + slice_start)
|
| 128 |
+
copy_exact(source, target, slice_bytes, digest)
|
| 129 |
key = spec["name"]
|
| 130 |
names.append(key)
|
| 131 |
entry = {
|
|
|
|
| 139 |
if "row_start" in spec:
|
| 140 |
entry["row_start"] = spec["row_start"]
|
| 141 |
entry["row_end"] = spec["row_end"]
|
| 142 |
+
if output_major:
|
| 143 |
+
entry["layout"] = "output-major-blocks"
|
| 144 |
manifest["tensors"][key] = entry
|
| 145 |
offset += slice_bytes
|
| 146 |
total += slice_bytes
|
|
|
|
| 185 |
[`EschaLabs/Qwen3.8-27B-Escha-W2`](https://huggingface.co/EschaLabs/Qwen3.8-27B-Escha-W2),
|
| 186 |
used by [`ProCreations/Qwen3.8-27b-W2`](https://huggingface.co/spaces/ProCreations/Qwen3.8-27b-W2).
|
| 187 |
|
| 188 |
+
The original Escha 2/3-bit codes are losslessly transposed into output-major
|
| 189 |
+
block order for coalesced WebGPU reads. Hadamard signs, scales, biases, norms,
|
| 190 |
+
and int8 embedding/head values remain byte-for-byte identical. No additional
|
| 191 |
+
model quantization or approximation is applied.
|
| 192 |
|
| 193 |
- Source revision: `{source_revision}`
|
| 194 |
- Tensor bytes: `{total_bytes / 1e9:.2f} GB`
|
| 195 |
+
- Format: `escha-webgpu-pack-v2`
|
| 196 |
"""
|
| 197 |
(root / "README.md").write_text(card, encoding="utf-8")
|
| 198 |
|
|
|
|
| 245 |
root = Path(tmp) / "pack"
|
| 246 |
root.mkdir(parents=True)
|
| 247 |
manifest = {
|
| 248 |
+
"format": "escha-webgpu-pack-v2",
|
| 249 |
+
"code_layout": "output-major-blocks",
|
| 250 |
"source": SOURCE_REPO,
|
| 251 |
"source_revision": revision,
|
| 252 |
"alignment": ALIGNMENT,
|