-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
132 lines (121 loc) · 6.54 KB
/
Copy pathmain.cpp
File metadata and controls
132 lines (121 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <csignal>
#include <getopt.h>
#include "uzaleat_core.hpp"
#ifdef _OPENMP
#include <omp.h>
#endif
void print_usage(const char* prog) {
std::cout << "Usage: " << prog << " [options]\n"
<< "Options:\n"
<< " --plugin FILE .gutr plugin file\n"
<< " --model-so FILE .so model file (alternative to --plugin)\n"
<< " --train Training mode\n"
<< " --chat Chat mode\n"
<< " --data PATH Training data path\n"
<< " --tokenizer FILE Tokenizer file\n"
<< " --model FILE Model file (output/input GGUF)\n"
<< " --hidden N Hidden size (default 768)\n"
<< " --layers N Number of layers (default 12)\n"
<< " --context N Context size (default 1024)\n"
<< " --epochs N Epochs (default 3)\n"
<< " --lr F Learning rate (default 0.0001)\n"
<< " --batch N Batch size (default 8)\n"
<< " --threads N CPU threads (default 4)\n"
<< " --gpu Enable Vulkan GPU acceleration\n"
<< " --sample-every N Sample during training every N steps (default 50)\n"
<< " --temperature F Sampling temperature (default 0.8)\n"
<< " --top-p F Top-p sampling (default 0.9)\n"
<< " --max-tokens N Max tokens to generate (default 50)\n"
<< " --shuffle-buffer N Shuffle buffer size (default 10000)\n"
<< " --tt-rank N TT rank (default 64)\n"
<< " --proj-rank N Random projection rank (default 64)\n"
<< " --update-interval N Tokens between FLETTOHM updates (default 10000)\n"
<< " --num-experts N Number of MoE experts (default 6)\n"
<< " --window-size N Local window size (default 4096)\n"
<< " --help Show this help\n";
exit(0);
}
int main(int argc, char* argv[]) {
std::set_terminate([](){
std::cerr << "\n\033[31m[uzaLEAT FATAL] Unhandled exception (likely Vulkan OOM). Check VRAM!\033[0m\n";
std::exit(1);
});
uzaleat::CoreConfig config;
static struct option long_opts[] = {
{"plugin", required_argument, 0, 0},
{"model-so", required_argument, 0, 0},
{"train", no_argument, 0, 0},
{"chat", no_argument, 0, 0},
{"data", required_argument, 0, 0},
{"tokenizer", required_argument, 0, 0},
{"model", required_argument, 0, 0},
{"hidden", required_argument, 0, 0},
{"layers", required_argument, 0, 0},
{"context", required_argument, 0, 0},
{"epochs", required_argument, 0, 0},
{"lr", required_argument, 0, 0},
{"batch", required_argument, 0, 0},
{"threads", required_argument, 0, 0},
{"gpu", no_argument, 0, 0},
{"sample-every", required_argument, 0, 0},
{"temperature", required_argument, 0, 0},
{"top-p", required_argument, 0, 0},
{"max-tokens", required_argument, 0, 0},
{"shuffle-buffer", required_argument, 0, 0},
{"tt-rank", required_argument, 0, 0},
{"proj-rank", required_argument, 0, 0},
{"update-interval",required_argument, 0, 0},
{"num-experts", required_argument, 0, 0},
{"window-size", required_argument, 0, 0},
{"holdout-p", required_argument, 0, 0},
{"help", no_argument, 0, 'h'},
{0,0,0,0}
};
int c, option_index = 0;
while ((c = getopt_long(argc, argv, "h", long_opts, &option_index)) != -1) {
if (c == 'h') print_usage(argv[0]);
if (c != 0) continue;
const std::string opt = long_opts[option_index].name;
if (opt == "plugin") config.plugin_path = optarg;
else if (opt == "model-so") config.model_so_path = optarg;
else if (opt == "train") config.train_mode = true;
else if (opt == "chat") config.chat_mode = true;
else if (opt == "data") config.data_path = optarg;
else if (opt == "tokenizer") config.tokenizer_path = optarg;
else if (opt == "model") config.model_path = optarg;
else if (opt == "hidden") config.hidden_size = std::stoul(optarg);
else if (opt == "layers") config.num_layers = std::stoul(optarg);
else if (opt == "context") config.context_size = std::stoul(optarg);
else if (opt == "epochs") config.epochs = std::stoi(optarg);
else if (opt == "lr") config.learning_rate = std::stof(optarg);
else if (opt == "batch") config.batch_size = std::stoi(optarg);
else if (opt == "threads") config.num_threads = std::stoi(optarg);
else if (opt == "gpu") config.use_gpu = true;
else if (opt == "sample-every") config.sample_every = std::stoi(optarg);
else if (opt == "temperature") config.temperature = std::stof(optarg);
else if (opt == "top-p") config.top_p = std::stof(optarg);
else if (opt == "max-tokens") config.max_tokens_sample = std::stoi(optarg);
else if (opt == "shuffle-buffer") config.shuffle_buffer = std::stoi(optarg);
else if (opt == "tt-rank") config.tt_rank = std::stoi(optarg);
else if (opt == "proj-rank") config.proj_rank = std::stoi(optarg);
else if (opt == "update-interval")config.update_interval = std::stoi(optarg);
else if (opt == "num-experts") config.num_experts = std::stoi(optarg);
else if (opt == "window-size") config.window_size = std::stoi(optarg);
else if (opt == "holdout-p") config.holdout_percentage = std::stof(optarg);
else if (opt == "help") print_usage(argv[0]);
}
if (!config.train_mode && !config.chat_mode) {
std::cerr << "Error: specify --train or --chat\n";
print_usage(argv[0]);
}
if (config.plugin_path.empty() && config.model_so_path.empty()) {
std::cerr << "Error: need --plugin or --model-so\n";
print_usage(argv[0]);
}
#ifdef _OPENMP
omp_set_num_threads(config.num_threads);
#endif
uzaleat::UzaLEATCore core(config);
return core.run();
}