10-quantize-callback.diff 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From ed941590d59fc07b1ad21d6aa458588e47d1e446 Mon Sep 17 00:00:00 2001
  2. From: Josh Yan <jyan00017@gmail.com>
  3. Date: Wed, 10 Jul 2024 13:39:39 -0700
  4. Subject: [PATCH] quantize progress
  5. ---
  6. include/llama.h | 3 +++
  7. src/llama.cpp | 8 ++++++++
  8. 2 files changed, 11 insertions(+)
  9. diff --git a/include/llama.h b/include/llama.h
  10. index bb4b05ba..613db68e 100644
  11. --- a/include/llama.h
  12. +++ b/include/llama.h
  13. @@ -349,6 +349,9 @@ extern "C" {
  14. bool keep_split; // quantize to the same number of shards
  15. void * imatrix; // pointer to importance matrix data
  16. void * kv_overrides; // pointer to vector containing overrides
  17. +
  18. + llama_progress_callback quantize_callback; // callback to report quantization progress
  19. + void * quantize_callback_data; // user data for the callback
  20. } llama_model_quantize_params;
  21. // grammar types
  22. diff --git a/src/llama.cpp b/src/llama.cpp
  23. index 2b9ace28..ac640c02 100644
  24. --- a/src/llama.cpp
  25. +++ b/src/llama.cpp
  26. @@ -18252,6 +18252,12 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
  27. const auto tn = LLM_TN(model.arch);
  28. new_ofstream(0);
  29. for (int i = 0; i < ml.n_tensors; ++i) {
  30. + if (params->quantize_callback){
  31. + if (!params->quantize_callback(i, params->quantize_callback_data)) {
  32. + return;
  33. + }
  34. + }
  35. +
  36. auto weight = ml.get_weight(i);
  37. struct ggml_tensor * tensor = weight->tensor;
  38. if (weight->idx != cur_split && params->keep_split) {
  39. @@ -18789,6 +18795,8 @@ struct llama_model_quantize_params llama_model_quantize_default_params() {
  40. /*.keep_split =*/ false,
  41. /*.imatrix =*/ nullptr,
  42. /*.kv_overrides =*/ nullptr,
  43. + /*.quantize_callback =*/ nullptr,
  44. + /*.quantize_callback_data =*/ nullptr,
  45. };
  46. return result;
  47. --
  48. 2.39.3 (Apple Git-146)