samai-8b-M8 / artifacts /r13_scripts /patch_skip_single.py
tchbcb's picture
r13: skip single-cand tensors in s3 (OOM fix)
4f7460f verified
Raw History Blame Contribute Delete
1.11 kB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""patch_skip_single.py — S3 单候选张量跳过: token_embd/output 等固定 q8_0 档不进 GPU 误差计算
(151936x4096 级张量 W fp32=2.5G + 中间量 → OOM 根因; E_tab 仅报告用, DP 只搜多候选张量)"""
SK_OLD = ''' cands = ["q8_0"]
W = torch.from_numpy(np.ascontiguousarray(t.data)).to(dev).float()'''
SK_NEW = ''' cands = ["q8_0"]
if len(cands) == 1:
n1 = int(np.prod(shape))
E_tab[base] = {c: 0.0 for c in cands}
sizes_tab[base] = {c: block_bytes(n1, c) for c in ["q4_0", "q5_0", "q6_k", "q8_0"]}
table[base] = cands
continue
W = torch.from_numpy(np.ascontiguousarray(t.data)).to(dev).float()'''
def main():
path = "/tmp/k8b/r13_chain.py"
src = open(path).read()
cnt = src.count(SK_OLD)
assert cnt == 1, "anchor not unique: count=%d" % cnt
src = src.replace(SK_OLD, SK_NEW, 1)
compile(src, path, "exec")
open(path, "w").write(src)
print("PATCHED", path)
print("PATCH_OK single-cand skip")
main()