v41: US-NC-2 share host (code + shards + native Engram over HTTP)
Browse files- worker/share-host.sh +112 -0
worker/share-host.sh
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# US-NC-2 share host: assemble everything a GPU pod needs into one directory and serve it over
|
| 3 |
+
# HTTP, so no pod ever depends on Hugging Face (which rate-limits this account) or on a volume it
|
| 4 |
+
# cannot mount (Runpod volumes are datacenter-local).
|
| 5 |
+
#
|
| 6 |
+
# Serves: the worker bundle, the five published GGUF shards, and the native Engram tensors
|
| 7 |
+
# extracted from the archived source checkpoint. Random path segment + optional basic auth token
|
| 8 |
+
# keep the checkpoint from being openly enumerable.
|
| 9 |
+
set -uo pipefail
|
| 10 |
+
trap 'echo "share host aborted rc=$? at line $LINENO"' ERR
|
| 11 |
+
STAMP=$(date -u +%Y%m%dT%H%M%SZ); WORK=${WORK:-/workspace/v41-quant}
|
| 12 |
+
SOURCE_DIR=${SOURCE_DIR:-/workspace/v41-download/models/DeepSeek-V4.1-Flash/2bc89ac599031fa673cab993f1df02fc4a98c673}
|
| 13 |
+
TOKEN_PATH=${TOKEN_PATH:-$(openssl rand -hex 12 2>/dev/null || date +%s%N | sha256sum | cut -c1-16)}
|
| 14 |
+
SHARE=${SHARE:-/workspace/v41-share/$TOKEN_PATH}
|
| 15 |
+
PORT=${PORT:-8000}
|
| 16 |
+
mkdir -p "$WORK/logs" "$SHARE"; exec > >(tee -a "$WORK/logs/share-$STAMP.log") 2>&1
|
| 17 |
+
echo "=== share host $STAMP"
|
| 18 |
+
echo "share dir: $SHARE path token: $TOKEN_PATH"
|
| 19 |
+
export DEBIAN_FRONTEND=noninteractive
|
| 20 |
+
apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates python3-pip >/tmp/apt.log 2>&1
|
| 21 |
+
|
| 22 |
+
echo "--- code bundle"
|
| 23 |
+
tar czf "$SHARE/v41-runtimes.tgz" -C "$WORK" scripts runtimes
|
| 24 |
+
ls -la "$SHARE/v41-runtimes.tgz"
|
| 25 |
+
|
| 26 |
+
echo "--- GGUF shards from the archived pack"
|
| 27 |
+
mkdir -p "$SHARE/gguf"
|
| 28 |
+
for src in "$WORK"/gguf-publish/*.gguf "$WORK"/gguf-mixedq2/*.gguf; do
|
| 29 |
+
[ -f "$src" ] || continue
|
| 30 |
+
ln -sf "$src" "$SHARE/gguf/$(basename "$src")" 2>/dev/null || cp -f "$src" "$SHARE/gguf/"
|
| 31 |
+
done
|
| 32 |
+
( cd "$WORK/gguf-publish" 2>/dev/null && sha256sum ./*.gguf ) > "$SHARE/gguf/SHA256SUMS" 2>/dev/null || true
|
| 33 |
+
ls -la "$SHARE/gguf" | head -8
|
| 34 |
+
|
| 35 |
+
echo "--- Engram extraction from the archived source checkpoint"
|
| 36 |
+
python3 - "$SOURCE_DIR" "$SHARE" <<'PYEOF'
|
| 37 |
+
import hashlib, json, os, sys, time
|
| 38 |
+
src_dir, share = sys.argv[1:3]
|
| 39 |
+
index = json.load(open(os.path.join(src_dir, "model.safetensors.index.json")))
|
| 40 |
+
weight_map = index["weight_map"]
|
| 41 |
+
targets = sorted(n for n in weight_map if ".engram." in n)
|
| 42 |
+
print(f"engram tensors: {len(targets)}", flush=True)
|
| 43 |
+
headers = {}
|
| 44 |
+
def header_of(shard):
|
| 45 |
+
if shard not in headers:
|
| 46 |
+
with open(os.path.join(src_dir, shard), "rb") as fh:
|
| 47 |
+
length = int.from_bytes(fh.read(8), "little")
|
| 48 |
+
hdr = json.loads(fh.read(length)); hdr.pop("__metadata__", None)
|
| 49 |
+
headers[shard] = (hdr, 8 + length)
|
| 50 |
+
return headers[shard]
|
| 51 |
+
|
| 52 |
+
entries, blobs, started = {}, {}, time.time()
|
| 53 |
+
for name in targets:
|
| 54 |
+
shard = weight_map[name]
|
| 55 |
+
hdr, data_start = header_of(shard)
|
| 56 |
+
begin, end = hdr[name]["data_offsets"]
|
| 57 |
+
size = end - begin
|
| 58 |
+
t0 = time.time()
|
| 59 |
+
with open(os.path.join(src_dir, shard), "rb") as fh:
|
| 60 |
+
fh.seek(data_start + begin)
|
| 61 |
+
blob = fh.read(size)
|
| 62 |
+
if len(blob) != size:
|
| 63 |
+
raise RuntimeError(f"{name}: short read")
|
| 64 |
+
blobs[name] = blob
|
| 65 |
+
entries[name] = {"source_shard": shard, "dtype": hdr[name]["dtype"], "shape": hdr[name]["shape"],
|
| 66 |
+
"data_offsets": [begin, end], "bytes": size,
|
| 67 |
+
"sha256": hashlib.sha256(blob).hexdigest(), "seconds": round(time.time() - t0, 1)}
|
| 68 |
+
print(f" {name}: {size/1e9:.2f} GB sha256={entries[name]['sha256'][:16]}…", flush=True)
|
| 69 |
+
|
| 70 |
+
offset = 0
|
| 71 |
+
header_entries = {}
|
| 72 |
+
for name in targets:
|
| 73 |
+
header_entries[name] = {"dtype": entries[name]["dtype"], "shape": entries[name]["shape"],
|
| 74 |
+
"data_offsets": [offset, offset + len(blobs[name])]}
|
| 75 |
+
offset += len(blobs[name])
|
| 76 |
+
payload = json.dumps(header_entries, separators=(",", ":")).encode()
|
| 77 |
+
pad = (-(8 + len(payload))) % 8
|
| 78 |
+
path = os.path.join(share, "engram-native.safetensors")
|
| 79 |
+
with open(path, "wb") as fh:
|
| 80 |
+
fh.write(len(payload + b" " * pad).to_bytes(8, "little") + payload + b" " * pad)
|
| 81 |
+
for name in targets:
|
| 82 |
+
fh.write(blobs[name])
|
| 83 |
+
manifest = {"source_dir": src_dir, "file": os.path.basename(path), "bytes": os.path.getsize(path),
|
| 84 |
+
"tensors": entries, "seconds": round(time.time() - started, 1)}
|
| 85 |
+
json.dump(manifest, open(os.path.join(share, "engram-manifest.json"), "w"), indent=1)
|
| 86 |
+
with open(os.path.join(share, "engram-SHA256SUMS"), "w") as fh:
|
| 87 |
+
fh.write(f"{hashlib.sha256(open(path,'rb').read()).hexdigest()} {os.path.basename(path)}\n")
|
| 88 |
+
print(json.dumps({"engram_bytes": manifest["bytes"], "seconds": manifest["seconds"]}, indent=1))
|
| 89 |
+
PYEOF
|
| 90 |
+
|
| 91 |
+
echo "--- share manifest"
|
| 92 |
+
python3 - "$SHARE" "$TOKEN_PATH" "$PORT" <<'PYEOF'
|
| 93 |
+
import hashlib, json, os, sys
|
| 94 |
+
share, token, port = sys.argv[1:4]
|
| 95 |
+
files = []
|
| 96 |
+
for root, _, names in os.walk(share):
|
| 97 |
+
for name in sorted(names):
|
| 98 |
+
path = os.path.join(root, name)
|
| 99 |
+
rel = os.path.relpath(path, share)
|
| 100 |
+
if os.path.islink(path):
|
| 101 |
+
continue
|
| 102 |
+
files.append({"path": rel, "bytes": os.path.getsize(path)})
|
| 103 |
+
record = {"share": share, "path_token": token, "port": port, "files": files,
|
| 104 |
+
"bytes": sum(f["bytes"] for f in files)}
|
| 105 |
+
json.dump(record, open(os.path.join(share, "manifest.json"), "w"), indent=1)
|
| 106 |
+
print(json.dumps({k: v for k, v in record.items() if k != "files"}, indent=1))
|
| 107 |
+
for f in files:
|
| 108 |
+
print(f" {f['path']:52s} {f['bytes']/1e9:7.2f} GB")
|
| 109 |
+
PYEOF
|
| 110 |
+
|
| 111 |
+
echo "=== serving on port $PORT (path token $TOKEN_PATH)"
|
| 112 |
+
exec python3 -m http.server "$PORT" --directory "$SHARE"
|