interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / x86 / model / reference_probe.c

27 lines · 1084 bytes Raw Blame History
1/* Independent upstream C reference, qualification only. Not linked into kernel. */
2#define main upstream_main
3#include CK_LLAMA_REFERENCE
4#undef main
5int main(int argc, char **argv) {
6 if (argc < 4) return 2;
7 Transformer t; build_transformer(&t, argv[1]);
8 unsigned count = strtoul(argv[2], NULL, 10), nt = argc > 4 ? argc - 4 : 1;
9 int token = argc > 4 ? atoi(argv[4]) : 1;
10 float *logits = NULL;
11 printf("REFERENCE_MODEL ids=");
12 unsigned generated = 0;
13 for (unsigned pos = 0; pos < count + nt - 1; pos++) {
14 logits = forward(&t, token, pos);
15 token = 0;
16 for (int i = 1; i < t.config.vocab_size; i++) if (logits[i] > logits[token]) token = i;
17 if (pos + 1 < nt) token = atoi(argv[5 + pos]);
18 else {
19 if (token == 1) break;
20 printf("%s%d", generated++ ? "," : "", token);
21 }
22 }
23 puts("");
24 FILE *f = fopen(argv[3], "wb");
25 if (!logits || !f || fwrite(logits, 4, t.config.vocab_size, f) != (size_t)t.config.vocab_size || fclose(f)) return 2;
26 free_transformer(&t); return 0;
27}