File size: 1,112 Bytes
4f7460f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()