lookup-create.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "arg.h"
  2. #include "common.h"
  3. #include "ngram-cache.h"
  4. #include "llama.h"
  5. #include <string>
  6. #include <vector>
  7. int main(int argc, char ** argv){
  8. common_params params;
  9. if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_LOOKUP)) {
  10. return 1;
  11. }
  12. // init llama.cpp
  13. llama_backend_init();
  14. llama_numa_init(params.numa);
  15. // load the model
  16. common_init_result llama_init = common_init_from_params(params);
  17. llama_model_ptr & model = llama_init.model;
  18. llama_context_ptr & ctx = llama_init.context;
  19. GGML_ASSERT(model != nullptr);
  20. // tokenize the prompt
  21. std::vector<llama_token> inp;
  22. inp = common_tokenize(ctx.get(), params.prompt, true, true);
  23. fprintf(stderr, "%s: tokenization done\n", __func__);
  24. common_ngram_cache ngram_cache;
  25. common_ngram_cache_update(ngram_cache, LLAMA_NGRAM_STATIC, LLAMA_NGRAM_STATIC, inp, inp.size(), true);
  26. fprintf(stderr, "%s: hashing done, writing file to %s\n", __func__, params.lookup_cache_static.c_str());
  27. common_ngram_cache_save(ngram_cache, params.lookup_cache_static);
  28. return 0;
  29. }