llama_cpp 0.21.2 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/ext/llama_cpp/llama_cpp.c +41 -353
- data/lib/llama_cpp/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9d289500d478dbaea942656eeaf4c076dd81fdcbf5fe670c323c5ce431945da
|
4
|
+
data.tar.gz: 5dff9d66db034b7f275add566e760adf84b10b578ff9a2fb32a684fd17735f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3109cee58c80d79ba90aa3ec33e0517c8bb54a1592ff4020ca18e16bf78c0bed5389ac1c5dd1221e757c87c8e3fb1af226c45d5b3d2a5b1ee6bc7afd13e242
|
7
|
+
data.tar.gz: 139cb66ec6cd2adbd2b178ad7f84581698905870bb549105f9683e14a80d04d8210405762e98937fed685352a4434d89f8fe43d8cbf500b1396d091c7d6366ba
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## [[0.22.1](https://github.com/yoshoku/llama_cpp.rb/compare/v0.22.0...v0.22.1)] - 2025-08-30
|
2
|
+
|
3
|
+
- Change supported llama.cpp version to b6310.
|
4
|
+
- Add `llama_adapter_meta_count` module function.
|
5
|
+
|
6
|
+
## [[0.22.0](https://github.com/yoshoku/llama_cpp.rb/compare/v0.21.2...v0.22.0)] - 2025-08-23
|
7
|
+
|
8
|
+
- Change supported llama.cpp version to b6240.
|
9
|
+
- Add `llama_state_seq_get_size_ext` module function.
|
10
|
+
- Add `LLAMA_STATE_SEQ_FLAGS_SWA_ONLY` constant.
|
11
|
+
- Remove `LlamaKvCache` class.
|
12
|
+
- Remove `llama_get_kv_self` module function.
|
13
|
+
- Remove ` llama_get_kv_self_clear` module function.
|
14
|
+
- Remove `llama_kv_self_seq_rm` module function.
|
15
|
+
- Remove `llama_kv_self_seq_cp` module function.
|
16
|
+
- Remove `llama_kv_self_seq_keep` module function.
|
17
|
+
- Remove `llama_kv_self_seq_add` module function.
|
18
|
+
- Remove `llama_kv_self_seq_div` module function.
|
19
|
+
- Remove `llama_kv_self_seq_pos_min` module function.
|
20
|
+
- Remove `llama_kv_self_seq_pos_max` module function.
|
21
|
+
- Remove `llama_kv_self_deflag` module function.
|
22
|
+
- Remove `llama_kv_self_can_shift?` module function.
|
23
|
+
- Remove `llama_kv_self_update` module function.
|
24
|
+
|
1
25
|
## [[0.21.2](https://github.com/yoshoku/llama_cpp.rb/compare/v0.21.1...v0.21.2)] - 2025-08-09
|
2
26
|
|
3
27
|
- Change supported llama.cpp version to b6100.
|
data/ext/llama_cpp/llama_cpp.c
CHANGED
@@ -11,7 +11,6 @@ VALUE rb_cLlamaModelQuantizeParams;
|
|
11
11
|
VALUE rb_cLlamaLogitBias;
|
12
12
|
VALUE rb_cLlamaAdapterLora;
|
13
13
|
VALUE rb_cLlamaMemoryT;
|
14
|
-
VALUE rb_cLlamaKvCache;
|
15
14
|
VALUE rb_cLlamaTokenDataArray;
|
16
15
|
VALUE rb_cLlamaBatch;
|
17
16
|
VALUE rb_cLlamaSampler;
|
@@ -1853,6 +1852,20 @@ static VALUE rb_llama_adapter_lora_init(VALUE self, VALUE model, VALUE path_lora
|
|
1853
1852
|
return TypedData_Wrap_Struct(rb_cLlamaAdapterLora, &llama_adapter_lora_wrapper_data_type, adapter_wrapper);
|
1854
1853
|
}
|
1855
1854
|
|
1855
|
+
/**
|
1856
|
+
* @overload llama_adapter_meta_count(adapter)
|
1857
|
+
* @param [LlamaAdapterLora] adapter
|
1858
|
+
* @return [Integer]
|
1859
|
+
*/
|
1860
|
+
static VALUE rb_llama_adapter_meta_count(VALUE self, VALUE adapter) {
|
1861
|
+
if (!rb_obj_is_kind_of(adapter, rb_cLlamaAdapterLora)) {
|
1862
|
+
rb_raise(rb_eArgError, "adapter must be a LlamaAdapterLora");
|
1863
|
+
return Qnil;
|
1864
|
+
}
|
1865
|
+
llama_adapter_lora_wrapper* adapter_wrapper = get_llama_adapter_lora_wrapper(adapter);
|
1866
|
+
return INT2NUM(llama_adapter_meta_count(adapter_wrapper->adapter));
|
1867
|
+
}
|
1868
|
+
|
1856
1869
|
/**
|
1857
1870
|
* @overload llama_set_adapter_lora(context, adapter, scale)
|
1858
1871
|
* @param [LlamaContext] context
|
@@ -2172,264 +2185,29 @@ static VALUE rb_llama_get_memory(VALUE self, VALUE ctx) {
|
|
2172
2185
|
return TypedData_Wrap_Struct(rb_cLlamaMemoryT, &llama_memory_t_wrapper_data_type, memory_wrapper);
|
2173
2186
|
}
|
2174
2187
|
|
2175
|
-
/* llama_kv_cache wrapper */
|
2176
|
-
typedef struct {
|
2177
|
-
struct llama_kv_cache* kv_cache;
|
2178
|
-
} llama_kv_cache_wrapper;
|
2179
|
-
|
2180
|
-
static void llama_kv_cache_wrapper_free(void *ptr) {
|
2181
|
-
if (ptr) {
|
2182
|
-
ruby_xfree(ptr);
|
2183
|
-
}
|
2184
|
-
}
|
2185
|
-
|
2186
|
-
static size_t llama_kv_cache_wrapper_size(const void *ptr) {
|
2187
|
-
return sizeof(*((llama_kv_cache_wrapper*)ptr));
|
2188
|
-
}
|
2189
|
-
|
2190
|
-
static rb_data_type_t llama_kv_cache_wrapper_data_type = {
|
2191
|
-
"LlamaKvCache",
|
2192
|
-
{ NULL,
|
2193
|
-
llama_kv_cache_wrapper_free,
|
2194
|
-
llama_kv_cache_wrapper_size },
|
2195
|
-
NULL,
|
2196
|
-
NULL,
|
2197
|
-
RUBY_TYPED_FREE_IMMEDIATELY
|
2198
|
-
};
|
2199
|
-
|
2200
|
-
static VALUE llama_kv_cache_wrapper_alloc(VALUE self) {
|
2201
|
-
llama_kv_cache_wrapper* data = (llama_kv_cache_wrapper*)ruby_xmalloc(sizeof(llama_kv_cache_wrapper));
|
2202
|
-
data->kv_cache = NULL;
|
2203
|
-
return TypedData_Wrap_Struct(self, &llama_kv_cache_wrapper_data_type, data);
|
2204
|
-
}
|
2205
|
-
|
2206
|
-
// static llama_kv_cache_wrapper* get_llama_kv_cache_wrapper(VALUE self) {
|
2207
|
-
// llama_kv_cache_wrapper* data = NULL;
|
2208
|
-
// TypedData_Get_Struct(self, llama_kv_cache_wrapper, &llama_kv_cache_wrapper_data_type, data);
|
2209
|
-
// return data;
|
2210
|
-
// }
|
2211
|
-
|
2212
|
-
/**
|
2213
|
-
* @overload llama_get_kv_self(context)
|
2214
|
-
* @param [LlamaContext] context
|
2215
|
-
* @return [LlamaKvCache]
|
2216
|
-
*/
|
2217
|
-
static VALUE rb_llama_get_kv_self(VALUE self, VALUE ctx) {
|
2218
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2219
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2220
|
-
return Qnil;
|
2221
|
-
}
|
2222
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2223
|
-
llama_kv_cache_wrapper* kv_cache_wrapper = (llama_kv_cache_wrapper*)ruby_xmalloc(sizeof(llama_kv_cache_wrapper));
|
2224
|
-
kv_cache_wrapper->kv_cache = llama_get_kv_self(context_wrapper->context);
|
2225
|
-
RB_GC_GUARD(ctx);
|
2226
|
-
return TypedData_Wrap_Struct(rb_cLlamaKvCache, &llama_kv_cache_wrapper_data_type, kv_cache_wrapper);
|
2227
|
-
}
|
2228
|
-
|
2229
|
-
/**
|
2230
|
-
* @overload llama_kv_self_clear(context)
|
2231
|
-
* @param [LlamaContext] context
|
2232
|
-
* @return [NilClass]
|
2233
|
-
*/
|
2234
|
-
static VALUE rb_llama_kv_self_clear(VALUE self, VALUE ctx) {
|
2235
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2236
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2237
|
-
return Qnil;
|
2238
|
-
}
|
2239
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2240
|
-
llama_kv_self_clear(context_wrapper->context);
|
2241
|
-
RB_GC_GUARD(ctx);
|
2242
|
-
return Qnil;
|
2243
|
-
}
|
2244
|
-
|
2245
|
-
/**
|
2246
|
-
* @overload llama_kv_self_seq_rm(context, seq_id, p0, p1)
|
2247
|
-
* @param [LlamaContext] context
|
2248
|
-
* @param [Integer] seq_id
|
2249
|
-
* @param [Integer] p0
|
2250
|
-
* @param [Integer] p1
|
2251
|
-
* @return [Boolean]
|
2252
|
-
*/
|
2253
|
-
static VALUE rb_llama_kv_self_seq_rm(VALUE self, VALUE ctx, VALUE seq_id, VALUE p0, VALUE p1) {
|
2254
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2255
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2256
|
-
return Qnil;
|
2257
|
-
}
|
2258
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2259
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2260
|
-
return Qnil;
|
2261
|
-
}
|
2262
|
-
if (!RB_INTEGER_TYPE_P(p0)) {
|
2263
|
-
rb_raise(rb_eArgError, "p0 must be an Integer");
|
2264
|
-
return Qnil;
|
2265
|
-
}
|
2266
|
-
if (!RB_INTEGER_TYPE_P(p1)) {
|
2267
|
-
rb_raise(rb_eArgError, "p1 must be an Integer");
|
2268
|
-
return Qnil;
|
2269
|
-
}
|
2270
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2271
|
-
const bool res = llama_kv_self_seq_rm(context_wrapper->context, NUM2INT(seq_id), NUM2INT(p0), NUM2INT(p1));
|
2272
|
-
RB_GC_GUARD(ctx);
|
2273
|
-
return res ? Qtrue : Qfalse;
|
2274
|
-
}
|
2275
|
-
|
2276
|
-
/**
|
2277
|
-
* @overload llama_kv_self_seq_cp(context, seq_id_src, seq_id_dst, p0, p1)
|
2278
|
-
* @param [LlamaContext] context
|
2279
|
-
* @param [Integer] seq_id_src
|
2280
|
-
* @param [Integer] seq_id_dst
|
2281
|
-
* @param [Integer] p0
|
2282
|
-
* @param [Integer] p1
|
2283
|
-
* @return [NilClass]
|
2284
|
-
*/
|
2285
|
-
static VALUE rb_llama_kv_self_seq_cp(VALUE self, VALUE ctx, VALUE seq_id_src, VALUE seq_id_dst, VALUE p0, VALUE p1) {
|
2286
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2287
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2288
|
-
return Qnil;
|
2289
|
-
}
|
2290
|
-
if (!RB_INTEGER_TYPE_P(seq_id_src)) {
|
2291
|
-
rb_raise(rb_eArgError, "seq_id_src must be an Integer");
|
2292
|
-
return Qnil;
|
2293
|
-
}
|
2294
|
-
if (!RB_INTEGER_TYPE_P(seq_id_dst)) {
|
2295
|
-
rb_raise(rb_eArgError, "seq_id_dst must be an Integer");
|
2296
|
-
return Qnil;
|
2297
|
-
}
|
2298
|
-
if (!RB_INTEGER_TYPE_P(p0)) {
|
2299
|
-
rb_raise(rb_eArgError, "p0 must be an Integer");
|
2300
|
-
return Qnil;
|
2301
|
-
}
|
2302
|
-
if (!RB_INTEGER_TYPE_P(p1)) {
|
2303
|
-
rb_raise(rb_eArgError, "p1 must be an Integer");
|
2304
|
-
return Qnil;
|
2305
|
-
}
|
2306
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2307
|
-
llama_kv_self_seq_cp(context_wrapper->context, NUM2INT(seq_id_src), NUM2INT(seq_id_dst), NUM2INT(p0), NUM2INT(p1));
|
2308
|
-
RB_GC_GUARD(ctx);
|
2309
|
-
return Qnil;
|
2310
|
-
}
|
2311
|
-
|
2312
|
-
/**
|
2313
|
-
* @overload llama_kv_self_seq_keep(context, seq_id)
|
2314
|
-
* @param [LlamaContext] context
|
2315
|
-
* @param [Integer] seq_id
|
2316
|
-
* @return [NilClass]
|
2317
|
-
*/
|
2318
|
-
static VALUE rb_llama_kv_self_seq_keep(VALUE self, VALUE ctx, VALUE seq_id) {
|
2319
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2320
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2321
|
-
return Qnil;
|
2322
|
-
}
|
2323
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2324
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2325
|
-
return Qnil;
|
2326
|
-
}
|
2327
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2328
|
-
llama_kv_self_seq_keep(context_wrapper->context, NUM2INT(seq_id));
|
2329
|
-
RB_GC_GUARD(ctx);
|
2330
|
-
return Qnil;
|
2331
|
-
}
|
2332
|
-
|
2333
|
-
/**
|
2334
|
-
* @overload llama_kv_self_seq_add(context, seq_id, p0, p1, delta)
|
2335
|
-
* @param [LlamaContext] context
|
2336
|
-
* @param [Integer] seq_id
|
2337
|
-
* @param [Integer] p0
|
2338
|
-
* @param [Integer] p1
|
2339
|
-
* @param [Integer] delta
|
2340
|
-
* @return [NilClass]
|
2341
|
-
*/
|
2342
|
-
static VALUE rb_llama_kv_self_seq_add(VALUE self, VALUE ctx, VALUE seq_id, VALUE p0, VALUE p1, VALUE delta) {
|
2343
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2344
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2345
|
-
return Qnil;
|
2346
|
-
}
|
2347
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2348
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2349
|
-
return Qnil;
|
2350
|
-
}
|
2351
|
-
if (!RB_INTEGER_TYPE_P(p0)) {
|
2352
|
-
rb_raise(rb_eArgError, "p0 must be an Integer");
|
2353
|
-
return Qnil;
|
2354
|
-
}
|
2355
|
-
if (!RB_INTEGER_TYPE_P(p1)) {
|
2356
|
-
rb_raise(rb_eArgError, "p1 must be an Integer");
|
2357
|
-
return Qnil;
|
2358
|
-
}
|
2359
|
-
if (!RB_INTEGER_TYPE_P(delta)) {
|
2360
|
-
rb_raise(rb_eArgError, "delta must be an Integer");
|
2361
|
-
return Qnil;
|
2362
|
-
}
|
2363
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2364
|
-
llama_kv_self_seq_add(context_wrapper->context, NUM2INT(seq_id), NUM2INT(p0), NUM2INT(p1), NUM2INT(delta));
|
2365
|
-
RB_GC_GUARD(ctx);
|
2366
|
-
return Qnil;
|
2367
|
-
}
|
2368
|
-
|
2369
2188
|
/**
|
2370
|
-
* @overload
|
2371
|
-
* @param [LlamaContext] context
|
2372
|
-
* @param [Integer] seq_id
|
2373
|
-
* @param [Integer] p0
|
2374
|
-
* @param [Integer] p1
|
2375
|
-
* @param [Integer] d
|
2376
|
-
* @return [NilClass]
|
2377
|
-
*/
|
2378
|
-
static VALUE rb_llama_kv_self_seq_div(VALUE self, VALUE ctx, VALUE seq_id, VALUE p0, VALUE p1, VALUE d) {
|
2379
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2380
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2381
|
-
return Qnil;
|
2382
|
-
}
|
2383
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2384
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2385
|
-
return Qnil;
|
2386
|
-
}
|
2387
|
-
if (!RB_INTEGER_TYPE_P(p0)) {
|
2388
|
-
rb_raise(rb_eArgError, "p0 must be an Integer");
|
2389
|
-
return Qnil;
|
2390
|
-
}
|
2391
|
-
if (!RB_INTEGER_TYPE_P(p1)) {
|
2392
|
-
rb_raise(rb_eArgError, "p1 must be an Integer");
|
2393
|
-
return Qnil;
|
2394
|
-
}
|
2395
|
-
if (!RB_INTEGER_TYPE_P(d)) {
|
2396
|
-
rb_raise(rb_eArgError, "d must be an Integer");
|
2397
|
-
return Qnil;
|
2398
|
-
}
|
2399
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2400
|
-
llama_kv_self_seq_div(context_wrapper->context, NUM2INT(seq_id), NUM2INT(p0), NUM2INT(p1), NUM2INT(d));
|
2401
|
-
RB_GC_GUARD(ctx);
|
2402
|
-
return Qnil;
|
2403
|
-
}
|
2404
|
-
|
2405
|
-
/**
|
2406
|
-
* @overload llama_kv_self_seq_pos_min(context, seq_id)
|
2189
|
+
* @overload llama_state_get_size(context)
|
2407
2190
|
* @param [LlamaContext] context
|
2408
|
-
* @param [Integer] seq_id
|
2409
2191
|
* @return [Integer]
|
2410
2192
|
*/
|
2411
|
-
static VALUE
|
2193
|
+
static VALUE rb_llama_state_get_size(VALUE self, VALUE ctx) {
|
2412
2194
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2413
2195
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2414
2196
|
return Qnil;
|
2415
2197
|
}
|
2416
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2417
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2418
|
-
return Qnil;
|
2419
|
-
}
|
2420
2198
|
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2421
|
-
const
|
2199
|
+
const size_t size = llama_state_get_size(context_wrapper->context);
|
2422
2200
|
RB_GC_GUARD(ctx);
|
2423
|
-
return
|
2201
|
+
return SIZET2NUM(size);
|
2424
2202
|
}
|
2425
2203
|
|
2426
2204
|
/**
|
2427
|
-
* @overload
|
2205
|
+
* @overload llama_state_seq_get_size(context, seq_id)
|
2428
2206
|
* @param [LlamaContext] context
|
2429
2207
|
* @param [Integer] seq_id
|
2430
2208
|
* @return [Integer]
|
2431
2209
|
*/
|
2432
|
-
static VALUE
|
2210
|
+
static VALUE rb_llama_state_seq_get_size(VALUE self, VALUE ctx, VALUE seq_id) {
|
2433
2211
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2434
2212
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2435
2213
|
return Qnil;
|
@@ -2439,82 +2217,19 @@ static VALUE rb_llama_kv_self_seq_pos_max(VALUE self, VALUE ctx, VALUE seq_id) {
|
|
2439
2217
|
return Qnil;
|
2440
2218
|
}
|
2441
2219
|
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2442
|
-
const
|
2443
|
-
RB_GC_GUARD(ctx);
|
2444
|
-
return INT2NUM(pos_max);
|
2445
|
-
}
|
2446
|
-
|
2447
|
-
/**
|
2448
|
-
* @overload llama_kv_self_defrag(context)
|
2449
|
-
* @param [LlamaContext] context
|
2450
|
-
* @return [NilClass]
|
2451
|
-
*/
|
2452
|
-
static VALUE rb_llama_kv_self_defrag(VALUE self, VALUE ctx) {
|
2453
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2454
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2455
|
-
return Qnil;
|
2456
|
-
}
|
2457
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2458
|
-
llama_kv_self_defrag(context_wrapper->context);
|
2459
|
-
RB_GC_GUARD(ctx);
|
2460
|
-
return Qnil;
|
2461
|
-
}
|
2462
|
-
|
2463
|
-
/**
|
2464
|
-
* @overload llama_kv_self_update(context)
|
2465
|
-
* @param [LlamaContext] context
|
2466
|
-
* @return [NilClass]
|
2467
|
-
*/
|
2468
|
-
static VALUE rb_llama_kv_self_update(VALUE self, VALUE ctx) {
|
2469
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2470
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2471
|
-
return Qnil;
|
2472
|
-
}
|
2473
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2474
|
-
llama_kv_self_update(context_wrapper->context);
|
2475
|
-
RB_GC_GUARD(ctx);
|
2476
|
-
return Qnil;
|
2477
|
-
}
|
2478
|
-
|
2479
|
-
/**
|
2480
|
-
* @overload llama_kv_self_can_shift?(context)
|
2481
|
-
* @param [LlamaContext] context
|
2482
|
-
* @return [Boolean]
|
2483
|
-
*/
|
2484
|
-
static VALUE rb_llama_kv_self_can_shift(VALUE self, VALUE ctx) {
|
2485
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2486
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2487
|
-
return Qnil;
|
2488
|
-
}
|
2489
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2490
|
-
const bool res = llama_kv_self_can_shift(context_wrapper->context);
|
2491
|
-
RB_GC_GUARD(ctx);
|
2492
|
-
return res ? Qtrue : Qfalse;
|
2493
|
-
}
|
2494
|
-
|
2495
|
-
/**
|
2496
|
-
* @overload llama_state_get_size(context)
|
2497
|
-
* @param [LlamaContext] context
|
2498
|
-
* @return [Integer]
|
2499
|
-
*/
|
2500
|
-
static VALUE rb_llama_state_get_size(VALUE self, VALUE ctx) {
|
2501
|
-
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2502
|
-
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2503
|
-
return Qnil;
|
2504
|
-
}
|
2505
|
-
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2506
|
-
const size_t size = llama_state_get_size(context_wrapper->context);
|
2220
|
+
const size_t size = llama_state_seq_get_size(context_wrapper->context, NUM2INT(seq_id));
|
2507
2221
|
RB_GC_GUARD(ctx);
|
2508
2222
|
return SIZET2NUM(size);
|
2509
2223
|
}
|
2510
2224
|
|
2511
2225
|
/**
|
2512
|
-
* @overload
|
2226
|
+
* @overload llama_state_seq_get_size_ext(context, seq_id, flags)
|
2513
2227
|
* @param [LlamaContext] context
|
2514
2228
|
* @param [Integer] seq_id
|
2229
|
+
* @param [Integer] flags
|
2515
2230
|
* @return [Integer]
|
2516
2231
|
*/
|
2517
|
-
static VALUE
|
2232
|
+
static VALUE rb_llama_state_seq_get_size_ext(VALUE self, VALUE ctx, VALUE seq_id, VALUE flags) {
|
2518
2233
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2519
2234
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2520
2235
|
return Qnil;
|
@@ -2523,8 +2238,12 @@ static VALUE rb_llama_state_seq_get_size(VALUE self, VALUE ctx, VALUE seq_id) {
|
|
2523
2238
|
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2524
2239
|
return Qnil;
|
2525
2240
|
}
|
2241
|
+
if (!RB_INTEGER_TYPE_P(flags)) {
|
2242
|
+
rb_raise(rb_eArgError, "flags must be an Integer");
|
2243
|
+
return Qnil;
|
2244
|
+
}
|
2526
2245
|
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2527
|
-
const size_t size =
|
2246
|
+
const size_t size = llama_state_seq_get_size_ext(context_wrapper->context, NUM2INT(seq_id), (uint32_t)NUM2UINT(flags));
|
2528
2247
|
RB_GC_GUARD(ctx);
|
2529
2248
|
return SIZET2NUM(size);
|
2530
2249
|
}
|
@@ -4187,6 +3906,7 @@ void Init_llama_cpp(void) {
|
|
4187
3906
|
rb_define_const(rb_mLlamaCpp, "LLAMA_DEFAULT_SEED", rb_str_new2(tmp));
|
4188
3907
|
|
4189
3908
|
rb_define_const(rb_mLlamaCpp, "LLAMA_TOKEN_NULL", INT2NUM(LLAMA_TOKEN_NULL));
|
3909
|
+
rb_define_const(rb_mLlamaCpp, "LLAMA_STATE_SEQ_FLAGS_SWA_ONLY", INT2NUM(LLAMA_STATE_SEQ_FLAGS_SWA_ONLY));
|
4190
3910
|
|
4191
3911
|
sprintf(tmp, "0x%x", LLAMA_FILE_MAGIC_GGLA);
|
4192
3912
|
rb_define_const(rb_mLlamaCpp, "LLAMA_FILE_MAGIC_GGLA", rb_str_new2(tmp));
|
@@ -5066,9 +4786,6 @@ void Init_llama_cpp(void) {
|
|
5066
4786
|
/* TODO: llama_get_model */
|
5067
4787
|
rb_define_module_function(rb_mLlamaCpp, "llama_get_model", rb_llama_get_model, 1);
|
5068
4788
|
|
5069
|
-
/* llama_get_kv_self */
|
5070
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_get_kv_self", rb_llama_get_kv_self, 1);
|
5071
|
-
|
5072
4789
|
/* llama_get_memory */
|
5073
4790
|
rb_define_module_function(rb_mLlamaCpp, "llama_get_memory", rb_llama_get_memory, 1);
|
5074
4791
|
|
@@ -5152,6 +4869,14 @@ void Init_llama_cpp(void) {
|
|
5152
4869
|
/* llama_adapter_lora_init */
|
5153
4870
|
rb_define_module_function(rb_mLlamaCpp, "llama_adapter_lora_init", rb_llama_adapter_lora_init, 2);
|
5154
4871
|
|
4872
|
+
/* TODO: llama_adapter_meta_val_str */
|
4873
|
+
|
4874
|
+
/* llama_adapter_meta_count */
|
4875
|
+
rb_define_module_function(rb_mLlamaCpp, "llama_adapter_meta_count", rb_llama_adapter_meta_count, 1);
|
4876
|
+
|
4877
|
+
/* TODO: llama_adapter_meta_key_by_index */
|
4878
|
+
/* TODO: llama_adapter_meta_val_str_by_index */
|
4879
|
+
|
5155
4880
|
/* llama_set_adapter_lora */
|
5156
4881
|
rb_define_module_function(rb_mLlamaCpp, "llama_set_adapter_lora", rb_llama_set_adapter_lora, 3);
|
5157
4882
|
|
@@ -5200,46 +4925,6 @@ void Init_llama_cpp(void) {
|
|
5200
4925
|
/* llama_memory_can_shift */
|
5201
4926
|
rb_define_module_function(rb_mLlamaCpp, "llama_memory_can_shift?", rb_llama_memory_can_shift, 1);
|
5202
4927
|
|
5203
|
-
/**
|
5204
|
-
* Document-class: LlamaCpp::LlamaKvCache
|
5205
|
-
* "struct llama_kv_cache" wrapper class
|
5206
|
-
*/
|
5207
|
-
rb_cLlamaKvCache = rb_define_class_under(rb_mLlamaCpp, "LlamaKvCache", rb_cObject);
|
5208
|
-
rb_define_alloc_func(rb_cLlamaKvCache, llama_kv_cache_wrapper_alloc);
|
5209
|
-
|
5210
|
-
/* llama_kv_self_clear */
|
5211
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_clear", rb_llama_kv_self_clear, 1);
|
5212
|
-
|
5213
|
-
/* llama_kv_self_seq_rm */
|
5214
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_rm", rb_llama_kv_self_seq_rm, 4);
|
5215
|
-
|
5216
|
-
/* llama_kv_self_seq_cp */
|
5217
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_cp", rb_llama_kv_self_seq_cp, 5);
|
5218
|
-
|
5219
|
-
/* llama_kv_self_seq_keep */
|
5220
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_keep", rb_llama_kv_self_seq_keep, 2);
|
5221
|
-
|
5222
|
-
/* llama_kv_self_seq_add */
|
5223
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_add", rb_llama_kv_self_seq_add, 5);
|
5224
|
-
|
5225
|
-
/* llama_kv_self_seq_div */
|
5226
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_div", rb_llama_kv_self_seq_div, 5);
|
5227
|
-
|
5228
|
-
/* llama_kv_self_seq_pos_min */
|
5229
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_pos_min", rb_llama_kv_self_seq_pos_min, 2);
|
5230
|
-
|
5231
|
-
/* llama_kv_self_seq_pos_max */
|
5232
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_pos_max", rb_llama_kv_self_seq_pos_max, 2);
|
5233
|
-
|
5234
|
-
/* llama_kv_self_defrag */
|
5235
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_defrag", rb_llama_kv_self_defrag, 1);
|
5236
|
-
|
5237
|
-
/* llama_kv_self_update */
|
5238
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_update", rb_llama_kv_self_update, 1);
|
5239
|
-
|
5240
|
-
/* llama_kv_self_can_shift */
|
5241
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_can_shift?", rb_llama_kv_self_can_shift, 1);
|
5242
|
-
|
5243
4928
|
/* llama_state_get_size */
|
5244
4929
|
rb_define_module_function(rb_mLlamaCpp, "llama_state_get_size", rb_llama_state_get_size, 1);
|
5245
4930
|
|
@@ -5255,6 +4940,9 @@ void Init_llama_cpp(void) {
|
|
5255
4940
|
/* TODO: llama_state_seq_set_data */
|
5256
4941
|
/* TODO: llama_state_seq_save_file */
|
5257
4942
|
/* TODO: llama_state_seq_load_file */
|
4943
|
+
rb_define_module_function(rb_mLlamaCpp, "llama_state_seq_get_size_ext", rb_llama_state_seq_get_size_ext, 3);
|
4944
|
+
/* TODO: llama_state_seq_get_data_ext */
|
4945
|
+
/* TODO: llama_state_seq_set_data_ext */
|
5258
4946
|
|
5259
4947
|
/* llama_batch_get_one */
|
5260
4948
|
rb_define_module_function(rb_mLlamaCpp, "llama_batch_get_one", rb_llama_batch_get_one, 1);
|
data/lib/llama_cpp/version.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# llama_cpp.rb provides Ruby bindings for the llama.cpp.
|
4
4
|
module LlamaCpp
|
5
5
|
# The version of llama_cpp.rb you install.
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.22.1'
|
7
7
|
|
8
8
|
# The supported version of llama.cpp.
|
9
|
-
LLAMA_CPP_VERSION = '
|
9
|
+
LLAMA_CPP_VERSION = 'b6310'
|
10
10
|
end
|