lookup-create.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "ggml.h"
  2. #include "llama.h"
  3. #include "common.h"
  4. #include "ngram-cache.h"
  5. #include <cstdint>
  6. #include <fstream>
  7. #include <iostream>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <vector>
  11. int main(int argc, char ** argv){
  12. gpt_params params;
  13. if (!gpt_params_parse(argc, argv, params)) {
  14. return 1;
  15. }
  16. // init llama.cpp
  17. llama_backend_init();
  18. llama_numa_init(params.numa);
  19. llama_model * model = NULL;
  20. llama_context * ctx = NULL;
  21. // load the model
  22. std::tie(model, ctx) = llama_init_from_gpt_params(params);
  23. GGML_ASSERT(model != nullptr);
  24. // tokenize the prompt
  25. const bool add_bos = llama_should_add_bos_token(model);
  26. std::vector<llama_token> inp;
  27. inp = ::llama_tokenize(ctx, params.prompt, add_bos, true);
  28. fprintf(stderr, "%s: tokenization done\n", __func__);
  29. llama_ngram_cache ngram_cache;
  30. llama_ngram_cache_update(ngram_cache, LLAMA_NGRAM_STATIC, LLAMA_NGRAM_STATIC, inp, inp.size(), true);
  31. fprintf(stderr, "%s: hashing done, writing file to %s\n", __func__, params.lookup_cache_static.c_str());
  32. llama_ngram_cache_save(ngram_cache, params.lookup_cache_static);
  33. }