Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

1.4 KB
Raw Blame
#include <stdio.h>
#include <string.h>
#include "../bpf/ebpf_jev_common.h"
#define JEV_WEIGHTS_STRUCT_DEFINED
#include "ebpf_jev_weights.h"
#include "parity_vectors.h"

int main(int argc, char **argv) {
    if (argc != 2) return 2;
    FILE *f = fopen(argv[1], "rb");
    static struct jev_model_weights w;
    if (!f || fread(&w, sizeof(w), 1, f) != 1 || fgetc(f) != EOF) return 2;
    fclose(f);
    if (memcmp(&w, &jev_weights, sizeof(w))) return 1;
    for (int n = 0; n < JEV_PARITY_COUNT; n++) {
        const struct jev_vector *v = &jev_vectors[n];
        struct jev_scratch s = {};
        struct jev_math c = {&s, &w};
        memcpy(s.name, v->name, sizeof(s.name));
        for (int i = 0; i < 62 && !jev_gram(i, &c); i++) {}
        memcpy(s.in, v->x, 16);
        for (int i = 0; i < 16; i++) s.in[16+i] = clamp_byte(s.sums[i] >> w.emb_shift);
        memcpy(s.in+32, v->h, 32);
        for (int i = 0; i < 64; i++) jev_hidden(i, &c);
        for (int i = 0; i < 4; i++) {
            jev_head(i, &c);
            int sum = w.b2[i];
            for (int j = 0; j < 64; j++) sum += w.W2[i][j] * s.hidden[j];
            if (clamp_byte(sum >> w.shift2) != v->logit[i]) return 1;
        }
        if (memcmp(s.in, v->x, 32) || memcmp(s.hidden, v->h_next, 32) ||
            memcmp(s.scores, v->scores, 4)) {
            fprintf(stderr, "Mismatch at vector %d\n", n);
            return 1;
        }
    }
    puts("500/500 native C vectors matched");
    return 0;
}