Skip to content

Commit

Permalink
Add Bumblebee.cache_dir/0 for discovering cache location (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Jun 26, 2023
1 parent 23de64b commit 30bce91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 12 additions & 0 deletions lib/bumblebee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -932,4 +932,16 @@ defmodule Bumblebee do
"expected repository to be either {:hf, repository_id}, {:hf, repository_id, options}" <>
" or {:local, directory}, got: #{inspect(other)}"
end

@doc """
Returns the directory where downloaded files are stored.
"""
@spec cache_dir() :: String.t()
def cache_dir() do
if dir = System.get_env("BUMBLEBEE_CACHE_DIR") do
Path.expand(dir)
else
:filename.basedir(:user_cache, "bumblebee")
end
end
end
10 changes: 1 addition & 9 deletions lib/bumblebee/huggingface/hub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Bumblebee.HuggingFace.Hub do
"""
@spec cached_download(String.t(), keyword()) :: {:ok, String.t()} | {:error, String.t()}
def cached_download(url, opts \\ []) do
cache_dir = opts[:cache_dir] || bumblebee_cache_dir()
cache_dir = opts[:cache_dir] || Bumblebee.cache_dir()
offline = opts[:offline] || bumblebee_offline?()
auth_token = opts[:auth_token]

Expand Down Expand Up @@ -154,14 +154,6 @@ defmodule Bumblebee.HuggingFace.Hub do
File.write(path, json)
end

defp bumblebee_cache_dir() do
if dir = System.get_env("BUMBLEBEE_CACHE_DIR") do
Path.expand(dir)
else
:filename.basedir(:user_cache, "bumblebee")
end
end

defp bumblebee_offline?() do
System.get_env("BUMBLEBEE_OFFLINE") in ~w(1 true)
end
Expand Down

0 comments on commit 30bce91

Please sign in to comment.