Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions ldm/models/diffusion/ddim.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def __init__(self, model, schedule="linear", **kwargs):

def register_buffer(self, name, attr):
if type(attr) == torch.Tensor:
if attr.device != torch.device("cuda"):
attr = attr.to(torch.device("cuda"))
# if attr.device != torch.device("cuda"):
# attr = attr.to(torch.device("cuda"))
if attr.device != torch.device("mps"):
attr = attr.to(torch.float32).to(torch.device("mps")).contiguous()
setattr(self, name, attr)

def make_schedule(self, ddim_num_steps, ddim_discretize="uniform", ddim_eta=0., verbose=True):
Expand Down
9 changes: 6 additions & 3 deletions scripts/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def load_model_from_config(config, ckpt, verbose=False):
print("unexpected keys:")
print(u)

model.cuda()
# model.cuda()
model.to("mps")
model.eval()
return model

Expand Down Expand Up @@ -199,7 +200,8 @@ def main():
config = OmegaConf.load(f"{opt.config}")
model = load_model_from_config(config, f"{opt.ckpt}")

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
# device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
device = torch.device("mps") if torch.backends.mps.is_available() else torch.device("cpu")
model = model.to(device)

if opt.plms:
Expand Down Expand Up @@ -242,7 +244,8 @@ def main():

precision_scope = autocast if opt.precision == "autocast" else nullcontext
with torch.no_grad():
with precision_scope("cuda"):
# with precision_scope("cuda"):
with nullcontext("mps"):
with model.ema_scope():
tic = time.time()
all_samples = list()
Expand Down