exfrmdlrstu

exfrmdlrstu

How to use {:local, dir} when loading models in Bumblebee?

I’m getting errors when trying to use {:local, cache_dir} in Bumblebee’s load_model function. Checking the cache directory using cache_dir(), I was able to locate the models that I previously downloaded, but the files inside are hashed. Is there any way I could use the downloaded models so I can call each model on demand and not use too much memory/storage?

Here is an example code that I use to load from the cache if the model is already downloaded:

defp maybe_load_from_cache(whisper_model) do
    {_, model} = whisper_model
    model_path = String.replace(model, "/", "--")
    cache_dir = Path.join(Bumblebee.cache_dir(), "huggingface/#{model_path}")

    case File.ls(cache_dir) do
      {:ok, _files} ->
        {:local, cache_dir}
      _ ->
        whisper_model
    end
  end

Marked As Solved

jonatanklosko

jonatanklosko

Creator of Livebook

Hey @exfrmdlrstu! There are two distinct bits:

  1. The :local source allows you to point to a local directory that follows the usual structure of a HuggingFace Hub repository. For example, you could git clone a repository such as google-bert/bert-base-uncased and then use {:local, path_to_dir} to load from there.

  2. The internal cache, where bumblebee downloads the individual files from a remote repository. This cache is opaque and Bumblebee uses it to only download the given model/tokenizer file once. When you call Bumblebee.load_model/1 second time, it only makes a quick request to the HuggingFace repo to make sure the remote file hasn’t changed, and if it hasn’t, then simply reuses the one downloaded previously. You can actually disable all networking by setting BUMBLEBEE_OFFLINE=1 env var, or by loading from {:hf, "org/repo", offline: true} (if the model is not in the cache yet, the function raises).

Looking at your snippet specifically, I think what you are trying to do is what Bumblebee.load_model/1 already does by default, as described above. Let me know if I missed something : )

Also Liked

exfrmdlrstu

exfrmdlrstu

I see, so that’s what Bumblebee’s cache is for. This makes a lot of sense. Looks like I don’t need to worry using load_model on demand. Thank you for this, @jonatanklosko !

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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