File size: 1,970 Bytes
cac4e09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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)