"docs/git@developer.sourcefind.cn:OpenDAS/torchaudio.git" did not exist on "8125372bbdf2c35a6ac7361b6343d9a3d175ca1c"
Unverified Commit 9062b284 authored by Alon Burg's avatar Alon Burg Committed by GitHub
Browse files

Support fp16 in conversion from original ckpt (#2733)

add --half to convert_original_stable_diffusion_to_diffusers.py
parent b3d5cc4a
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# limitations under the License. # limitations under the License.
""" Conversion script for the LDM checkpoints. """ """ Conversion script for the LDM checkpoints. """
import torch
import argparse import argparse
from diffusers.pipelines.stable_diffusion.convert_from_ckpt import download_from_original_stable_diffusion_ckpt from diffusers.pipelines.stable_diffusion.convert_from_ckpt import download_from_original_stable_diffusion_ckpt
...@@ -123,6 +124,7 @@ if __name__ == "__main__": ...@@ -123,6 +124,7 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"--controlnet", action="store_true", default=None, help="Set flag if this is a controlnet checkpoint." "--controlnet", action="store_true", default=None, help="Set flag if this is a controlnet checkpoint."
) )
parser.add_argument("--half", action="store_true", help="Save weights in half precision.")
args = parser.parse_args() args = parser.parse_args()
pipe = download_from_original_stable_diffusion_ckpt( pipe = download_from_original_stable_diffusion_ckpt(
...@@ -143,6 +145,9 @@ if __name__ == "__main__": ...@@ -143,6 +145,9 @@ if __name__ == "__main__":
controlnet=args.controlnet, controlnet=args.controlnet,
) )
if args.half:
pipe.to(torch_dtype=torch.float16)
if args.controlnet: if args.controlnet:
# only save the controlnet model # only save the controlnet model
pipe.controlnet.save_pretrained(args.dump_path, safe_serialization=args.to_safetensors) pipe.controlnet.save_pretrained(args.dump_path, safe_serialization=args.to_safetensors)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment