mortenlund

mortenlund

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.

Showing Posts 1 to 10

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 OP

I will try to build for linux and check.

Will create an issue.

Thanks for the reply!

mortenlund

mortenlund OP

I tried both inside the Task and also after the Task.await

polvalente

polvalente

Nx Core Team

Thanks. I’d have expected either to have worked.
Also try to use Nx.backend_deallocate inside the task, so we can see if there’s a chance that function itself is busted.

mortenlund

mortenlund OP

I have also tried using the backend_deallocation function with same result :slight_smile:

Currently trying to build torchx for WSL to check for same problem there.

mortenlund

mortenlund OP

Sofar in my test this does not behave the same way on linux.
I will try to downgrade libtorch on the windows test as the latest version for Linux is 2.7.1

Using htop, both VIRT, RES and SHR stayed stable during the test.

mortenlund

mortenlund OP

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

polvalente

polvalente

Nx Core Team

It’s very likely this is a Windows-only bug. Please report this as an issue with a summary of these findings!

mortenlund

mortenlund OP

Issue created here:

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

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

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!

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews