diff --git a/CHANGELOG.md b/CHANGELOG.md index 72e413e4b..2b0a622a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +- Exclude Android Adreno 750 driver `2150604839` from llama.cpp Vulkan loads: automatic selection falls back to CPU with a warning, and an explicit GPU request throws instead of crashing or producing incorrect text. + - Update the default LiteRT-LM runtime to `leehack/litert-lm-native@v0.18.0` (upstream LiteRT-LM `v0.18.0`). On the macOS GPU backend the program cache of Qwen3 0.6B and Gemma 4 E2B no longer diff --git a/README.md b/README.md index a0cbf508f..5d8da3f45 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ Android deployments, NPU. See the [support matrix](https://llamadart.leehack.com/docs/platforms/support-matrix) for each target. +Android llama.cpp excludes the known unsafe Adreno 750 driver `2150604839`: +explicit GPU requests throw, while automatic selection with a Vulkan +preference falls back to CPU with a warning. See the +[device limitations](https://llamadart.leehack.com/docs/platforms/support-matrix#known-limitations). + ## Start Here | Need | Link | diff --git a/example/basic_app/README.md b/example/basic_app/README.md index 6ce0bd43e..219a0217d 100644 --- a/example/basic_app/README.md +++ b/example/basic_app/README.md @@ -8,7 +8,7 @@ A clean, organized CLI application demonstrating the capabilities of the `llamad - **Single Response Mode**: Pass a prompt as an argument for quick tasks. - **Automatic Model Management**: Accepts local paths, HTTP(S) URLs, and `hf://` Hugging Face model sources, then resolves remote sources through the package-managed cache. - **Platform Cache Defaults**: Remote model URLs use `DefaultModelDownloadManager`, so desktop/server runs share the per-user `llamadart` model cache while explicit local paths are loaded directly. -- **Backend Optimization**: Defaults to GPU acceleration (Metal/Vulkan) when available. +- **Backend Optimization**: Defaults to GPU acceleration (Metal/Vulkan) when available on desktop and CPU for Android llama.cpp. Android Adreno 750 driver `2150604839` is excluded from Vulkan: automatic selection with a Vulkan preference uses CPU with a warning; explicit GPU requests throw. - **LoRA Adapters**: Load one or more LoRA adapters with repeated `--lora` flags. - **Structured Output**: Pass `--grammar` for GBNF-constrained generation. - **Tool Calling Test Mode**: Enable `--tool-test` to exercise function-calling flow. diff --git a/lib/src/backends/llama_cpp/llama_cpp_service.dart b/lib/src/backends/llama_cpp/llama_cpp_service.dart index 8296f8733..4cd492513 100644 --- a/lib/src/backends/llama_cpp/llama_cpp_service.dart +++ b/lib/src/backends/llama_cpp/llama_cpp_service.dart @@ -2104,12 +2104,13 @@ class LlamaCppService { required int splitMode, required int mainGpu, }) => resolveVulkanLoadDecision( - usesGpu: gpuLayers > 0 && backend != GpuBackend.cpu, + usesGpu: gpuLayers != 0 && backend != GpuBackend.cpu, backendRegistry: ggmlGpuRegistryName(backend), splitMode: splitMode, mainGpu: mainGpu, registered: _registeredDevices, probe: () => _vulkanDeviceProbe, + isAndroid: _isAndroid, ); /// The registered ggml devices, in registry order. diff --git a/lib/src/backends/llama_cpp/load_device_selection.dart b/lib/src/backends/llama_cpp/load_device_selection.dart index 931028ad4..74a20a684 100644 --- a/lib/src/backends/llama_cpp/load_device_selection.dart +++ b/lib/src/backends/llama_cpp/load_device_selection.dart @@ -117,7 +117,8 @@ final class VulkanLoadDecision { /// The usable devices to list for the load in place of the selected ones; /// `null` when no listed load can avoid the unusable devices, which is when - /// every selected device is one, and when nothing changes. + /// every selected device is one, or an unsafe Android driver is registered, + /// and when nothing changes. final List? devices; /// Whether no usable device is left, so the load cannot run on the GPU. @@ -152,18 +153,18 @@ VulkanDeviceFacts? vulkanFactsOf( return named.first; } -/// Decides what a model load does about Vulkan devices below Vulkan 1.2. +/// Decides what a model load does about Vulkan devices below Vulkan 1.2 or, +/// on [isAndroid], the known unsafe Adreno 750 driver. /// /// [usesGpu] is false for a load that offloads nothing, which never starts a /// device. [backendRegistry] is the ggml registry of an explicit GPU backend, /// whose devices the load lists (`llama_model_params.devices`) when it has /// any, or `null` when llama.cpp selects among every registered device. /// -/// Only the devices the load would use count: a registered device that is -/// not selected is never initialized (`ggml_backend_vk_reg_get_device` only -/// describes it). [registered] is read only for a load that [usesGpu], and -/// [probe] only when a Vulkan device is selected. A device whose facts -/// [vulkanFactsOf] cannot tell is taken as usable. +/// Vulkan API floors apply to selected model devices. On Android the driver +/// guard also covers registered devices that auxiliary GPU selectors could +/// choose independently. [registered] is read only for a load that [usesGpu]. +/// A device whose facts cannot be matched is taken as usable. VulkanLoadDecision resolveVulkanLoadDecision({ required bool usesGpu, required String? backendRegistry, @@ -171,6 +172,7 @@ VulkanLoadDecision resolveVulkanLoadDecision({ required int mainGpu, required List Function() registered, required VulkanDeviceProbe Function() probe, + bool isAndroid = false, }) { if (!usesGpu) return VulkanLoadDecision.unchanged; final devices = registered(); @@ -186,12 +188,33 @@ VulkanLoadDecision resolveVulkanLoadDecision({ mainGpu: mainGpu, ); - if (!selected.any((device) => device.isVulkan)) { + final inspected = isAndroid ? devices : selected; + if (!inspected.any((device) => device.isVulkan)) { return VulkanLoadDecision.unchanged; } final facts = probe().devices; if (facts == null) return VulkanLoadDecision.unchanged; + // Projector and decision-head GPU selection is independent of the model's + // list. Refuse GPU work if any registered Android device has this driver. + if (isAndroid) { + for (final device in devices.where((device) => device.isVulkan)) { + if (facts.any( + (fact) => + fact.name == device.description && + fact.isIntegratedGpu == (device.type == _typeIgpu) && + fact.hasAdreno750DriverDefect, + )) { + return VulkanLoadDecision._( + unsupported: + '"${device.description}" (${device.name}) on Android driver ' + '2150604839 has known llama.cpp Vulkan shader-compiler crashes ' + 'and incorrect quantized results. GPU work is excluded until ' + 'a native workaround and the model are qualified', + ); + } + } + } String? unsupported; final usable = []; for (final device in selected) { diff --git a/lib/src/backends/llama_cpp/vulkan_device_probe.dart b/lib/src/backends/llama_cpp/vulkan_device_probe.dart index aa767ec90..bc94a5204 100644 --- a/lib/src/backends/llama_cpp/vulkan_device_probe.dart +++ b/lib/src/backends/llama_cpp/vulkan_device_probe.dart @@ -20,6 +20,8 @@ final class VulkanDeviceFacts { required this.instanceApiVersion, required this.apiVersion, required this.subgroupSize, + this.vendorId = 0, + this.driverVersion = 0, }); /// Vulkan 1.2 as `VK_MAKE_API_VERSION` encodes it. @@ -46,6 +48,23 @@ final class VulkanDeviceFacts { /// or the driver is older than Vulkan 1.1 and cannot report it. final int subgroupSize; + /// `VkPhysicalDeviceProperties.vendorID`, or 0 when not reported. + final int vendorId; + + /// The vendor-specific `VkPhysicalDeviceProperties.driverVersion`. + final int driverVersion; + + /// The Android Adreno 750 driver with shader-compiler crashes and + /// incorrect quantized matrix-vector results (llamadart-native #79). + /// + /// A crash workaround alone does not qualify this driver for inference; + /// common K-quants remain incorrect. Other driver versions are unaffected + /// by this narrowly matched guard. + bool get hasAdreno750DriverDefect => + vendorId == 0x5143 && + driverVersion == 2150604839 && + name == 'Adreno (TM) 750'; + /// Whether ggml-vulkan can drive the device. /// /// ggml-vulkan registers no device when the loader is below Vulkan 1.2 @@ -196,6 +215,8 @@ final class VulkanDeviceInfoApi { instanceApiVersion: info.ref.instance_api_version, apiVersion: info.ref.api_version, subgroupSize: info.ref.subgroup_size, + vendorId: info.ref.vendor_id, + driverVersion: info.ref.driver_version, ), ); } diff --git a/lib/src/core/models/inference/model_params.dart b/lib/src/core/models/inference/model_params.dart index 135c95b38..14cbd448d 100644 --- a/lib/src/core/models/inference/model_params.dart +++ b/lib/src/core/models/inference/model_params.dart @@ -129,6 +129,9 @@ class ModelParams { /// a GPU or NPU that fails to start throws `LlamaUnsupportedException` /// there. [validate] rejects a device that contradicts [preferredBackend], /// [gpuLayers], [mainGpu] or [liteRtLmBackend]. + /// Android llama.cpp excludes the known unsafe Adreno 750 driver + /// `2150604839`: [ComputeDevice.gpu] throws, while automatic selection + /// with a Vulkan preference falls back to CPU with a warning. final ComputeDevice device; /// Number of model layers to offload to the GPU (n_gpu_layers). diff --git a/skills/llamadart-flutter-app/SKILL.md b/skills/llamadart-flutter-app/SKILL.md index 77720ea9f..a4ca221e9 100644 --- a/skills/llamadart-flutter-app/SKILL.md +++ b/skills/llamadart-flutter-app/SKILL.md @@ -168,7 +168,10 @@ or shipping runtimes the app does not use. - Android: llama.cpp ships `cpu` and `vulkan` by default; `opencl` is opt-in through `llamadart_native_backends`. llama.cpp `ComputeDevice.auto` stays on the CPU there; Vulkan is experimental and device-dependent, so request - `ComputeDevice.gpu` only on devices the app has validated. Leave + `ComputeDevice.gpu` only on devices the app has validated. Adreno 750 + driver `2150604839` is excluded: an explicit GPU request throws; automatic + selection with a Vulkan preference falls back to CPU with a warning. + A shader-compiler workaround alone does not qualify quantized output. Leave `ModelParams.microBatchSize` unset on Android Vulkan: on a GPU whose subgroup size is 16, below 8 or unreadable a text prompt is then decoded at most 8 tokens at a time, and a value above 32 returns wrong text there. The 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 16d945b15..4a9258a09 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart @@ -5616,9 +5616,11 @@ void main() { List registered, List? facts, { LlamaCppObjectCalls? objectCalls, + bool isAndroid = false, }) { reads = 0; final service = LlamaCppService( + isAndroid: isAndroid, deviceTypes: (_) => [gpuType], objectCalls: objectCalls, registeredDevices: () => registered, @@ -5633,6 +5635,80 @@ void main() { return service; } + for (final gpuLayers in [ModelParams.maxGpuLayers, -1]) { + test( + 'Android Adreno guard refuses explicit GPU and loads auto on CPU ' + 'before a native model call can use the unsafe device ($gpuLayers layers)', + () { + final adreno = entry('Vulkan0', description: 'Adreno (TM) 750'); + const bad = VulkanDeviceFacts( + name: 'Adreno (TM) 750', + deviceType: 2, + instanceApiVersion: vulkan13, + apiVersion: vulkan13, + subgroupSize: 64, + vendorId: 0x5143, + driverVersion: 2150604839, + ); + // Metal supplies the host's real GPU module; the injected registry + // and facts supply Android's selected Vulkan device. No driver is + // initialized by the probe and the guarded load must use the CPU. + final explicit = serviceWith([adreno], [bad], isAndroid: true); + expect( + () => explicit.loadModel( + modelPath, + ModelParams( + gpuLayers: gpuLayers, + contextSize: 64, + device: ComputeDevice.gpu, + preferredBackend: GpuBackend.metal, + ), + ), + throwsA( + isA().having( + (e) => e.message, + 'message', + contains('driver 2150604839'), + ), + ), + ); + expect(_readPrivateForTesting(explicit, '_models'), isEmpty); + final automatic = serviceWith([adreno], [bad], isAndroid: true); + final model = automatic.loadModel( + modelPath, + ModelParams( + gpuLayers: gpuLayers, + contextSize: 64, + preferredBackend: GpuBackend.metal, + ), + ); + expect(automatic.getResolvedGpuLayers(), 0); + expect(automatic.getActiveBackendName(), 'CPU'); + expect( + warnings, + contains( + allOf( + contains('driver 2150604839'), + contains('so the model loaded on CPU with 0 GPU layers'), + ), + ), + ); + final context = automatic.createContext( + model, + const ModelParams(contextSize: 64), + ); + final params = + _readPrivateForTesting>( + automatic, + '_contextParams', + )[context]!; + expect(params.op_offload, isFalse); + expect(params.offload_kqv, isFalse); + }, + testOn: 'mac-os', + ); + } + Matcher noVulkanWarning() => isNot(contains(contains('Vulkan 1.2'))); test('ComputeDevice.gpu throws and loads nothing when the only ' diff --git a/test/unit/backends/llama_cpp/load_device_selection_test.dart b/test/unit/backends/llama_cpp/load_device_selection_test.dart index b80dc68f3..4eb05cf1a 100644 --- a/test/unit/backends/llama_cpp/load_device_selection_test.dart +++ b/test/unit/backends/llama_cpp/load_device_selection_test.dart @@ -250,8 +250,10 @@ void main() { bool usesGpu = true, int splitMode = _layer, int mainGpu = 0, + bool isAndroid = false, }) => resolveVulkanLoadDecision( usesGpu: usesGpu, + isAndroid: isAndroid, backendRegistry: backend, splitMode: splitMode, mainGpu: mainGpu, @@ -301,6 +303,67 @@ void main() { final maliOld = _fact('Mali-G68', _vulkan11); final mali = _device('Vulkan0', description: 'Mali-G68'); + test( + 'refuses Android GPU loads when the affected driver is registered', + () { + final adreno = _device('Vulkan0', description: 'Adreno (TM) 750'); + const bad = VulkanDeviceFacts( + name: 'Adreno (TM) 750', + deviceType: 2, + instanceApiVersion: _vulkan13, + apiVersion: _vulkan13, + subgroupSize: 64, + vendorId: 0x5143, + driverVersion: 2150604839, + ); + expect( + decide([adreno], _facts([bad]), isAndroid: true), + refused('driver 2150604839'), + ); + expect(decide([adreno], _facts([bad])), unchanged()); + expect( + decide([adreno], _facts([bad]), isAndroid: true, usesGpu: false), + unchanged(), + ); + expect( + decide([adreno, cuda], _facts([bad]), isAndroid: true), + refused('driver 2150604839'), + ); + expect( + decide( + [adreno, rtx], + _facts([bad, rtxOk]), + isAndroid: true, + splitMode: _none, + mainGpu: 1, + ), + refused('driver 2150604839'), + ); + final newer = VulkanDeviceFacts( + name: bad.name, + deviceType: bad.deviceType, + instanceApiVersion: bad.instanceApiVersion, + apiVersion: bad.apiVersion, + subgroupSize: bad.subgroupSize, + vendorId: bad.vendorId, + driverVersion: bad.driverVersion + 1, + ); + expect(decide([adreno], _facts([newer]), isAndroid: true), unchanged()); + expect( + decide([adreno], _facts([bad, newer]), isAndroid: true), + refused('driver 2150604839'), + ); + expect( + decide( + [adreno], + () => const VulkanDeviceProbe.unavailable('missing'), + isAndroid: true, + ), + unchanged(), + ); + }, + ); + test('a load that offloads nothing reads neither the registry nor the ' 'facts', () { expect(decide([mali], _facts([maliOld]), usesGpu: false), unchanged()); diff --git a/test/unit/backends/llama_cpp/vulkan_device_probe_test.dart b/test/unit/backends/llama_cpp/vulkan_device_probe_test.dart index d42841fe8..e3a4cf2ed 100644 --- a/test/unit/backends/llama_cpp/vulkan_device_probe_test.dart +++ b/test/unit/backends/llama_cpp/vulkan_device_probe_test.dart @@ -56,6 +56,26 @@ void main() { ); }); + test('matches the Adreno defect by vendor, driver and device name', () { + VulkanDeviceFacts fact({ + int vendor = 0x5143, + int driver = 2150604839, + String name = 'Adreno (TM) 750', + }) => VulkanDeviceFacts( + name: name, + deviceType: 1, + instanceApiVersion: _version(1, 3), + apiVersion: _version(1, 3), + subgroupSize: 64, + vendorId: vendor, + driverVersion: driver, + ); + expect(fact().hasAdreno750DriverDefect, isTrue); + expect(fact(vendor: 0).hasAdreno750DriverDefect, isFalse); + expect(fact(driver: 2150604840).hasAdreno750DriverDefect, isFalse); + expect(fact(name: 'Adreno (TM) 740').hasAdreno750DriverDefect, isFalse); + }); + test('has the small matmul tile defect at every subgroup size ' 'ggml-vulkan mis-tiles', () { // llama.cpp v0.6.0 gives a warp 8 rows of the 32-row block only at a @@ -184,6 +204,8 @@ void main() { info.ref.instance_api_version = _version(1, 3, 275); info.ref.api_version = _version(1, 3 - index, 7); info.ref.subgroup_size = index == 0 ? 16 : 64; + info.ref.vendor_id = 0x5143 + index; + info.ref.driver_version = 2150604839 + index; return 0; }, ); @@ -200,6 +222,11 @@ void main() { ]); expect(devices.map((device) => device.isIntegratedGpu), [true, false]); expect(devices.map((device) => device.deviceType), [1, 2]); + expect(devices.map((device) => device.vendorId), [0x5143, 0x5144]); + expect(devices.map((device) => device.driverVersion), [ + 2150604839, + 2150604840, + ]); expect(api.probe().unavailableReason, isNull); }, ); diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 9437a6538..5831b7afe 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -9,6 +9,8 @@ For canonical full release notes, use: ## Unreleased +- Exclude Android Adreno 750 driver `2150604839` from llama.cpp Vulkan loads: automatic selection falls back to CPU with a warning, and an explicit GPU request throws instead of crashing or producing incorrect text. + - Update the default LiteRT-LM runtime to `leehack/litert-lm-native@v0.18.0` (upstream LiteRT-LM `v0.18.0`). On the macOS GPU backend the program cache of Qwen3 0.6B and Gemma 4 E2B no longer diff --git a/website/docs/guides/backend-selection.md b/website/docs/guides/backend-selection.md index 57e0d4103..5c727bb87 100644 --- a/website/docs/guides/backend-selection.md +++ b/website/docs/guides/backend-selection.md @@ -129,6 +129,11 @@ never falls back to another device: LiteRT-LM it needs the GPU backend: Linux arm64 and macOS x64 have none. - `npu` is LiteRT-LM on Android only. +Android llama.cpp excludes the known unsafe Adreno 750 driver `2150604839`. +An explicit GPU request throws; automatic selection with a Vulkan preference +falls back to CPU with a warning when no usable GPU remains. A native crash +workaround does not establish correct inference for its quantized models. + Native LiteRT-LM starts its runtime on the first call that needs it, such as the first generation or `tokenize`, so a GPU or NPU delegate that fails to start throws `LlamaUnsupportedException` there rather than from the load. The diff --git a/website/docs/platforms/support-matrix.md b/website/docs/platforms/support-matrix.md index c7340e65e..8d5c62bb4 100644 --- a/website/docs/platforms/support-matrix.md +++ b/website/docs/platforms/support-matrix.md @@ -193,6 +193,21 @@ output and grammars, sampling controls and speculative decoding. Guides: warning; a GPU llama.cpp would not select, like an integrated GPU beside a discrete one, changes nothing. Whether this is what crashes the Galaxy A53 is not confirmed. + On Android, the exact Qualcomm vendor `0x5143`, `Adreno (TM) 750` + driver `2150604839` has shader-compiler crashes and incorrect quantized + results, including common `Q4_K_M` models. When this device is registered, + GPU loads are refused even if another GPU was selected: projector and + decision-head GPU selection can independently choose the affected device. + `ComputeDevice.auto` loads on CPU with a warning, including when + `preferredBackend` requests Vulkan; `ComputeDevice.gpu` throws + `LlamaUnsupportedException`. CPU loads do not probe Vulkan. Detection needs + the device-facts API in native `v0.6.0-1` or later; an overridden runtime + without it cannot enforce this guard. Other driver versions are unchanged. + A shader crash workaround alone does not qualify this driver; re-enabling + a model requires qualification of the final native artifact on that exact + driver. + See [native issue #79](https://github.com/leehack/llamadart-native/issues/79). + Keep `auto` or `cpu` on Android unless the app has validated Vulkan on its target devices. - Some Vulkan drivers crash in the cooperative-matrix path; see