1 Star 1 Fork 0

ZheGuangLi/sd-webui-controlnet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
extract_controlnet.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
RcINS 提交于 2023-04-13 17:50 . Extraction add half option
import argparse
import torch
from safetensors.torch import load_file, save_file
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--src", default=None, type=str, required=True, help="Path to the model to convert.")
parser.add_argument("--dst", default=None, type=str, required=True, help="Path to the output model.")
parser.add_argument("--half", action="store_true", help="Cast to FP16.")
args = parser.parse_args()
assert args.src is not None, "Must provide a model path!"
assert args.dst is not None, "Must provide a checkpoint path!"
if args.src.endswith(".safetensors"):
state_dict = load_file(args.src)
else:
state_dict = torch.load(args.src)
if any([k.startswith("control_model.") for k, v in state_dict.items()]):
dtype = torch.float16 if args.half else torch.float32
state_dict = {k.replace("control_model.", ""): v.to(dtype) for k, v in state_dict.items() if k.startswith("control_model.")}
if args.dst.endswith(".safetensors"):
save_file(state_dict, args.dst)
else:
torch.save({"state_dict": state_dict}, args.dst)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhaiguang/sd-webui-controlnet.git
[email protected]:zhaiguang/sd-webui-controlnet.git
zhaiguang
sd-webui-controlnet
sd-webui-controlnet
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385