Skip to content

examples: cache hf model when --model not provided#7353

Merged
ggerganov merged 5 commits intoggml-org:masterfrom
amirzia:master
May 21, 2024
Merged

examples: cache hf model when --model not provided#7353
ggerganov merged 5 commits intoggml-org:masterfrom
amirzia:master

Conversation

@amirzia
Copy link
Copy Markdown
Contributor

@amirzia amirzia commented May 17, 2024

Ref: #7252

Comment thread common/common.cpp Outdated
Comment thread common/common.cpp Outdated
@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented May 17, 2024

Also, wouldn't it be nice to have LLAMA_CACHE default to $HOME/.cache/llama.cpp?

~/.cache actually exist on all modern desktop linux distro: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html

On windows, the equivalent of .cache is std::getenv("APPDATA")

Not sure what it is on macos.

@mofosyne mofosyne added enhancement New feature or request Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix labels May 18, 2024
@amirzia amirzia marked this pull request as draft May 18, 2024 07:12
Comment thread common/common.cpp Outdated
@amirzia
Copy link
Copy Markdown
Contributor Author

amirzia commented May 18, 2024

@ngxson Thanks for the comments. The default cache locations for all the 3 OSes are updated. The default application cache directory for macOS is ~/Library/Caches (+).

If the implementation looks good, I can go ahead and update the documentation accordingly.

@amirzia amirzia requested review from ggerganov and ngxson May 18, 2024 10:48
@amirzia amirzia marked this pull request as ready for review May 18, 2024 10:48
Comment thread common/common.cpp
Comment thread common/common.cpp
cache_directory = std::getenv("HOME") + std::string("/.cache/");
}
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think on Mac os pretty much all apps also use ~/.cache (so, same as linux)

Just my 2 cents

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use macos very often so I'm not sure. Maybe @ggerganov knows more about this?

My assumption is that ~/.cache widely used by applications ported from linux (maybe?), while ~/Library/Caches is the conventional OS X way (according to this documentation).

In either way, having model cached under user's $HOME is already very nice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see apps caches in both places on my machine - I guess either way is fine. Don't have an opinion

Copy link
Copy Markdown
Contributor

@ngxson ngxson May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep ~/Library/Caches then (as it is referred in apple's documentation)

@amirzia amirzia requested review from julien-c and ngxson May 20, 2024 15:21
Comment thread common/common.cpp Outdated
cache_directory += "llama.cpp";
cache_directory += DIRECTORY_SEPARATOR;
}
const bool success = create_directory_with_parents(cache_directory);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you forgot to remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, it should be removed now :)

Copy link
Copy Markdown
Member

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amirzia amirzia requested a review from ngxson May 21, 2024 12:28
Comment thread common/common.cpp
}
params.model = cache_directory + string_split(params.hf_file, '/').back();
}
} else if (!params.model_url.empty()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: Do you think we should also use cache dir under this condition params.model_url? @ggerganov

For now only params.hf_repo enables cache dir.

Copy link
Copy Markdown
Contributor

@ngxson ngxson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd prefer to also support cache dir with --model-url. But that's not very important for now.

@ggerganov ggerganov merged commit 11474e7 into ggml-org:master May 21, 2024
Comment thread common/common.cpp
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
#elif defined(_WIN32)
cache_directory = std::getenv("APPDATA");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the cache directory on Windows is %LOCALAPPDATA% (see platformdirs). %APPDATA% will be synced synced between computers in an Active Directory domain ("Roaming").

Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request May 21, 2024
* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided

* examples: cache hf model when --model not provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request examples Review Complexity : Low Trivial changes to code that most beginner devs (or those who want a break) can tackle. e.g. UI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants