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

webui support controlnet extension #948

Merged
merged 23 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions onediff_sd_webui_extensions/compile/compile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def get_calibrate_info(filename: str) -> Union[None, Dict]:


def get_compiled_graph(sd_model, quantization) -> OneDiffCompiledGraph:
compiled_unet = compile_unet(
sd_model.model.diffusion_model, quantization=quantization
)
diffusion_model = sd_model.model.diffusion_model
# for controlnet
if "forward" in diffusion_model.__dict__:
diffusion_model.__dict__.pop("forward")
compiled_unet = compile_unet(diffusion_model, quantization=quantization)
return OneDiffCompiledGraph(sd_model, compiled_unet, quantization)
27 changes: 16 additions & 11 deletions onediff_sd_webui_extensions/compile/sd_webui_onediff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ def forward(self, x):


# https://github.com/Stability-AI/generative-models/blob/059d8e9cd9c55aea1ef2ece39abf605efb8b7cc9/sgm/modules/diffusionmodules/util.py#L207
def timestep_embedding(timesteps, dim, max_period=10000):
half = dim // 2
freqs = flow.exp(
-math.log(max_period)
* flow.arange(start=0, end=half, dtype=flow.float32)
/ half
).to(device=timesteps.device)
args = timesteps[:, None].float() * freqs[None]
embedding = flow.cat([flow.cos(args), flow.sin(args)], dim=-1)
if dim % 2:
embedding = flow.cat([embedding, flow.zeros_like(embedding[:, :1])], dim=-1)
def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):
if not repeat_only:
half = dim // 2
freqs = flow.exp(
-math.log(max_period)
* flow.arange(start=0, end=half, dtype=flow.float32)
/ half
).to(device=timesteps.device)
args = timesteps[:, None].float() * freqs[None]
embedding = flow.cat([flow.cos(args), flow.sin(args)], dim=-1)
if dim % 2:
embedding = flow.cat([embedding, flow.zeros_like(embedding[:, :1])], dim=-1)
else:
raise NotImplementedError(
"repeat_only=True is not implemented in timestep_embedding"
)
return embedding


Expand Down
Loading