@@ -107,8 +107,8 @@ class ExitCtl extends ControlMessage {
107
107
108
108
class LoadModelCtl extends ControlMessage {
109
109
final String path;
110
- final ContextParams ctxParams ;
111
- LoadModelCtl (this .path, this .ctxParams );
110
+ final ContextParams params ;
111
+ LoadModelCtl (this .path, this .params );
112
112
113
113
LoadModelResp done (Model model) => LoadModelResp (id, model: model);
114
114
@@ -219,9 +219,8 @@ class _Allocations<E> {
219
219
}
220
220
}
221
221
222
- // key: rawModelPointer
223
222
final _modelAllocs = _Allocations <int >();
224
- final _ctxAllocs = _Allocations <int >();
223
+ // final _ctxAllocs = _Allocations<int>();
225
224
226
225
late final SendPort _log;
227
226
late final SendPort _response;
@@ -259,34 +258,33 @@ void _onControl(ControlMessage ctl) {
259
258
260
259
case LoadModelCtl ():
261
260
final Set <Pointer > allocs = {};
262
- final pd = ctl.ctxParams;
263
- final pc = libllama. llama_context_default_params ().. setSimpleFrom (pd );
261
+ final params = libllama. llama_context_default_params ()
262
+ .. setSimpleFrom (ctl.params );
264
263
265
264
// TODO: can't do this until we track contexts to manage memory allocation
266
265
// pc.tensor_split
267
266
268
- pc .progress_callback = Pointer .fromFunction (_onModelLoadProgress);
267
+ params .progress_callback = Pointer .fromFunction (_onModelLoadProgress);
269
268
final idPointer = calloc.allocate <Uint32 >(sizeOf <Uint32 >());
270
269
allocs.add (idPointer);
271
270
idPointer.value = ctl.id;
272
- pc .progress_callback_user_data = idPointer.cast <Void >();
271
+ params .progress_callback_user_data = idPointer.cast <Void >();
273
272
274
- final rawModelPointer = libllama
273
+ final rawModel = libllama
275
274
.llama_load_model_from_file (
276
275
ctl.path.toNativeUtf8 ().cast <Char >(),
277
- pc ,
276
+ params ,
278
277
)
279
278
.address;
280
279
281
- if (rawModelPointer == 0 ) {
282
- _response.send (ctl.error (
283
- Exception ("failed loading model: ${ctl .path }" ),
284
- ));
280
+ if (rawModel == 0 ) {
281
+ _response
282
+ .send (ctl.error (Exception ("failed loading model: ${ctl .path }" )));
285
283
return ;
286
284
}
287
285
288
- _modelAllocs[rawModelPointer ] = allocs;
289
- _response.send (ctl.done (Model ._(rawModelPointer )));
286
+ _modelAllocs[rawModel ] = allocs;
287
+ _response.send (ctl.done (Model ._(rawModel )));
290
288
291
289
case FreeModelCtl ():
292
290
assert (ctl.model._rawPointer != 0 );
@@ -300,7 +298,19 @@ void _onControl(ControlMessage ctl) {
300
298
301
299
case NewContextCtl ():
302
300
assert (ctl.model._rawPointer != 0 );
303
- // libllama.llama_new_context_with_model(model, params)
301
+ final params = libllama.llama_context_default_params ()
302
+ ..setSimpleFrom (ctl.params);
303
+
304
+ final rawCtx = libllama
305
+ .llama_new_context_with_model (ctl.model._ffiPointer, params)
306
+ .address;
307
+
308
+ if (rawCtx == 0 ) {
309
+ _response.send (ctl.error (Exception ("failed creating context" )));
310
+ return ;
311
+ }
312
+
313
+ _response.send (ctl.done (Context ._(rawCtx)));
304
314
305
315
case FreeContextCtl ():
306
316
}
0 commit comments