-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_generation.c
More file actions
49 lines (44 loc) · 1.47 KB
/
test_generation.c
File metadata and controls
49 lines (44 loc) · 1.47 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
#include "Core_CPP/niyah_core.h"
#include <stdio.h>
#include <stdlib.h>
int main() {
NiyahConfig cfg = {
.magic = NIYAH_MAGIC,
.version = NIYAH_VER,
.vocab_size = 32000,
.ctx_len = 512,
.embed_dim = 128,
.n_layers = 4,
.n_heads = 8,
.n_kv_heads = 8,
.ffn_mult = 4, /* ffn_hidden = embed_dim * ffn_mult = 512 */
.rope_theta = 10000.0f,
.rms_eps = 1e-5f,
.flags = 0
};
NiyahModel *model = niyah_alloc(&cfg);
if (!model) {
fprintf(stderr, "ERROR: niyah_alloc failed\n");
return 1;
}
printf("SIMD backend : %s\n", niyah_simd_name());
printf("Total params : %zu\n", niyah_param_count(model));
printf("embed_dim : %u\n", model->cfg.embed_dim);
printf("n_layers : %u\n", model->cfg.n_layers);
printf("head_dim : %u\n", model->head_dim);
printf("ffn_dim : %u\n\n", model->ffn_dim);
/* توليد 10 رموز عشوائية */
uint32_t token = 0; /* <BOS> */
for (int pos = 0; pos < 10; pos++) {
float *logits = niyah_forward(model, token, pos);
uint32_t next = 0;
float mx = logits[0];
for (uint32_t i = 1; i < cfg.vocab_size; i++) {
if (logits[i] > mx) { mx = logits[i]; next = i; }
}
printf("pos %2d: token %-6u logit_max = %.4f\n", pos, next, mx);
token = next;
}
niyah_free(model);
return 0;
}