Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bumblebee.cache_dir/0 for discovering cache location #220

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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