tahamajs's picture
download
raw
1.43 kB
import torch
import torch.nn as nn
from packaging import version
OPENAIUNETWRAPPER = "sgm.modules.diffusionmodules.wrappers.OpenAIWrapper"
class IdentityWrapper(nn.Module):
def __init__(self, diffusion_model, compile_model: bool = False):
super().__init__()
compile = (
torch.compile
if (version.parse(torch.__version__) >= version.parse("2.0.0"))
and compile_model
else lambda x: x
)
self.diffusion_model = compile(diffusion_model)
def forward(self, *args, **kwargs):
return self.diffusion_model(*args, **kwargs)
class OpenAIWrapper(IdentityWrapper):
def forward(
self, x: torch.Tensor, t: torch.Tensor, c: dict, **kwargs
) -> torch.Tensor:
x = torch.cat((x, c.get("concat", torch.Tensor([]).type_as(x))), dim=1)
if "cond_view" in c:
return self.diffusion_model(
x,
timesteps=t,
context=c.get("crossattn", None),
y=c.get("vector", None),
cond_view=c.get("cond_view", None),
cond_motion=c.get("cond_motion", None),
**kwargs,
)
else:
return self.diffusion_model(
x,
timesteps=t,
context=c.get("crossattn", None),
y=c.get("vector", None),
**kwargs,
)

Xet Storage Details

Size:
1.43 kB
·
Xet hash:
0488d472e8e55771a98a0e3c70b738f9120d8f08706f1cdc41bb898d042f4ad6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.