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

"cannot perform operation across devices mps and cpu" when running examples with torchx and mps #275

Closed
lambadalambda opened this issue Nov 11, 2023 · 1 comment

Comments

@lambadalambda
Copy link

I tested a few examples in the documentation with the Torchx backend set to use :mps. They all fail with this error:

** (ArgumentError) cannot perform operation across devices mps and cpu
    (torchx 0.6.3) lib/torchx.ex:485: anonymous fn/2 in Torchx.prepare_tensors!/1
    (elixir 1.14.3) lib/enum.ex:1780: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.14.3) lib/enum.ex:1780: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (torchx 0.6.3) lib/torchx.ex:370: Torchx.clip/3
    (elixir 1.14.3) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
    (elixir 1.14.3) lib/enum.ex:4299: Enum.reduce_range/5
    (elixir 1.14.3) lib/enum.ex:2472: Enum.map/2
    (torchx 0.6.3) lib/torchx/backend.ex:529: Torchx.Backend.indices_from_nx/2

Here's example code to trigger it.

Mix.install([
  {:bumblebee, "~> 0.4.2"},
  {:torchx, ">= 0.0.0"}
])

Nx.default_backend({Torchx.Backend, device: :mps})

{:ok, bert} = Bumblebee.load_model({:hf, "bert-base-uncased"})
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "bert-base-uncased"})

serving = Bumblebee.Text.fill_mask(bert, tokenizer)
text = "The capital of [MASK] is Paris."

Nx.Serving.run(serving, text)
|> IO.inspect()

I understand that mps support is still in an experimental state, but I've been doing accelerated stable diffusion with python and libtorch for months now, so this should definitely be possible.

@lambadalambda lambadalambda changed the title "cannot perform operation across devices mps and cpu" when running examples with mps "cannot perform operation across devices mps and cpu" when running examples with torchx and mps Nov 11, 2023
@josevalim
Copy link
Contributor

This is tracked here: elixir-nx/nx#679

PRs are welcome. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants