qwenjev / scripts /xet_experiment.py
tchbcb's picture
v0.4.8: safetensors-loss fix + HEAD verification + v0.4.7 OOM-gate sync
cac4e09 verified
Raw History Blame Contribute Delete
1.97 kB
# Remote experiment (run on T4): does HF_HUB_DISABLE_XET=1 fix silent
# .safetensors loss? Linear code only (envelope pitfall #7).
import os, json, struct, time, urllib.request
tok = open("/content/qwenjev_work_v3/.hf_token").read().strip()
REPO = "tchbcb/qwenjev"
# build a tiny valid safetensors (F32 2x2) without torch
header = {"w": {"dtype": "F32", "shape": [2, 2], "data_offsets": [0, 16]}}
hjson = json.dumps(header).encode()
hjson += b" " * ((8 - len(hjson) % 8) % 8)
buf = struct.pack("<Q", len(hjson)) + hjson + b"\x00" * 16
open("/tmp/xet_test.safetensors", "wb").write(buf)
print("test file:", len(buf), "bytes", flush=True)
def head(p):
url = "https://huggingface.co/" + REPO + "/resolve/main/" + p
try:
r = urllib.request.urlopen(urllib.request.Request(url, method="HEAD"), timeout=30)
return "OK len=" + str(r.headers.get("Content-Length"))
except Exception as e:
return "FAIL " + str(e)[:50]
from huggingface_hub import HfApi
import huggingface_hub
print("hf_hub version:", huggingface_hub.__version__, flush=True)
# A: default backend (xet)
pA = "t4_assets_v3/_xet_test/default.safetensors"
try:
HfApi(token=tok).upload_file(
path_or_fileobj="/tmp/xet_test.safetensors", path_in_repo=pA,
repo_id=REPO, repo_type="model", commit_message="xet test A default")
time.sleep(2)
print("A default-backend :", head(pA), flush=True)
except Exception as e:
print("A upload error:", str(e)[:120], flush=True)
# B: xet disabled
os.environ["HF_HUB_DISABLE_XET"] = "1"
pB = "t4_assets_v3/_xet_test/noxet.safetensors"
try:
HfApi(token=tok).upload_file(
path_or_fileobj="/tmp/xet_test.safetensors", path_in_repo=pB,
repo_id=REPO, repo_type="model", commit_message="xet test B no-xet")
time.sleep(2)
print("B no-xet-backend :", head(pB), flush=True)
except Exception as e:
print("B upload error:", str(e)[:120], flush=True)
print("EXPERIMENT_DONE", flush=True)