Skip to content

GGML_ASSERT(device) failed #3497

@RandyJohan

Description

@RandyJohan

Hello friends, I have a problem when I try to initialize the whisper context using a plugin in flutter by ffi, I leave the logs:

[fu_whisper_create] Initializing Whisper...
[fu_whisper_create] Model: large_assets/models/ggml-medium-q5_0.bin
[CHECK] use_gpu = 0
[CHECK] flash_attn = 0
whisper_init_from_file_with_params_no_state: loading model from 'large_assets/models/ggml-medium-q5_0.bin'
whisper_init_with_params_no_state: use gpu = 0
whisper_init_with_params_no_state: flash attn = 0
whisper_init_with_params_no_state: gpu_device = 0
whisper_init_with_params_no_state: dtw = 0
whisper_init_with_params_no_state: devices = 0
whisper_init_with_params_no_state: backends = 0
whisper_model_load: loading model
whisper_model_load: n_vocab = 51865
whisper_model_load: n_audio_ctx = 1500
whisper_model_load: n_audio_state = 1024
whisper_model_load: n_audio_head = 16
whisper_model_load: n_audio_layer = 24
whisper_model_load: n_text_ctx = 448
whisper_model_load: n_text_state = 1024
whisper_model_load: n_text_head = 16
whisper_model_load: n_text_layer = 24
whisper_model_load: n_mels = 80
whisper_model_load: ftype = 8
whisper_model_load: qntvr = 1
whisper_model_load: type = 4 (medium)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: n_langs = 99
[ERROR] ggml_backend_dev_backend_reg received null device!
C:\fractalup\master-flutter\flutter\windows\flutter\ephemeral\.plugin_symlinks\flutter_whisper\fu_whisper\ggml\src\ggml-backend.cpp:509: GGML_ASSERT(device) failed

I'm avoiding GPUs for now, but I don't understand why this error keeps appearing when I just try to initialize the context. This is my CMakeList.txt; it's driving me crazy.

cmake_minimum_required(VERSION 3.15)
project(flutter_whisper_plugin)

# ✅ Clean definitions and compatible with whisper.cpp master (1.8.2)
add_definitions( 
-DWHISPER_VERSION="1.8.2" 
-DGGML_VERSION="0.0.0" 
-DGGML_COMMIT="local" 
-DGGML_USE_STD_THREAD # Use std::thread for multithreading 
-DGGML_CUDA=0 
-DGGML_OPENCL=0 
-DGGML_VULKAN=0 
-DGGML_METAL=0 
-DGGML_FLASH_ATTN=0 
-DGGML_COREML=0 
-DGGML_OPENVINO=0 
-DGGML_SYCL=0 
-DGGML_RPC=0 
-DGGML_KOMPUTE=0 
-DGGML_BLAS=0 # Disable BLAS if not needed; enable if OpenBLAS is installed for performance 
-DGGML_NO_ACCELERATE=1 # Ensure no accidental accelerator inclusion
)

# Path to Flutter headers
set(FLUTTER_ROOT "C:/app/master-flutter/flutter")
include_directories("${FLUTTER_ROOT}/bin/cache/artifacts/engine/windows")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Optimize for host CPU

# Base routes
set(PLUGIN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
set(FU_WHISPER_DIR ${PLUGIN_ROOT_DIR}/fu_whisper)
set(GGML_DIR ${FU_WHISPER_DIR}/ggml)
set(WRAPPER_DIR ${PLUGIN_ROOT_DIR}/native)


# Main source files
set(WHISPER_SOURCES 
${FU_WHISPER_DIR}/src/whisper.cpp 
${GGML_DIR}/src/ggml.c 
${GGML_DIR}/src/ggml-alloc.c 
${GGML_DIR}/src/ggml-opt.cpp 
${GGML_DIR}/src/ggml-quants.c 
${GGML_DIR}/src/ggml-backend.cpp 
${GGML_DIR}/src/ggml-backend-reg.cpp 
${GGML_DIR}/src/ggml-threading.cpp 
# CPU-specific sources (ensure quantization, traits, and optimizations) 
${GGML_DIR}/src/ggml-cpu/ggml-cpu.cpp 
${GGML_DIR}/src/ggml-cpu/ggml-cpu.c 
${GGML_DIR}/src/ggml-cpu/quants.c 
${GGML_DIR}/src/ggml-cpu/traits.cpp 
${GGML_DIR}/src/ggml-cpu/hbm.cpp # High-bandwidth memory support (optional) 
${GGML_DIR}/src/ggml-cpu/amx/amx.cpp # Intel AMX if applicable 
${GGML_DIR}/src/ggml-cpu/amx/mmq.cpp # Matrix multiplication optimizations 
${GGML_DIR}/src/ggml-cpu/unary-ops.cpp 
${GGML_DIR}/src/ggml-cpu/binary-ops.cpp 
${GGML_DIR}/src/ggml-cpu/ops.cpp 
${GGML_DIR}/src/ggml-cpu/vec.cpp 
${GGML_DIR}/src/ggml-cpu/arch/arm/quants.c 
# Add platform-specific if present (e.g., for ARM, but skip for Windows x64) 
# ${GGML_DIR}/src/ggml-aarch64.c
)

# Include headers
include_directories( 
${FU_WHISPER_DIR}/include 
${GGML_DIR}/include 
${GGML_DIR}/src 
${GGML_DIR}/src/ggml-cpu # For CPU impl headers 
${WRAPPER_DIR} 
${PLUGIN_ROOT_DIR}/include
)

# whisper static library
add_library(whisper STATIC ${WHISPER_SOURCES})

# Flutter shared plugin
add_library(flutter_whisper_plugin SHARED 
flutter_whisper_plugin.cpp 
${WRAPPER_DIR}/whisper_wrapper.cpp
)

#target_link_libraries(flutter_whisper_plugin PRIVATE whisper flutter_wrapper_plugin)
# Link whisper static lib and Flutter engine
target_link_libraries(flutter_whisper_plugin PRIVATE whisper flutter_wrapper_plugin)
#target_link_libraries(flutter_whisper_plugin PRIVATE "${FLUTTER_ROOT}/bin/cache/artifacts/engine/windows-x64/flutter_windows.dll.lib") # Flutter DLL import lib

target_include_directories(flutter_whisper_plugin PUBLIC 
${PLUGIN_ROOT_DIR}/include
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions