2024-03-23 01:24:36 +01:00
|
|
|
#include "ggml.h"
|
|
|
|
#include "llama.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "ngram-cache.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-06-13 01:41:52 +02:00
|
|
|
static void print_usage(char* argv0) {
|
2024-03-23 01:24:36 +01:00
|
|
|
fprintf(stderr, "Merges multiple lookup cache files into a single one.\n");
|
2024-06-13 01:41:52 +02:00
|
|
|
fprintf(stderr, "Usage: %s [--help] lookup_part_1.bin lookup_part_2.bin ... lookup_merged.bin\n", argv0);
|
2024-03-23 01:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv){
|
|
|
|
if (argc < 3) {
|
2024-06-13 01:41:52 +02:00
|
|
|
print_usage(argv[0]);
|
2024-03-23 01:24:36 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> args;
|
|
|
|
args.resize(argc-1);
|
|
|
|
for (int i = 0; i < argc-1; ++i) {
|
|
|
|
args[i] = argv[i+1];
|
|
|
|
if (args[i] == "-h" || args[i] == "--help") {
|
2024-06-13 01:41:52 +02:00
|
|
|
print_usage(argv[0]);
|
2024-03-23 01:24:36 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "lookup-merge: loading file %s\n", args[0].c_str());
|
2024-10-10 22:57:42 +02:00
|
|
|
common_ngram_cache ngram_cache_merged = common_ngram_cache_load(args[0]);
|
2024-03-23 01:24:36 +01:00
|
|
|
|
|
|
|
for (size_t i = 1; i < args.size()-1; ++i) {
|
|
|
|
fprintf(stderr, "lookup-merge: loading file %s\n", args[i].c_str());
|
2024-10-10 22:57:42 +02:00
|
|
|
common_ngram_cache ngram_cache = common_ngram_cache_load(args[i]);
|
2024-03-23 01:24:36 +01:00
|
|
|
|
2024-10-10 22:57:42 +02:00
|
|
|
common_ngram_cache_merge(ngram_cache_merged, ngram_cache);
|
2024-03-23 01:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "lookup-merge: saving file %s\n", args.back().c_str());
|
2024-10-10 22:57:42 +02:00
|
|
|
common_ngram_cache_save(ngram_cache_merged, args.back());
|
2024-03-23 01:24:36 +01:00
|
|
|
}
|