How to install and compile a git fork of torchx

I have a problem compiling my custom fork of torchx , here is a code that is failing in a local installation of livebook, (tried tons of combinations and this code is an example):

Mix.install(
  [
    {:bumblebee, "~> 0.4.2"},
    {:nx, "~> 0.6.1"},
    {:torchx, git: "https://github.com/carakan/nx"},
    {:kino, "~> 0.10.0"}
  ],
  force: true,
  config: [
    nx: [default_backend: Torchx]
  ],
  system_env: [
    # LIBTORCH_VERSION: "2.1.0",
    LIBTORCH_DIR: "~/Downloads/libtorch"
  ]
)

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

and shows this error:

** (Mix.Error) App nx lists itself as a dependency
    (mix 1.15.5) lib/mix.ex:577: Mix.raise/2
    (elixir 1.15.5) lib/enum.ex:984: Enum."-each/2-lists^foreach/1-0-"/2
    (mix 1.15.5) lib/mix/dep/converger.ex:18: Mix.Dep.Converger.topological_sort/1
    (mix 1.15.5) lib/mix/dep/converger.ex:78: Mix.Dep.Converger.converge/4
    (mix 1.15.5) lib/mix/dep/fetcher.ex:16: Mix.Dep.Fetcher.all/3
    (mix 1.15.5) lib/mix/tasks/deps.get.ex:34: Mix.Tasks.Deps.Get.run/1
    (mix 1.15.5) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5
    /Users/carakan/Documents/libtorch-sd.livemd#cell:cxwhmrbzgh2dnojn5rvaagoeuzcdk6gl:1: (file)

I noticed that torchx is like a submodule into Nx project so it’s like an error of circular dependency. How can I correctly add my custom fork of nx and tochx?

Thanks in advance!

Try {:torchx, github: "carakan/nx", sparse: "torchx"}. Sparse means that the mix package is nested in the torchx/ directory in the github repo : )

Also note that the backend should be nx: [default_backend: Torchx.Backend] (although you use Nx.global_default_backend, so you don’t need that config altogether).

3 Likes