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

Add mps backend for Pytorch in HF models #138

Merged
merged 1 commit into from
Jun 7, 2023
Merged
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
2 changes: 2 additions & 0 deletions outlines/models/hf_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def call_stable_diffusion_pipeline(
pipe = StableDiffusionPipeline.from_pretrained(model_name)
if torch.cuda.is_available():
pipe = pipe.to("cuda")
elif torch.backends.mps.is_available():
pipe = pipe.to("mps")

images = pipe(prompt, num_images_per_prompt=samples).images
if not isinstance(images, list):
Expand Down
3 changes: 3 additions & 0 deletions outlines/models/hf_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def call_model_generate_method(
if torch.cuda.is_available():
model = model.to("cuda")
prompt_tokens = prompt_tokens.to("cuda")
elif torch.backends.mps.is_available():
model = model.to("mps")
prompt_tokens = prompt_tokens.to("mps")

returned_tokens = model.generate(
**prompt_tokens,
Expand Down