update get_parameter_dtype by yiyixuxu · Pull Request #9526 · huggingface/diffusers (original) (raw)

small optimization on dtype method for our ModelMixin
see context in this PR #9520 (comment)

main: Getting unet.dtype took 0.004666426 seconds
PR branch: Getting unet.dtype took 0.000084107 seconds

from diffusers import UNetMotionModel, UNet2DConditionModel, MotionAdapter import torch

dtype = torch.float32

adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=dtype)

load SD 1.5 based finetuned model

model_id = "SG161222/Realistic_Vision_V5.1_noVAE" unet = UNet2DConditionModel.from_pretrained(model_id, subfolder="unet", torch_dtype=dtype)

wrap model with motion adapter

unet = UNetMotionModel.from_unet2d(unet, adapter) unet.to("cuda")

import time from contextlib import contextmanager

@contextmanager def timer(name): start_time = time.perf_counter() yield end_time = time.perf_counter() print(f"{name} took {end_time - start_time:.9f} seconds")

with timer("Getting unet.dtype"): print(unet.dtype)