Repository navigation
llama : add --n-cpu-ffn option #26622
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| #include "ggml.h" | ||
| #include "llama.h" | ||
|
|
||
| #include <list> | ||
| #include <set> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
@@ -1083,11 +1084,13 @@ const char * const LLM_KV_SPLIT_TENSORS_COUNT = "split.tensors.count"; | |
| } | ||
|
|
||
| // | ||
| // MoE utils | ||
| // FFN offload utils | ||
| // | ||
|
|
||
| const char * const LLM_FFN_EXPS_REGEX = "\\.ffn_(up|down|gate|gate_up)_(ch|)exps"; | ||
|
|
||
| const char * const LLM_FFN_DENSE_REGEX = "\\.ffn_(up|down|gate)\\."; | ||
|
|
||
| inline std::string llm_ffn_exps_block_regex(int idx) { | ||
| return string_format("blk\\.%d%s", idx, LLM_FFN_EXPS_REGEX); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either adapt this to take the regex and rename or replace it in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Should --n-cpu-ffn also become part of llama-bench, mirroring --n-cpu-moe?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useful, doesn't have to be in this PR though. |
||
|
|
@@ -1096,6 +1099,15 @@ inline llama_model_tensor_buft_override llm_ffn_exps_cpu_override() { | |
| return { LLM_FFN_EXPS_REGEX, ggml_backend_cpu_buffer_type() }; | ||
| } | ||
|
|
||
| inline void llm_add_n_cpu_ffn_overrides(int n, const char * ffn_regex, std::vector<llama_model_tensor_buft_override> & overrides) { | ||
| // keep strings alive and avoid leaking memory by storing them in a static list | ||
| static std::list<std::string> buft_override_strings; | ||
| for (int i = 0; i < n; ++i) { | ||
| buft_override_strings.push_back(string_format("blk\\.%d%s", i, ffn_regex)); | ||
| overrides.push_back({buft_override_strings.back().c_str(), ggml_backend_cpu_buffer_type()}); | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // training utils | ||
| // | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.