llama_cpp 0.21.2 → 0.22.0
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 +19 -0
- data/ext/llama_cpp/llama_cpp.c +19 -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: 44ea7eb462df4d37cd20d802e5f305d4ff05b605e3d442ca966458714a57881b
|
4
|
+
data.tar.gz: f3e73839dda61b43efd71c0d325384b78c6b47fc8535ab62d25a54c66aa6d09f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2060e02b8bb154b5d34c242b54f331b840cc5e3f46bce6bcc307b52de4e6eb2613a5e725154b51c9e272576c00d004f72827acb035f62c280862fae94a9f5a5
|
7
|
+
data.tar.gz: 43a110ce026562b17b6f7da9b9bd013be7671bf457c3ddb84a3de362333a7b7f665031577755c7de984e0e84da39f1c474f96dc830040fa08185b5b405169697
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
## [[0.22.0](https://github.com/yoshoku/llama_cpp.rb/compare/v0.21.2...v0.22.0)] - 2025-08-23
|
2
|
+
|
3
|
+
- Change supported llama.cpp version to b6240.
|
4
|
+
- Add `llama_state_seq_get_size_ext` module function.
|
5
|
+
- Add `LLAMA_STATE_SEQ_FLAGS_SWA_ONLY` constant.
|
6
|
+
- Remove `LlamaKvCache` class.
|
7
|
+
- Remove `llama_get_kv_self` module function.
|
8
|
+
- Remove ` llama_get_kv_self_clear` module function.
|
9
|
+
- Remove `llama_kv_self_seq_rm` module function.
|
10
|
+
- Remove `llama_kv_self_seq_cp` module function.
|
11
|
+
- Remove `llama_kv_self_seq_keep` module function.
|
12
|
+
- Remove `llama_kv_self_seq_add` module function.
|
13
|
+
- Remove `llama_kv_self_seq_div` module function.
|
14
|
+
- Remove `llama_kv_self_seq_pos_min` module function.
|
15
|
+
- Remove `llama_kv_self_seq_pos_max` module function.
|
16
|
+
- Remove `llama_kv_self_deflag` module function.
|
17
|
+
- Remove `llama_kv_self_can_shift?` module function.
|
18
|
+
- Remove `llama_kv_self_update` module function.
|
19
|
+
|
1
20
|
## [[0.21.2](https://github.com/yoshoku/llama_cpp.rb/compare/v0.21.1...v0.21.2)] - 2025-08-09
|
2
21
|
|
3
22
|
- 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;
|
@@ -2172,264 +2171,29 @@ static VALUE rb_llama_get_memory(VALUE self, VALUE ctx) {
|
|
2172
2171
|
return TypedData_Wrap_Struct(rb_cLlamaMemoryT, &llama_memory_t_wrapper_data_type, memory_wrapper);
|
2173
2172
|
}
|
2174
2173
|
|
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
|
-
/**
|
2370
|
-
* @overload llama_kv_self_seq_div(context, seq_id, p0, p1, d)
|
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
2174
|
/**
|
2406
|
-
* @overload
|
2175
|
+
* @overload llama_state_get_size(context)
|
2407
2176
|
* @param [LlamaContext] context
|
2408
|
-
* @param [Integer] seq_id
|
2409
2177
|
* @return [Integer]
|
2410
2178
|
*/
|
2411
|
-
static VALUE
|
2179
|
+
static VALUE rb_llama_state_get_size(VALUE self, VALUE ctx) {
|
2412
2180
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2413
2181
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2414
2182
|
return Qnil;
|
2415
2183
|
}
|
2416
|
-
if (!RB_INTEGER_TYPE_P(seq_id)) {
|
2417
|
-
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2418
|
-
return Qnil;
|
2419
|
-
}
|
2420
2184
|
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2421
|
-
const
|
2185
|
+
const size_t size = llama_state_get_size(context_wrapper->context);
|
2422
2186
|
RB_GC_GUARD(ctx);
|
2423
|
-
return
|
2187
|
+
return SIZET2NUM(size);
|
2424
2188
|
}
|
2425
2189
|
|
2426
2190
|
/**
|
2427
|
-
* @overload
|
2191
|
+
* @overload llama_state_seq_get_size(context, seq_id)
|
2428
2192
|
* @param [LlamaContext] context
|
2429
2193
|
* @param [Integer] seq_id
|
2430
2194
|
* @return [Integer]
|
2431
2195
|
*/
|
2432
|
-
static VALUE
|
2196
|
+
static VALUE rb_llama_state_seq_get_size(VALUE self, VALUE ctx, VALUE seq_id) {
|
2433
2197
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2434
2198
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2435
2199
|
return Qnil;
|
@@ -2439,82 +2203,19 @@ static VALUE rb_llama_kv_self_seq_pos_max(VALUE self, VALUE ctx, VALUE seq_id) {
|
|
2439
2203
|
return Qnil;
|
2440
2204
|
}
|
2441
2205
|
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);
|
2206
|
+
const size_t size = llama_state_seq_get_size(context_wrapper->context, NUM2INT(seq_id));
|
2507
2207
|
RB_GC_GUARD(ctx);
|
2508
2208
|
return SIZET2NUM(size);
|
2509
2209
|
}
|
2510
2210
|
|
2511
2211
|
/**
|
2512
|
-
* @overload
|
2212
|
+
* @overload llama_state_seq_get_size_ext(context, seq_id, flags)
|
2513
2213
|
* @param [LlamaContext] context
|
2514
2214
|
* @param [Integer] seq_id
|
2215
|
+
* @param [Integer] flags
|
2515
2216
|
* @return [Integer]
|
2516
2217
|
*/
|
2517
|
-
static VALUE
|
2218
|
+
static VALUE rb_llama_state_seq_get_size_ext(VALUE self, VALUE ctx, VALUE seq_id, VALUE flags) {
|
2518
2219
|
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
|
2519
2220
|
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
|
2520
2221
|
return Qnil;
|
@@ -2523,8 +2224,12 @@ static VALUE rb_llama_state_seq_get_size(VALUE self, VALUE ctx, VALUE seq_id) {
|
|
2523
2224
|
rb_raise(rb_eArgError, "seq_id must be an Integer");
|
2524
2225
|
return Qnil;
|
2525
2226
|
}
|
2227
|
+
if (!RB_INTEGER_TYPE_P(flags)) {
|
2228
|
+
rb_raise(rb_eArgError, "flags must be an Integer");
|
2229
|
+
return Qnil;
|
2230
|
+
}
|
2526
2231
|
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
|
2527
|
-
const size_t size =
|
2232
|
+
const size_t size = llama_state_seq_get_size_ext(context_wrapper->context, NUM2INT(seq_id), (uint32_t)NUM2UINT(flags));
|
2528
2233
|
RB_GC_GUARD(ctx);
|
2529
2234
|
return SIZET2NUM(size);
|
2530
2235
|
}
|
@@ -4187,6 +3892,7 @@ void Init_llama_cpp(void) {
|
|
4187
3892
|
rb_define_const(rb_mLlamaCpp, "LLAMA_DEFAULT_SEED", rb_str_new2(tmp));
|
4188
3893
|
|
4189
3894
|
rb_define_const(rb_mLlamaCpp, "LLAMA_TOKEN_NULL", INT2NUM(LLAMA_TOKEN_NULL));
|
3895
|
+
rb_define_const(rb_mLlamaCpp, "LLAMA_STATE_SEQ_FLAGS_SWA_ONLY", INT2NUM(LLAMA_STATE_SEQ_FLAGS_SWA_ONLY));
|
4190
3896
|
|
4191
3897
|
sprintf(tmp, "0x%x", LLAMA_FILE_MAGIC_GGLA);
|
4192
3898
|
rb_define_const(rb_mLlamaCpp, "LLAMA_FILE_MAGIC_GGLA", rb_str_new2(tmp));
|
@@ -5066,9 +4772,6 @@ void Init_llama_cpp(void) {
|
|
5066
4772
|
/* TODO: llama_get_model */
|
5067
4773
|
rb_define_module_function(rb_mLlamaCpp, "llama_get_model", rb_llama_get_model, 1);
|
5068
4774
|
|
5069
|
-
/* llama_get_kv_self */
|
5070
|
-
rb_define_module_function(rb_mLlamaCpp, "llama_get_kv_self", rb_llama_get_kv_self, 1);
|
5071
|
-
|
5072
4775
|
/* llama_get_memory */
|
5073
4776
|
rb_define_module_function(rb_mLlamaCpp, "llama_get_memory", rb_llama_get_memory, 1);
|
5074
4777
|
|
@@ -5200,46 +4903,6 @@ void Init_llama_cpp(void) {
|
|
5200
4903
|
/* llama_memory_can_shift */
|
5201
4904
|
rb_define_module_function(rb_mLlamaCpp, "llama_memory_can_shift?", rb_llama_memory_can_shift, 1);
|
5202
4905
|
|
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
4906
|
/* llama_state_get_size */
|
5244
4907
|
rb_define_module_function(rb_mLlamaCpp, "llama_state_get_size", rb_llama_state_get_size, 1);
|
5245
4908
|
|
@@ -5255,6 +4918,9 @@ void Init_llama_cpp(void) {
|
|
5255
4918
|
/* TODO: llama_state_seq_set_data */
|
5256
4919
|
/* TODO: llama_state_seq_save_file */
|
5257
4920
|
/* TODO: llama_state_seq_load_file */
|
4921
|
+
rb_define_module_function(rb_mLlamaCpp, "llama_state_seq_get_size_ext", rb_llama_state_seq_get_size_ext, 3);
|
4922
|
+
/* TODO: llama_state_seq_get_data_ext */
|
4923
|
+
/* TODO: llama_state_seq_set_data_ext */
|
5258
4924
|
|
5259
4925
|
/* llama_batch_get_one */
|
5260
4926
|
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.0'
|
7
7
|
|
8
8
|
# The supported version of llama.cpp.
|
9
|
-
LLAMA_CPP_VERSION = '
|
9
|
+
LLAMA_CPP_VERSION = 'b6240'
|
10
10
|
end
|