scrub-v7-src / pod_scripts /patch_supir.sh
lucaszhouch's picture
archive all pod-side scripts (final state incl blur/lumafix/nointerp chains)
bf21930
Raw History Blame Contribute Delete
2.14 kB
#!/bin/bash
# SUPIR 落地补丁 (全新 Pod 复刻必跑): 权重路径 + llava import 守卫 + 缺失依赖
pip install -q scipy k-diffusion sentencepiece timm openai-clip einops-exts diffusers open_clip_torch==2.24.0
cd /workspace/SUPIR
sed -i "s|SDXL_CLIP1_PATH = .*|SDXL_CLIP1_PATH = '/workspace/ckpts/clip-vit-large-patch14'|; s|SDXL_CLIP2_CKPT_PTH = .*|SDXL_CLIP2_CKPT_PTH = '/workspace/ckpts/CLIP-ViT-bigG-14/open_clip_pytorch_model.bin'|" CKPT_PTH.py
sed -i 's|SDXL_CKPT: .*|SDXL_CKPT: /workspace/ckpts/sd_xl_base_1.0_0.9vae.safetensors|; s|SUPIR_CKPT_Q: .*|SUPIR_CKPT_Q: /workspace/ckpts/SUPIR-v0Q.ckpt|' options/SUPIR_v0.yaml
python3 - <<'PYEOF'
src = open('test.py').read()
old = "from llava.llava_agent import LLavaAgent\nfrom CKPT_PTH import LLAVA_MODEL_PATH"
new = ("try:\n from llava.llava_agent import LLavaAgent\n from CKPT_PTH import LLAVA_MODEL_PATH\n"
"except Exception as _e:\n print('[patch] llava disabled:', _e)\n LLavaAgent = None\n LLAVA_MODEL_PATH = None")
if old in src:
open('test.py','w').write(src.replace(old, new))
print('patch_supir done')
PYEOF
# 上游 bug: tilevae.py 364 行 is_xformers_available 少括号永真, 无 xformers 时炸 NameError
sed -i 's|if is_xformers_available:|if is_xformers_available():|' /workspace/SUPIR/SUPIR/utils/tilevae.py
# 上游 bug 2: 无 xformers 回落路径 attn_forward_new* 只认 diffusers 块 (group_norm), sgm 块需走 attn_forward
python3 - <<'PYEOF2'
p = '/workspace/SUPIR/SUPIR/utils/tilevae.py'
src = open(p).read()
old1 = "task_queue.append(('attn', lambda x, net=net: attn_forward_new_pt2_0(net, x)))"
new1 = "task_queue.append(('attn', lambda x, net=net: (attn_forward_new_pt2_0(net, x) if hasattr(net, 'group_norm') else attn_forward(net, x))))"
old2 = "task_queue.append(('attn', lambda x, net=net: attn_forward_new(net, x)))"
new2 = "task_queue.append(('attn', lambda x, net=net: (attn_forward_new(net, x) if hasattr(net, 'group_norm') else attn_forward(net, x))))"
if old1 in src: src = src.replace(old1, new1)
if old2 in src: src = src.replace(old2, new2)
open(p,'w').write(src)
print('tilevae dispatch patched')
PYEOF2