Skip to content
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

feat: significantly optimize the time consumption of clip vision #2474

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

storyicon
Copy link
Contributor

@storyicon storyicon commented Jan 15, 2024

In the inference service using ControlNet, I observed a significant increase in time consumption when utilizing clip vision-related preprocessors (e.g. adapter_clip_sd15). The time fluctuates between 8s and 250s, depending on machine load. The typical time is around 10s. My machine is equipped with an A10 GPU, 96C CPU, and 251GB memory.

Upon investigation, I found a substantial portion of the time is spent in the following section:

self.model = CLIPVisionModelWithProjection(config)

Further exploration revealed that these time-consuming operations are primarily due to extensive initialization, such as:

https://github.com/huggingface/transformers/blob/366c03271e01c86e9a573bb64481f185de11ef29/src/transformers/models/clip/modeling_clip.py#L333-L334

https://github.com/huggingface/transformers/blob/366c03271e01c86e9a573bb64481f185de11ef29/src/transformers/models/clip/modeling_clip.py#L241-L244

This includes operations like nn.Linear, among others.

This issue is related to huggingface/transformers#21913.

After implementing this optimization, the average time consumption for clip vision can be compressed to at least 1/6 of the previous time. The results are highly stable, and there is no inconsistency in the inference outcomes.

In my case, before optimization, even on a completely idle machine, the preprocessing time for clip vision took at least 8 seconds. Now, it only requires 1.23 seconds.

@huchenlei
Copy link
Collaborator

I think this closes #2436. Thanks for the fix!

@huchenlei huchenlei merged commit 8b5f7c1 into Mikubill:main Jan 15, 2024
1 check passed
@storyicon
Copy link
Contributor Author

cool, so efficient.

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.

2 participants