diff --git a/CHANGELOG.md b/CHANGELOG.md index e09024cbf..312fccc70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## Unreleased + +- A negative `ModelParams.gpuLayers` now means all layers on every runtime, + as in llama.cpp, exactly like `ModelParams.maxGpuLayers`. Native llama.cpp + now also offloads the KV cache and reports the GPU backend instead of + `CPU`, LiteRT-LM under `ComputeDevice.auto` uses its GPU backend instead + of the CPU, and the Web applies its GPU safety caps and CPU fallback + ([#920](https://github.com/leehack/llamadart/issues/920)). + ## 0.13.0 - Pair this release with Apple companions `llamadart_llama_cpp_flutter`, diff --git a/lib/src/backends/litert_lm/litert_lm_backend_web.dart b/lib/src/backends/litert_lm/litert_lm_backend_web.dart index e3814705d..6651986b8 100644 --- a/lib/src/backends/litert_lm/litert_lm_backend_web.dart +++ b/lib/src/backends/litert_lm/litert_lm_backend_web.dart @@ -19,6 +19,7 @@ import '../../core/models/config/gpu_backend.dart'; import '../../core/models/config/kv_cache_type.dart'; import '../../core/models/config/log_level.dart'; import '../../core/models/inference/generation_params.dart'; +import '../../core/models/inference/gpu_layer_count.dart'; import '../../core/models/inference/model_params.dart'; import '../../core/models/model_format.dart'; import '../../core/url_redaction.dart'; @@ -1267,7 +1268,7 @@ class LiteRtLmBackend } return explicit; } - if (params.gpuLayers <= 0) { + if (resolveGpuLayerCount(params.gpuLayers) == 0) { return 'cpu'; } return _backendNameForGpuPreference(params.preferredBackend); @@ -1308,7 +1309,7 @@ class LiteRtLmBackend if (explicit != null) { return explicit; } - if (params.gpuLayers <= 0) { + if (resolveGpuLayerCount(params.gpuLayers) == 0) { return 'cpu'; } if (params.preferredBackend != GpuBackend.auto) { diff --git a/lib/src/backends/litert_lm/litert_lm_service.dart b/lib/src/backends/litert_lm/litert_lm_service.dart index 9dd45524e..980ad5065 100644 --- a/lib/src/backends/litert_lm/litert_lm_service.dart +++ b/lib/src/backends/litert_lm/litert_lm_service.dart @@ -15,6 +15,7 @@ import '../../core/models/config/gpu_backend.dart'; import '../../core/models/config/kv_cache_type.dart'; import '../../core/models/config/log_level.dart'; import '../../core/models/inference/generation_params.dart'; +import '../../core/models/inference/gpu_layer_count.dart'; import '../../core/models/inference/model_params.dart'; import '../../core/models/inference/tool_choice.dart'; import '../../core/models/model_format.dart'; @@ -1357,7 +1358,7 @@ class LiteRtLmService { if (explicit != null) { return explicit; } - if (params.gpuLayers <= 0) { + if (resolveGpuLayerCount(params.gpuLayers) == 0) { return liteRtLmCpuBackend; } return _backendNameForGpuPreference(params.preferredBackend); @@ -1481,7 +1482,7 @@ class LiteRtLmService { if (explicit != null) { return explicit; } - if (params.gpuLayers <= 0) { + if (resolveGpuLayerCount(params.gpuLayers) == 0) { return liteRtLmCpuBackend; } if (params.preferredBackend != GpuBackend.auto) { diff --git a/lib/src/backends/llama_cpp/llama_cpp_service.dart b/lib/src/backends/llama_cpp/llama_cpp_service.dart index c59b8e167..2fd90bcd4 100644 --- a/lib/src/backends/llama_cpp/llama_cpp_service.dart +++ b/lib/src/backends/llama_cpp/llama_cpp_service.dart @@ -23,6 +23,7 @@ import '../../core/models/config/gpu_device_info.dart'; import '../../core/models/config/log_level.dart'; import '../../core/models/diagnostics/model_file_type.dart'; import '../../core/models/inference/generation_params.dart'; +import '../../core/models/inference/gpu_layer_count.dart'; import '../../core/template/media_placeholders.dart'; import '../../core/models/inference/model_params.dart'; import '../../core/models/inference/next_token_scores.dart'; @@ -857,7 +858,10 @@ class LlamaCppService { /// Resolves the effective GPU layer count for model loading. /// - /// CPU backend preference always forces zero offloaded layers. + /// CPU backend preference always forces zero offloaded layers, and a + /// negative [ModelParams.gpuLayers] resolves to [ModelParams.maxGpuLayers]: + /// llama.cpp offloads every layer for it, so the context offload, backend + /// name and reported layer count must treat it as a GPU load. static int resolveGpuLayersForLoad( ModelParams modelParams, { bool isAndroid = false, @@ -870,7 +874,7 @@ class LlamaCppService { ) == GpuBackend.cpu ? 0 - : modelParams.gpuLayers; + : resolveGpuLayerCount(modelParams.gpuLayers); } /// The warning for a model an iOS simulator loaded with [resolvedGpuLayers] diff --git a/lib/src/backends/webgpu/webgpu_backend.dart b/lib/src/backends/webgpu/webgpu_backend.dart index 2fa5592ff..efbfee2be 100644 --- a/lib/src/backends/webgpu/webgpu_backend.dart +++ b/lib/src/backends/webgpu/webgpu_backend.dart @@ -17,6 +17,7 @@ import '../../core/models/config/llama_cpp_param_values.dart'; import '../../core/models/config/log_level.dart'; import '../../core/models/inference/generation_params.dart'; import '../../core/models/inference/generation_usage.dart'; +import '../../core/models/inference/gpu_layer_count.dart'; import '../../core/models/inference/model_params.dart'; import '../../core/models/inference/next_token_scores.dart'; import '../../core/template/media_placeholders.dart'; @@ -866,10 +867,6 @@ class WebGpuLlamaBackend return requestedGpuLayers; } - if (requestedGpuLayers < 0) { - return _qwen35SmallSafeWebGpuLayers; - } - return math.min(requestedGpuLayers, _qwen35SmallSafeWebGpuLayers); } @@ -1129,7 +1126,7 @@ class WebGpuLlamaBackend params.preferredBackend == GpuBackend.cpu || params.device == ComputeDevice.cpu ? 0 - : params.gpuLayers; + : resolveGpuLayerCount(params.gpuLayers); if (requestedGpuLayers > 0 && _isSafariBrowser() && diff --git a/lib/src/core/models/inference/gpu_layer_count.dart b/lib/src/core/models/inference/gpu_layer_count.dart new file mode 100644 index 000000000..be4558704 --- /dev/null +++ b/lib/src/core/models/inference/gpu_layer_count.dart @@ -0,0 +1,10 @@ +import 'model_params.dart'; + +/// The layer count a load offloads for a [ModelParams.gpuLayers] of +/// [gpuLayers]. +/// +/// A negative value means every layer, as `n_gpu_layers` does in llama.cpp, +/// and resolves to [ModelParams.maxGpuLayers]; any other value is returned +/// unchanged. +int resolveGpuLayerCount(int gpuLayers) => + gpuLayers < 0 ? ModelParams.maxGpuLayers : gpuLayers; diff --git a/lib/src/core/models/inference/model_params.dart b/lib/src/core/models/inference/model_params.dart index 51cef1990..dff43e5d3 100644 --- a/lib/src/core/models/inference/model_params.dart +++ b/lib/src/core/models/inference/model_params.dart @@ -117,7 +117,8 @@ class ModelParams { /// `LlamaUnsupportedException`; it never runs elsewhere: /// - [ComputeDevice.cpu] loads no GPU layers. On llama.cpp it loads only /// the CPU module, whatever [gpuLayers] and [preferredBackend] say; - /// LiteRT-LM still rejects a [gpuLayers] other than 0 or [maxGpuLayers]. + /// LiteRT-LM still rejects a positive [gpuLayers] other than + /// [maxGpuLayers]. /// - [ComputeDevice.gpu] on llama.cpp needs a GPU module and device for /// [preferredBackend] (Vulkan on Android and Metal on an iOS simulator /// when it is [GpuBackend.auto]), and on the Web an active WebGPU @@ -135,6 +136,10 @@ class ModelParams { final ComputeDevice device; /// Number of model layers to offload to the GPU (n_gpu_layers). + /// + /// `0` keeps every layer on the CPU. A negative value means all layers, as + /// llama.cpp defines `n_gpu_layers`, and every runtime treats it exactly + /// like [maxGpuLayers]. final int gpuLayers; /// Preferred GPU backend for inference. diff --git a/test/support/recording_exit_teardown.dart b/test/support/recording_exit_teardown.dart index 97deeca11..862c18ec8 100644 --- a/test/support/recording_exit_teardown.dart +++ b/test/support/recording_exit_teardown.dart @@ -57,6 +57,10 @@ final class RecordingExitTeardown { /// no devices. final List?> loadDevices = ?>[]; + /// The `llama_model_params.n_gpu_layers` of each + /// `llama_dart_model_load_from_file` so far. + final List loadGpuLayers = []; + /// Token count of the batch of each `llama_dart_decode` so far. final List decodedTokens = []; @@ -140,6 +144,7 @@ final class RecordingExitTeardown { ? null : [for (var i = 0; devices[i] != nullptr; i++) devices[i].address], ); + loadGpuLayers.add(params.n_gpu_layers); if (!_proceeds('llama_dart_model_load_from_file')) return nullptr; final model = real.modelLoadFromFile(path, params); owned.add(model.address); diff --git a/test/unit/backends/litert_lm/litert_lm_backend_web_test.dart b/test/unit/backends/litert_lm/litert_lm_backend_web_test.dart index 82d3c59dd..76b4dea95 100644 --- a/test/unit/backends/litert_lm/litert_lm_backend_web_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_backend_web_test.dart @@ -1374,6 +1374,49 @@ void main() { expect(createdBackends, [2]); }); + for (final (gpuLayers, backend) in const [ + (-1, 2), + (-2, 2), + (ModelParams.maxGpuLayers, 2), + (0, 3), + ]) { + test('auto with gpuLayers $gpuLayers creates backend $backend', () async { + addTearDown(fakeNavigatorGpu(FakeWebGpu.missing)); + + await LiteRtLmBackend().modelLoadFromUrl( + url, + ModelParams(gpuLayers: gpuLayers), + ); + + expect(createdBackends, [backend]); + }); + } + + test('a context with negative gpuLayers keeps a GPU model', () async { + addTearDown(fakeNavigatorGpu(FakeWebGpu.missing)); + final backend = LiteRtLmBackend(); + final modelHandle = await backend.modelLoadFromUrl( + url, + const ModelParams(), + ); + + await backend.contextCreate( + modelHandle, + const ModelParams(gpuLayers: -1), + ); + await expectLater( + () => + backend.contextCreate(modelHandle, const ModelParams(gpuLayers: 0)), + throwsA( + isA().having( + (error) => error.message.toString(), + 'message', + contains('from gpu to cpu'), + ), + ), + ); + }); + test('cpu runs on the CPU', () async { await LiteRtLmBackend().modelLoadFromUrl( url, diff --git a/test/unit/backends/litert_lm/litert_lm_service_test.dart b/test/unit/backends/litert_lm/litert_lm_service_test.dart index 3306b79ef..e752a95a4 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -1786,6 +1786,55 @@ void main() { }); }); + test('treats negative gpuLayers as every layer, not the CPU', () async { + final service = LiteRtLmService(); + final throwsUnavailableGpu = liteRtLmGateAbi() == Abi.macosX64 + ? throwsA(isA()) + : throwsArgumentError; + + try { + for (final gpuLayers in [-1, -2]) { + var modelHandle = await service.loadModel( + modelFile.path, + ModelParams(gpuLayers: gpuLayers), + ); + expect( + service.getActiveBackendName(), + 'LiteRT-LM ${_expectedAutoLiteRtLmBackend()}', + ); + service.freeModel(modelHandle); + + final metal = ModelParams( + gpuLayers: gpuLayers, + preferredBackend: GpuBackend.metal, + ); + if (service.getAvailableBackendInfo().contains('gpu')) { + modelHandle = await service.loadModel(modelFile.path, metal); + expect(service.getActiveBackendName(), 'LiteRT-LM gpu'); + expect(service.getResolvedGpuLayers(), ModelParams.maxGpuLayers); + service.freeModel(modelHandle); + } else { + expect( + () => service.loadModel(modelFile.path, metal), + throwsUnavailableGpu, + ); + } + + modelHandle = await service.loadModel( + modelFile.path, + const ModelParams(gpuLayers: 0), + ); + expect( + () => service.createContext(modelHandle, metal), + anyOf(throwsArgumentError, throwsUnavailableGpu), + ); + service.freeModel(modelHandle); + } + } finally { + service.dispose(); + } + }); + test('rejects explicit backend changes during context creation', () async { final service = LiteRtLmService(); diff --git a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart index 7ebe6490c..bd38902f1 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart @@ -2617,6 +2617,113 @@ void main() { }); }); + group('negative gpuLayers', () { + late Directory tempDir; + late String modelPath; + + setUpAll(() => LlamaCppService().initializeBackend()); + + setUp(() { + tempDir = Directory.systemTemp.createTempSync('negative_gpu_layers_'); + modelPath = path.join(tempDir.path, 'llama.gguf'); + writeSyntheticLlamaGguf(modelPath); + }); + + tearDown(() => tempDir.deleteSync(recursive: true)); + + // What a load with [gpuLayers] passes to llama.cpp, resolves and reports, + // and whether its context offloads the KV cache and ops. + ({ + int nativeGpuLayers, + int? resolvedGpuLayers, + String backendName, + bool offloadKqv, + bool opOffload, + }) + load(int gpuLayers, {ComputeDevice device = ComputeDevice.auto}) { + final recorder = RecordingExitTeardown( + ExitTeardownApi.tryResolve(isWindows: Platform.isWindows)!, + ); + final service = LlamaCppService( + objectCalls: LlamaCppObjectCalls.tracked(recorder.api), + ); + addTearDown(service.dispose); + final params = ModelParams( + contextSize: 64, + gpuLayers: gpuLayers, + device: device, + ); + final handle = service.loadModel(modelPath, params); + final context = service.createContext(handle, params); + final contextParams = + _readPrivateForTesting>( + service, + '_contextParams', + )[context]!; + return ( + nativeGpuLayers: recorder.loadGpuLayers.single, + resolvedGpuLayers: service.getResolvedGpuLayers(), + backendName: service.getActiveBackendName(), + offloadKqv: contextParams.offload_kqv, + opOffload: contextParams.op_offload, + ); + } + + for (final gpuLayers in [-1, -2, -2147483648]) { + test('$gpuLayers loads, offloads and reports like maxGpuLayers', () { + final all = load(ModelParams.maxGpuLayers); + final negative = load(gpuLayers); + + expect(all.nativeGpuLayers, ModelParams.maxGpuLayers); + expect(all.resolvedGpuLayers, ModelParams.maxGpuLayers); + expect(all.offloadKqv, isTrue); + expect(all.opOffload, isTrue); + expect(negative, all); + }); + } + + test('0 keeps the model, KV cache and backend name on the CPU', () { + final cpu = load(0); + + expect(cpu.nativeGpuLayers, 0); + expect(cpu.resolvedGpuLayers, 0); + expect(cpu.backendName, 'CPU'); + expect(cpu.offloadKqv, isFalse); + expect(cpu.opOffload, isFalse); + }); + + test('a positive count is passed through with context offload', () { + final partial = load(12); + + expect(partial.nativeGpuLayers, 12); + expect(partial.resolvedGpuLayers, 12); + expect(partial.backendName, load(ModelParams.maxGpuLayers).backendName); + expect(partial.offloadKqv, isTrue); + expect(partial.opOffload, isTrue); + }); + + test('ComputeDevice.cpu still loads no GPU layers for -1', () { + final cpu = load(-1, device: ComputeDevice.cpu); + + expect(cpu.nativeGpuLayers, 0); + expect(cpu.resolvedGpuLayers, 0); + expect(cpu.backendName, 'CPU'); + expect(cpu.offloadKqv, isFalse); + }); + + test('ComputeDevice.gpu with -1 loads or throws like maxGpuLayers', () { + Object attempt(int gpuLayers) { + try { + return load(gpuLayers, device: ComputeDevice.gpu); + } on LlamaUnsupportedException catch (error) { + return error.message; + } + } + + expect(attempt(-1), attempt(ModelParams.maxGpuLayers)); + }); + }); + group('ComputeDevice', () { test('auto keeps every llama.cpp field', () { const params = ModelParams( @@ -4398,6 +4505,38 @@ void main() { expect(LlamaCppService.resolveGpuLayersForLoad(params), 42); }); + + test('resolves negative gpu layers to every layer', () { + for (final gpuLayers in [-1, -999]) { + for (final backend in [GpuBackend.auto, GpuBackend.vulkan]) { + expect( + LlamaCppService.resolveGpuLayersForLoad( + ModelParams(gpuLayers: gpuLayers, preferredBackend: backend), + ), + ModelParams.maxGpuLayers, + ); + } + } + }); + + test('still forces negative gpu layers to zero on the CPU', () { + const negative = ModelParams(gpuLayers: -1); + + expect( + LlamaCppService.resolveGpuLayersForLoad( + negative.copyWith(preferredBackend: GpuBackend.cpu), + ), + 0, + ); + expect( + LlamaCppService.resolveGpuLayersForLoad(negative, isAndroid: true), + 0, + ); + expect( + LlamaCppService.resolveGpuLayersForLoad(negative, isIosSimulator: true), + 0, + ); + }); }); group('resolveContextBatchSizes', () { @@ -5315,6 +5454,19 @@ void main() { expect(LlamaCppService.shouldDisableContextGpuOffload(params), isFalse); }); + test('keeps offload enabled for negative gpu layers', () { + const params = ModelParams(gpuLayers: -1); + + expect(LlamaCppService.shouldDisableContextGpuOffload(params), isFalse); + expect( + LlamaCppService.resolveMtmdUseGpuForLoad( + params, + LlamaCppService.resolveGpuLayersForLoad(params), + ), + isTrue, + ); + }); + test('honors resolved load-time fallback to zero gpu layers', () { const params = ModelParams( gpuLayers: 32, @@ -5359,6 +5511,21 @@ void main() { ); }); + test('returns true for Android Vulkan with negative GPU layers', () { + const params = ModelParams( + gpuLayers: -1, + preferredBackend: GpuBackend.vulkan, + ); + + expect( + LlamaCppService.shouldUseConservativeAndroidVulkanContextConfig( + params, + isAndroid: true, + ), + isTrue, + ); + }); + test('returns false for Android CPU mode', () { const params = ModelParams( gpuLayers: 0, diff --git a/test/unit/backends/webgpu/webgpu_backend_test.dart b/test/unit/backends/webgpu/webgpu_backend_test.dart index 1f591a9ad..ec0c4f0a4 100644 --- a/test/unit/backends/webgpu/webgpu_backend_test.dart +++ b/test/unit/backends/webgpu/webgpu_backend_test.dart @@ -999,6 +999,26 @@ void main() { expect(lastRequestedMicroBatchSize, 4096); }); + for (final gpuLayers in const [-1, -2]) { + test('sends every layer for gpuLayers $gpuLayers', () async { + await backend.modelLoadFromUrl( + 'https://example.com/llama-3.2-3b.gguf', + ModelParams(contextSize: 4096, gpuLayers: gpuLayers), + ); + + expect(lastRequestedGpuLayers, ModelParams.maxGpuLayers); + }); + } + + test('caps negative gpuLayers for qwen3.5-0.8b', () async { + await backend.modelLoadFromUrl( + 'https://example.com/Qwen_Qwen3.5-0.8B-Q4_K_M.gguf', + const ModelParams(contextSize: 4096, gpuLayers: -1), + ); + + expect(lastRequestedGpuLayers, 2); + }); + test('bounds size-hinted large model batches when unset', () async { await backend.modelLoadFromUrl( 'https://example.com/local-large-model.gguf', @@ -1322,6 +1342,18 @@ void main() { }, ); + test('falls back to the CPU for negative gpuLayers', () async { + bridgeRuntimeHints['llamadart.webgpu.core_variant'] = 'wasm64'; + failLoads(message: 'array buffer allocation failed', firstAttempts: 1); + + await backend.modelLoadFromUrl( + 'https://example.com/negative-layers-model.gguf', + const ModelParams(contextSize: 4096, gpuLayers: -1), + ); + + expect(requestedGpuLayerCounts, [ModelParams.maxGpuLayers, 0]); + }); + test('leaves the first rung thread count unset by default', () async { bridgeRuntimeHints['llamadart.webgpu.core_variant'] = 'wasm64'; failLoads(message: 'array buffer allocation failed', firstAttempts: 1); @@ -3817,6 +3849,22 @@ void main() { expect(lastRequestedGpuLayers, 0); }); + test('forces CPU fallback on Safari for negative gpuLayers', () async { + globalContext.setProperty( + '__llamadartBridgeUserAgent'.toJS, + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/605.1.15 ' + '(KHTML, like Gecko) Version/17.5 Safari/605.1.15' + .toJS, + ); + + await backend.modelLoadFromUrl( + 'https://example.com/model.gguf', + const ModelParams(gpuLayers: -1), + ); + + expect(lastRequestedGpuLayers, 0); + }); + test('keeps Safari GPU layers when override flag is set', () async { globalContext.setProperty( '__llamadartBridgeUserAgent'.toJS, diff --git a/test/unit/core/models/inference/gpu_layer_count_test.dart b/test/unit/core/models/inference/gpu_layer_count_test.dart new file mode 100644 index 000000000..d9411351c --- /dev/null +++ b/test/unit/core/models/inference/gpu_layer_count_test.dart @@ -0,0 +1,25 @@ +import 'package:llamadart/src/core/models/inference/gpu_layer_count.dart'; +import 'package:llamadart/src/core/models/inference/model_params.dart'; +import 'package:test/test.dart'; + +void main() { + test('a negative count resolves to every layer', () { + for (final gpuLayers in [-1, -2, -999, -2147483648]) { + expect( + resolveGpuLayerCount(gpuLayers), + ModelParams.maxGpuLayers, + reason: 'gpuLayers $gpuLayers', + ); + } + }); + + test('zero and positive counts are unchanged', () { + for (final gpuLayers in [0, 1, 33, ModelParams.maxGpuLayers, 1000]) { + expect( + resolveGpuLayerCount(gpuLayers), + gpuLayers, + reason: 'gpuLayers $gpuLayers', + ); + } + }); +} diff --git a/test/unit/core/models/inference/model_params_test.dart b/test/unit/core/models/inference/model_params_test.dart index 0f9d01611..501a48fc5 100644 --- a/test/unit/core/models/inference/model_params_test.dart +++ b/test/unit/core/models/inference/model_params_test.dart @@ -352,6 +352,18 @@ void main() { } }); + test('every device accepts negative gpuLayers, meaning all layers', () { + for (final device in ComputeDevice.values) { + for (final gpuLayers in [-1, -2]) { + expect( + ModelParams(device: device, gpuLayers: gpuLayers).validate, + returnsNormally, + reason: '$device with gpuLayers $gpuLayers', + ); + } + } + }); + test('gpu and npu reject a negative mainGpu with splitMode none', () { for (final device in [ComputeDevice.gpu, ComputeDevice.npu]) { for (final mainGpu in [-1, -2]) { diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 978bdf0b3..7fd37cd0d 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -7,6 +7,15 @@ For canonical full release notes, use: - [`CHANGELOG.md`](https://github.com/leehack/llamadart/blob/main/CHANGELOG.md) +## Unreleased + +- A negative `ModelParams.gpuLayers` now means all layers on every runtime, + as in llama.cpp, exactly like `ModelParams.maxGpuLayers`. Native llama.cpp + now also offloads the KV cache and reports the GPU backend instead of + `CPU`, LiteRT-LM under `ComputeDevice.auto` uses its GPU backend instead + of the CPU, and the Web applies its GPU safety caps and CPU fallback + ([#920](https://github.com/leehack/llamadart/issues/920)). + ## 0.13.0 - Pair this release with Apple companions `llamadart_llama_cpp_flutter`, diff --git a/website/docs/configuration/runtime-parameters.md b/website/docs/configuration/runtime-parameters.md index 5a7da92da..efa2b0df5 100644 --- a/website/docs/configuration/runtime-parameters.md +++ b/website/docs/configuration/runtime-parameters.md @@ -34,10 +34,12 @@ Important fields: - `device`: `ComputeDevice.auto` (default), `cpu`, `gpu` or `npu`, for every runtime. `auto` keeps each runtime's default; an explicit device runs there or throws `LlamaUnsupportedException`. On llama.cpp, `cpu` ignores - `gpuLayers`; LiteRT-LM rejects a `gpuLayers` other than `0` or + `gpuLayers`; LiteRT-LM rejects a positive `gpuLayers` other than `ModelParams.maxGpuLayers` with any device. See [Choosing the device](../guides/backend-selection#choosing-the-device). -- `gpuLayers`: number of layers offloaded to GPU. +- `gpuLayers`: number of layers offloaded to GPU. `0` keeps the model on + CPU; a negative value means all layers, as in llama.cpp, and every runtime + treats it like `ModelParams.maxGpuLayers`. - `preferredBackend`: backend preference (`auto`, `vulkan`, `metal`, etc). On Linux and Windows, an explicit GPU backend whose module is missing loads the model on CPU with 0 GPU layers and logs a Dart warning; @@ -144,7 +146,8 @@ runtime default. | `numberOfThreads` | Generation thread count; `0` keeps automatic selection. | | `loras` | At most one adapter, at the default scale of `1.0`, loaded with the model. Runtime LoRA APIs, stacking and custom scales are llama.cpp-only. | -`gpuLayers` must be `0` (CPU) or `ModelParams.maxGpuLayers`. Native +`gpuLayers` must be `0` (CPU), `ModelParams.maxGpuLayers` or a negative +value, which means all layers like `maxGpuLayers`. Native LiteRT-LM rejects llama.cpp-specific fields such as `batchSize`, `numberOfThreadsBatch`, `splitMode`, `mainGpu` or KV-cache types: the load throws `LlamaUnsupportedException` naming each rejected field, so a GGUF