9
9
c_int32 ,
10
10
c_uint8 ,
11
11
c_uint32 ,
12
+ c_int64 ,
12
13
c_size_t ,
13
14
c_float ,
14
15
c_double ,
15
16
c_void_p ,
16
17
POINTER ,
17
18
_Pointer , # type: ignore
18
19
Structure ,
20
+ Union as CtypesUnion ,
19
21
Array ,
20
22
)
21
23
import pathlib
@@ -317,12 +319,9 @@ class llama_batch(Structure):
317
319
# LLAMA_KV_OVERRIDE_FLOAT,
318
320
# LLAMA_KV_OVERRIDE_BOOL,
319
321
# };
320
- class llama_model_kv_override_type (Structure ):
321
- _fields_ = [
322
- ("LLAMA_KV_OVERRIDE_INT" , c_int ),
323
- ("LLAMA_KV_OVERRIDE_FLOAT" , c_int ),
324
- ("LLAMA_KV_OVERRIDE_BOOL" , c_int ),
325
- ]
322
+ LLAMA_KV_OVERRIDE_INT = 0
323
+ LLAMA_KV_OVERRIDE_FLOAT = 1
324
+ LLAMA_KV_OVERRIDE_BOOL = 2
326
325
327
326
# struct llama_model_kv_override {
328
327
# char key[128];
@@ -333,15 +332,20 @@ class llama_model_kv_override_type(Structure):
333
332
# bool bool_value;
334
333
# };
335
334
# };
336
- class llama_model_kv_override ( Structure ):
335
+ class llama_model_kv_override_value ( CtypesUnion ):
337
336
_fields_ = [
338
- ("key" , ctypes .c_char * 128 ),
339
- ("tag" , llama_model_kv_override_type ),
340
- ("int_value" , ctypes .c_int64 ),
337
+ ("int_value" , c_int64 ),
341
338
("float_value" , c_double ),
342
339
("bool_value" , c_bool ),
343
340
]
344
341
342
+ class llama_model_kv_override (Structure ):
343
+ _fields_ = [
344
+ ("key" , ctypes .c_char * 128 ),
345
+ ("tag" , c_int ),
346
+ ("value" , llama_model_kv_override_value ),
347
+ ]
348
+
345
349
# struct llama_model_params {
346
350
# int32_t n_gpu_layers; // number of layers to store in VRAM
347
351
# int32_t main_gpu; // the GPU that is used for scratch and small tensors
0 commit comments