Skip to content

Commit

Permalink
remove custom mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil committed Sep 13, 2024
1 parent 53eedc6 commit a706204
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 4,538 deletions.
281 changes: 201 additions & 80 deletions optimum/onnxruntime/modeling_diffusion.py

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions optimum/onnxruntime/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,23 @@ def evaluation_loop(
metrics = {}

return EvalLoopOutput(predictions=all_preds, label_ids=all_labels, metrics=metrics, num_samples=len(dataset))


def np_to_pt(np_object, device):
if isinstance(np_object, np.ndarray):
if np_object.ndim == 4:
return torch.from_numpy(np_object).permute(0, 3, 1, 2)
elif np_object.ndim == 3:
return torch.from_numpy(np_object).permute(2, 0, 1)
else:
return torch.from_numpy(np_object)
elif isinstance(np_object, list) and isinstance(np_object[0], np.ndarray):
return [np_to_pt(a, device) for a in np_object]
elif isinstance(np_object, dict) and isinstance(next(iter(np_object.values())), np.ndarray):
return {k: np_to_pt(v, device) for k, v in np_object.items()}
elif isinstance(np_object, np.random.RandomState):
return torch.Generator(device=device).manual_seed(int(np_object.get_state()[1][0]))
elif isinstance(np_object, list) and isinstance(np_object[0], np.random.RandomState):
return [torch.Generator(device=device).manual_seed(int(a.get_state()[1][0])) for a in np_object]
else:
return np_object
445 changes: 0 additions & 445 deletions optimum/pipelines/diffusers/pipeline_latent_consistency.py

This file was deleted.

732 changes: 0 additions & 732 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion.py

This file was deleted.

533 changes: 0 additions & 533 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion_img2img.py

This file was deleted.

782 changes: 0 additions & 782 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion_inpaint.py

This file was deleted.

982 changes: 0 additions & 982 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion_xl.py

This file was deleted.

928 changes: 0 additions & 928 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion_xl_img2img.py

This file was deleted.

54 changes: 0 additions & 54 deletions optimum/pipelines/diffusers/pipeline_utils.py

This file was deleted.

14 changes: 12 additions & 2 deletions tests/onnxruntime/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,20 @@ def test_negative_prompt(self, model_arch: str):
inputs["negative_prompt_embeds"],
inputs["pooled_prompt_embeds"],
inputs["negative_pooled_prompt_embeds"],
) = pipeline.encode_prompt(prompt=prompt, negative_prompt=negative_prompt)
) = pipeline.encode_prompt(
prompt=prompt,
num_images_per_prompt=1,
device=torch.device("cpu"),
do_classifier_free_guidance=True,
negative_prompt=negative_prompt,
)
else:
inputs["prompt_embeds"], inputs["negative_prompt_embeds"] = pipeline.encode_prompt(
prompt=prompt, negative_prompt=negative_prompt
prompt=prompt,
num_images_per_prompt=1,
device=torch.device("cpu"),
do_classifier_free_guidance=True,
negative_prompt=negative_prompt,
)

images_2 = pipeline(**inputs, generator=get_generator("pt", SEED)).images
Expand Down

0 comments on commit a706204

Please sign in to comment.