Extraction add half option
parent
b1c0bc62e0
commit
2cca805b2a
|
|
@ -6,6 +6,7 @@ if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--src", default=None, type=str, required=True, help="Path to the model to convert.")
|
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("--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
assert args.src is not None, "Must provide a model path!"
|
assert args.src is not None, "Must provide a model path!"
|
||||||
|
|
@ -15,9 +16,10 @@ if __name__ == "__main__":
|
||||||
state_dict = load_file(args.src)
|
state_dict = load_file(args.src)
|
||||||
else:
|
else:
|
||||||
state_dict = torch.load(args.src)
|
state_dict = torch.load(args.src)
|
||||||
|
|
||||||
if any([k.startswith("control_model.") for k, v in state_dict.items()]):
|
if any([k.startswith("control_model.") for k, v in state_dict.items()]):
|
||||||
state_dict = {k.replace("control_model.", ""): v for k, v in state_dict.items() if k.startswith("control_model.")}
|
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"):
|
if args.dst.endswith(".safetensors"):
|
||||||
save_file(state_dict, args.dst)
|
save_file(state_dict, args.dst)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue