v0.4.8: safetensors-loss fix + HEAD verification + v0.4.7 OOM-gate sync
Browse files- scripts/xet_experiment.py +53 -0
scripts/xet_experiment.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Remote experiment (run on T4): does HF_HUB_DISABLE_XET=1 fix silent
|
| 2 |
+
# .safetensors loss? Linear code only (envelope pitfall #7).
|
| 3 |
+
import os, json, struct, time, urllib.request
|
| 4 |
+
|
| 5 |
+
tok = open("/content/qwenjev_work_v3/.hf_token").read().strip()
|
| 6 |
+
REPO = "tchbcb/qwenjev"
|
| 7 |
+
|
| 8 |
+
# build a tiny valid safetensors (F32 2x2) without torch
|
| 9 |
+
header = {"w": {"dtype": "F32", "shape": [2, 2], "data_offsets": [0, 16]}}
|
| 10 |
+
hjson = json.dumps(header).encode()
|
| 11 |
+
hjson += b" " * ((8 - len(hjson) % 8) % 8)
|
| 12 |
+
buf = struct.pack("<Q", len(hjson)) + hjson + b"\x00" * 16
|
| 13 |
+
open("/tmp/xet_test.safetensors", "wb").write(buf)
|
| 14 |
+
print("test file:", len(buf), "bytes", flush=True)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def head(p):
|
| 18 |
+
url = "https://huggingface.co/" + REPO + "/resolve/main/" + p
|
| 19 |
+
try:
|
| 20 |
+
r = urllib.request.urlopen(urllib.request.Request(url, method="HEAD"), timeout=30)
|
| 21 |
+
return "OK len=" + str(r.headers.get("Content-Length"))
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return "FAIL " + str(e)[:50]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
from huggingface_hub import HfApi
|
| 27 |
+
import huggingface_hub
|
| 28 |
+
print("hf_hub version:", huggingface_hub.__version__, flush=True)
|
| 29 |
+
|
| 30 |
+
# A: default backend (xet)
|
| 31 |
+
pA = "t4_assets_v3/_xet_test/default.safetensors"
|
| 32 |
+
try:
|
| 33 |
+
HfApi(token=tok).upload_file(
|
| 34 |
+
path_or_fileobj="/tmp/xet_test.safetensors", path_in_repo=pA,
|
| 35 |
+
repo_id=REPO, repo_type="model", commit_message="xet test A default")
|
| 36 |
+
time.sleep(2)
|
| 37 |
+
print("A default-backend :", head(pA), flush=True)
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print("A upload error:", str(e)[:120], flush=True)
|
| 40 |
+
|
| 41 |
+
# B: xet disabled
|
| 42 |
+
os.environ["HF_HUB_DISABLE_XET"] = "1"
|
| 43 |
+
pB = "t4_assets_v3/_xet_test/noxet.safetensors"
|
| 44 |
+
try:
|
| 45 |
+
HfApi(token=tok).upload_file(
|
| 46 |
+
path_or_fileobj="/tmp/xet_test.safetensors", path_in_repo=pB,
|
| 47 |
+
repo_id=REPO, repo_type="model", commit_message="xet test B no-xet")
|
| 48 |
+
time.sleep(2)
|
| 49 |
+
print("B no-xet-backend :", head(pB), flush=True)
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print("B upload error:", str(e)[:120], flush=True)
|
| 52 |
+
|
| 53 |
+
print("EXPERIMENT_DONE", flush=True)
|