-
Notifications
You must be signed in to change notification settings - Fork 12.4k
finetune.cpp command-line arg #13873
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
Open
graehl
wants to merge
1
commit into
ggml-org:master
Choose a base branch
from
graehl:finelayer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+727
−211
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,20 +10,20 @@ | |
#include <vector> | ||
|
||
#if defined(_MSC_VER) | ||
#pragma warning(disable: 4244 4267) // possible loss of data | ||
#pragma warning(disable: 4244 4267) // possible loss of data | ||
#endif | ||
|
||
int main(int argc, char ** argv) { | ||
common_params params; | ||
|
||
params.escape = false; | ||
|
||
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_PERPLEXITY)) { | ||
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_FINETUNE)) { | ||
return 1; | ||
} | ||
|
||
if (params.use_mmap) { | ||
LOG_INF("%s: force disabling memory mapping because it would result in-read-only pointers to the weights\n", __func__); | ||
LOG_INF("%s: force disabling memory mapping because it would result in-read-only pointers to the weights\n", | ||
__func__); | ||
params.use_mmap = false; | ||
} | ||
if (params.cache_type_k != GGML_TYPE_F32) { | ||
|
@@ -38,11 +38,11 @@ int main(int argc, char ** argv) { | |
common_init(); | ||
llama_backend_init(); | ||
llama_numa_init(params.numa); | ||
|
||
// load the model and apply lora adapter, if any | ||
common_init_result llama_init = common_init_from_params(params); | ||
llama_model_ptr & model = llama_init.model; | ||
llama_context_ptr & ctx = llama_init.context; | ||
common_init_result llama_init = common_init_from_params(params); | ||
llama_model_ptr & model = llama_init.model; | ||
llama_context_ptr & ctx = llama_init.context; | ||
auto pctx = ctx.get(); | ||
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. If possible, please avoid the use of 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. no prob. |
||
|
||
if (model == NULL) { | ||
LOG_ERR("%s: unable to load model\n", __func__); | ||
|
@@ -55,31 +55,32 @@ int main(int argc, char ** argv) { | |
LOG_INF("%s\n", common_params_get_system_info(params).c_str()); | ||
} | ||
|
||
constexpr float val_split = 0.05f; | ||
|
||
std::vector<llama_token> tokens = common_tokenize(ctx.get(), params.prompt, true); | ||
ggml_opt_dataset_t dataset = common_opt_dataset_init(ctx.get(), tokens, llama_n_ctx(ctx.get())/2); | ||
|
||
struct ggml_opt_optimizer_params optimizer_params = ggml_opt_get_default_optimizer_params(nullptr); | ||
optimizer_params.adamw.alpha = 1e-7f; // learning rate | ||
|
||
struct llama_opt_params lopt_params { | ||
/*n_ctx_train =*/ 0, | ||
/*param_filter =*/ llama_opt_param_filter_all, | ||
/*param_filter_ud =*/ nullptr, | ||
/*get_opt_pars =*/ ggml_opt_get_constant_optimizer_params, | ||
/*get_opt_pars_ud =*/ &optimizer_params, | ||
std::vector<llama_token> tokens = common_tokenize(pctx, params.prompt, true); | ||
ggml_opt_dataset_t dataset = common_opt_dataset_init(pctx, tokens, llama_n_ctx(pctx) / 2); | ||
|
||
struct lr_opt & lr = params.lr; | ||
LOG_INF("-optimizer %s -lr0 %.2g -wd %.2g -lr-min %.2g -min-epochs %.2g -epochs %d -period %.2g -val %.2g\n", | ||
ggml_opt_optimizer_name(params.optimizer), (double) lr.lr0, (double) lr.wd, (double) lr.lr_min, (double) lr.min_epochs, | ||
(unsigned) lr.epochs, (double) params.n_batch / params.n_ubatch, (double) params.val_split); | ||
|
||
struct llama_opt_params lopt_params{ | ||
/*n_ctx_train =*/0, | ||
/*param_filter =*/llama_opt_param_filter_all, | ||
/*param_filter_ud =*/nullptr, | ||
/*get_opt_pars =*/common_opt_lr_pars, | ||
/*get_opt_pars_ud =*/¶ms.lr, | ||
/*optimizer_type =*/params.optimizer, | ||
}; | ||
llama_opt_init(ctx.get(), model.get(), lopt_params); | ||
llama_opt_init(pctx, model.get(), lopt_params); | ||
|
||
const int64_t idata_split = ggml_opt_dataset_ndata(dataset) * (1.0f - val_split); | ||
const int64_t idata_split = ggml_opt_dataset_ndata(dataset) * (1.0f - params.val_split); | ||
|
||
ggml_opt_result_t result_train = ggml_opt_result_init(); | ||
ggml_opt_result_t result_eval = ggml_opt_result_init(); | ||
|
||
for (int epoch = 0; epoch < 2; ++epoch) { | ||
llama_opt_epoch(ctx.get(), dataset, result_train, result_eval, idata_split, | ||
ggml_opt_epoch_callback_progress_bar, ggml_opt_epoch_callback_progress_bar); | ||
for (lr.epoch = 0; lr.epoch < lr.epochs; ++lr.epoch) { | ||
llama_opt_epoch(pctx, dataset, result_train, result_eval, idata_split, | ||
ggml_opt_epoch_callback_progress_bar, ggml_opt_epoch_callback_progress_bar); | ||
fprintf(stderr, "\n"); | ||
|
||
ggml_opt_result_reset(result_train); | ||
|
@@ -88,7 +89,7 @@ int main(int argc, char ** argv) { | |
ggml_opt_result_free(result_train); | ||
ggml_opt_result_free(result_eval); | ||
|
||
llama_model_save_to_file(model.get(), "finetuned-model.gguf"); | ||
llama_model_save_to_file(model.get(), params.out_file.c_str()); | ||
|
||
llama_backend_free(); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.