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

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

Merged
merged 5 commits into from
May 21, 2024

Conversation

amirzia
Copy link
Contributor

@amirzia amirzia commented May 17, 2024

Ref: #7252

common/common.cpp Outdated Show resolved Hide resolved
common/common.cpp Outdated Show resolved Hide resolved
@ngxson
Copy link
Collaborator

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
common/common.cpp Outdated Show resolved Hide resolved
@amirzia
Copy link
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 ngxson and ggerganov May 18, 2024 10:48
@amirzia amirzia marked this pull request as ready for review May 18, 2024 10:48
cache_directory = std::getenv("HOME") + std::string("/.cache/");
}
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
Copy link
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
Collaborator

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
Owner

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
Collaborator

@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 ngxson and julien-c May 20, 2024 15:21
cache_directory += "llama.cpp";
cache_directory += DIRECTORY_SEPARATOR;
}
const bool success = create_directory_with_parents(cache_directory);
Copy link
Collaborator

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
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
Owner

@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
if (!success) {
throw std::runtime_error("failed to create cache directory: " + cache_directory);
}
params.model = cache_directory + string_split(params.hf_file, '/').back();
}
} else if (!params.model_url.empty()) {
Copy link
Collaborator

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
Collaborator

@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 ggerganov:master May 21, 2024
52 of 69 checks passed
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
#elif defined(_WIN32)
cache_directory = std::getenv("APPDATA");
Copy link
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/kobold.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
teleprint-me pushed a commit to teleprint-me/llama.cpp that referenced this pull request May 23, 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
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
Development

Successfully merging this pull request may close these issues.

None yet

6 participants