aboutsummaryrefslogtreecommitdiff
path: root/liblangdet/model_types.h
blob: aa46d39977e9bb34830847c9fc01244545010d98 (plain) (blame)
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
#ifndef LANGDET_MODEL_TYPES_H
#define LANGDET_MODEL_TYPES_H

#include "encoder.h"
#include "safetensors.h"

typedef struct {
    const float *wq;
    const float *wk;
    const float *wv;
    const float *wo;
    const float *q_bias;
    const float *k_bias;
    const float *v_bias;
    const float *o_bias;
    const float *input_norm;
    const float *attn_ln_bias;
    const float *up_proj;
    const float *ffn_inter_bias;
    const float *down_proj;
    const float *ffn_out_bias;
    const float *post_attn_norm;
    const float *ffn_ln_bias;
} langdet_layer_t;

typedef struct {
    const float *embed_tokens;
    langdet_layer_t *layers;
    const float *position_embeddings;
    const float *token_type_embeddings;
    const float *langdet_ln_w;
    const float *langdet_ln_b;
} langdet_weights_t;

struct langdet_model {
    langdet_config_t config;
    langdet_weights_t weights;
    /* All weight pointers borrow this mapping until model teardown. */
    safetensors_file_t *safetensors;
};

struct langdet_workspace {
    const langdet_model_t *model;
    int buf_seq_cap;
    float *x;
    float *q;
    float *k;
    float *v;
    float *attn_out;
    float *proj_out;
    float *ffn_up;
    float *attn_scores;
    size_t attn_scores_bytes;
};

#endif /* LANGDET_MODEL_TYPES_H */