mgwidmann
I’ve run into an issue that I don’t understand. Running on an M1 mac with 32 GB of ram trying to execute a very small LLM and I’m seeing huge times to do certain function calls.
In my GenServer, I have the following:
# @model "meta-llama/Llama-3.1-8B-Instruct"
# @model "mistralai/Mistral-7B-Instruct-v0.3"
# @model "HuggingFaceTB/SmolLM2-1.7B-Instruct"
@model "meta-llama/Llama-3.2-1B-Instruct"
def handle_cast(:load_model, _nothing) do
Logger.info("Async model load beginning...", [service: "RagLLM"])
repo = {:hf, @model, auth_token: System.fetch_env!("HF_TOKEN")}
{:ok, model_info} = Bumblebee.load_model(repo, type: :bf16)
Logger.info("Model loaded", [service: "RagLLM"])
{:ok, tokenizer} = Bumblebee.load_tokenizer(repo)
Logger.info("Tokenizer loaded", [service: "RagLLM"])
{:ok, generation_config} = Bumblebee.load_generation_config(repo)
Logger.info("Generation Config loaded", [service: "RagLLM"])
generation_config = Bumblebee.configure(generation_config, max_new_tokens: 100)
Logger.info("Model, tokenizer defined, bumblebee configured", [service: "RagLLM"])
serving =
Bumblebee.Text.generation(model_info, tokenizer, generation_config,
compile: [batch_size: 1, sequence_length: 6000]
)
Logger.info("Serving created", [service: "RagLLM"])
{:ok, _server} = Nx.Serving.start_link(serving: serving, name: LLMServing, batch_timeout: 100)
{:noreply, serving}
end
The load_model call can take 5 minutes to finish the load_model call. I’m using EMLX for my mac by setting the following in my application start function:
if :os.type() == {:unix, :darwin} do
IO.puts("Loading EMLX for MacOS")
Nx.default_backend({EMLX.Backend, device: :gpu})
Nx.Defn.default_options(compiler: EMLX)
else
Nx.default_backend({EXLA.Backend, device: :gpu})
Nx.Defn.default_options(compiler: EXLA)
end
But in an invoke_model.exs file, it gets through this line instantly but hangs on the NX.Serving.run/2 call.
if :os.type() == {:unix, :darwin} do
Application.ensure_all_started(:emlx)
Nx.default_backend({EMLX.Backend, device: :gpu})
Nx.Defn.default_options(compiler: EMLX)
else
Application.ensure_all_started(:exla)
end
Application.ensure_all_started(:bumblebee)
:observer.start()
repo = {:hf, "meta-llama/Llama-3.2-1B-Instruct", auth_token: System.fetch_env!("HF_TOKEN")}
{:ok, model_info} = Bumblebee.load_model(repo, type: :bf16)
IO.puts("Model loaded")
{:ok, tokenizer} = Bumblebee.load_tokenizer(repo)
IO.puts("Tokenizer loaded")
{:ok, generation_config} = Bumblebee.load_generation_config(repo)
IO.puts("Generation Config loaded")
generation_config = Bumblebee.configure(generation_config, max_new_tokens: 100)
IO.puts("Model, tokenizer defined, bumblebee configured")
serving =
Bumblebee.Text.generation(model_info, tokenizer, generation_config,
compile: [batch_size: 1, sequence_length: 6000]
)
IO.puts("Starting serving")
{:ok, _server} = Nx.Serving.start_link(serving: serving, name: LLMServing, batch_timeout: 100)
:timer.sleep(10_000)
IO.puts("Simple run call") # Last output that shows up
IO.inspect(Nx.Serving.run(serving, "What is the meaning of life?"))
IO.puts("Running model...")
IO.inspect(Nx.Serving.batched_run(LLMServing, "What is the meaning of life?"))
IO.puts("Done!")
I am not sure what I am doing wrong. Any ideas?
Trending in Questions
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
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
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jonatanklosko
You want this:
default_backendapplies only to the calling process,global_default_backendapplies to all.What about the
batch_run? For how long does it hang? Does it work in the same setup if you use EXLA instead?mgwidmann
Yes, I can’t get this function to complete either. I’ve waited over 30 minutes and nothing.
mgwidmann
I’m trying even on an EC2 machine with 23 GB of GPU memory and can’t load the
"meta-llama/Llama-3.2-1B-Instruct"model.jonatanklosko
Do you have cuDNN installed on the machine? Which version?
Note that you can also try EXLA with CPU, if you have enough RAM. It will take a while, but if it finishes, we will known that the issue is likely in EMLX.
mgwidmann
It appears yes it is already installed. I used the deep learning image, so most things should already be there I expect.
jonatanklosko
What is the cuDNN version? You can check using something like
apt list --installed | grep libcudnn.mgwidmann
I was able to get it working but changing my
PATHandLD_LIBRARY_PATHto be the latest 12.8 but it uses 20 G of GPU memory when the huggingface calculator says it should only require 1-4 G (18 G to train) and I’m only doing inference so its using way more memory than needed it seems to me.It does seem like EMXL is having issues for me. On this machine it takes 2 minutes to load the model and execute. I also tried on an arm64 machine but couldn’t get it to work, perhaps it will if I make similar fixes like I did here.
mgwidmann
Made the same changes to the arm64 machine and no, getting warnings and a crash. Used only 13 G of GPU memory though, out of the 15 G it has.
So looks like it needs the full 20 G it is using on the other machine. I don’t understand why it needs so much nor do I understand why it doesn’t work with EMLX
mgwidmann
I came across this issue, I wonder if it is the root cause since its still open. It could be crashed and not reporting anywhere.
https://github.com/elixir-nx/emlx/issues/58
mgwidmann
Forcing
{:nx, "~> 0.10.0", override: true},got the examples working in that issue, so perhaps there have been updates that EMLX should update to. Just not my issue for some reason…