mortenlund

mortenlund

Torchx: OOM (out of memory) on Windows

Hi!

I am using Elixir 1.18.3 on OTP 27.
Using torchx version 0.10 compiled using LIBTORCH_TARGET=cu128 and LIBTORCH_VERSION=2.9.0

I am trying to hunt down a serious memory leak / no-free situation when using Torchx.
This is very easy to reproduce using the code below.

The issue is that the virtual memory increases in eternity.

GPU memory is released at intervals as I expect libtorch to do keeping the load at a acceptable level:

I was hunting down a memory leak in the Ortex library (I thought) but it turned out the problem was in Torchx which I used to prepare som data I sent into Ortex.

defmodule Mix.Tasks.Simple do
  @impl Mix.Task
  def run(_args) do
    10000
    |> runner()
  end

  defp runner(0), do: :ok

  defp runner(ittr) do
    Task.async(fn ->
      tensor =
        Nx.broadcast(0, {1, 3, 640, 640})
        |> Nx.backend_transfer(Nx.default_backend())
    end)
    |> Task.await()

    Process.sleep(50)

    runner(ittr - 1)
  end
end

I have also tried to use :erlang.garbage_collect to try releasing the memory but that does nothing.
I also, as you can see put the code into a Task as I thought maybe the memory was “trapped” in my parent process.
This also did nothing.

Anyone have any ideas?

I would really like to run this in WSL and use EXLA instead, but due to peripherals I have to stay in Windows.

Marked As Solved

polvalente

polvalente

Nx Core Team

Just to update the thread here, Torchx on main has been refactored to use elixir-nx/fine for the NIFs. This both fixes the bug and makes it easier to maintain the NIFs!

Also Liked

polvalente

polvalente

Nx Core Team

Please report this as an issue on the Nx repository.

Do you know if this bug happens on Linux or Mac too?

edit:

After re-reading your code, I have a follow-up question: Where did you call :erlang.garbage_collect? What happens if you call it right after Task.await?

mortenlund

mortenlund

I can confirm that this only happens on Windows if my understanding of Linux htop is correct.

I also tried for libtorch 2.7.1 now, and it was the same as 2.8.0

mortenlund

mortenlund

Issue created here:

https://github.com/elixir-nx/nx/issues/1637

Maybe someone else on Windows could verify my test? :slight_smile:

Last Post!

mortenlund

mortenlund

Great @polvalente ! :partying_face::partying_face:

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement