Skip to content

update get_parameter_dtype #9526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged

update get_parameter_dtype #9526

merged 2 commits into from
Sep 25, 2024

Conversation

yiyixuxu
Copy link
Collaborator

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)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization! LGTM!

@xiang9156
Copy link

Thank you guys for lightning action!

@yiyixuxu yiyixuxu merged commit c76e884 into main Sep 25, 2024
18 checks passed
@yiyixuxu yiyixuxu deleted the test-dtype branch September 25, 2024 21:01
leisuzz pushed a commit to leisuzz/diffusers that referenced this pull request Oct 11, 2024
* up

* Update src/diffusers/models/modeling_utils.py

Co-authored-by: Aryan <[email protected]>

---------

Co-authored-by: Aryan <[email protected]>
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* up

* Update src/diffusers/models/modeling_utils.py

Co-authored-by: Aryan <[email protected]>

---------

Co-authored-by: Aryan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants