aboutsummaryrefslogtreecommitdiff
path: root/liblangdet/safetensors.h
blob: 99f1cfb54c1c85487293809a41c315061b4e9252 (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
#ifndef SAFETENSORS_H
#define SAFETENSORS_H

#include <stddef.h>
#include <stdint.h>

#define SAFETENSORS_MAX_TENSORS 1024

/* Unused checkpoint entries may have non-F32 dtypes. */
typedef enum {
    DTYPE_F32 = 0,
    DTYPE_UNKNOWN = -1
} safetensor_dtype_t;

typedef struct {
    char name[256];
    safetensor_dtype_t dtype;
    int ndim;
    int64_t shape[8];
    size_t data_offset;
    size_t data_size;
} safetensor_t;

typedef struct {
    void *data;
    size_t file_size;
    size_t header_size;
    int num_tensors;
    safetensor_t tensors[SAFETENSORS_MAX_TENSORS];
} safetensors_file_t;

/* Open a single safetensors file (memory-mapped) */
safetensors_file_t *safetensors_open(const char *path);
void safetensors_close(safetensors_file_t *sf);

const safetensor_t *safetensors_find(const safetensors_file_t *sf, const char *name);

/* Get raw pointer to tensor data (within mmap'd region) */
const void *safetensors_data(const safetensors_file_t *sf, const safetensor_t *t);

#endif /* SAFETENSORS_H */