diff --git a/.github/workflows/build-tflite.yml b/.github/workflows/build-tflite.yml index 53e6f0f..7b04739 100644 --- a/.github/workflows/build-tflite.yml +++ b/.github/workflows/build-tflite.yml @@ -15,21 +15,19 @@ on: jobs: build: strategy: + fail-fast: false matrix: include: - - os: macos-14 + - os: macos-15 arch: arm64 artifact: libtensorflowlite_c_darwin_arm64.dylib - - os: macos-13 - arch: x86_64 - artifact: libtensorflowlite_c_darwin_x86_64.dylib - os: ubuntu-24.04 arch: amd64 artifact: libtensorflowlite_c_linux_amd64.so - os: ubuntu-24.04-arm arch: arm64 artifact: libtensorflowlite_c_linux_arm64.so - - os: windows-latest + - os: windows-2022 arch: amd64 artifact: tensorflowlite_c_windows_amd64.dll runs-on: ${{ matrix.os }} @@ -47,13 +45,12 @@ jobs: with: python-version: '3.12' - - name: Setup Bazel (Unix) - if: runner.os != 'Windows' - run: npm install -g @bazel/bazelisk - - - name: Setup Bazel (Windows) - if: runner.os == 'Windows' - run: choco install bazelisk -y + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.19.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }}-${{ matrix.os }}-${{ matrix.arch }} + repository-cache: true - name: Build TFLite C shared library working-directory: tf_src diff --git a/lib/desktop/flutter_gemma_desktop.dart b/lib/desktop/flutter_gemma_desktop.dart index 9588f5a..b5ec948 100644 --- a/lib/desktop/flutter_gemma_desktop.dart +++ b/lib/desktop/flutter_gemma_desktop.dart @@ -217,7 +217,7 @@ class FlutterGemmaDesktop extends FlutterGemmaPlugin { if (_initEmbeddingCompleter != null && _initializedEmbeddingModel != null && _lastActiveEmbeddingModelName != null) { - final modelChanged = currentActiveModel != null && + final modelChanged = currentActiveModel == null || currentActiveModel.name != _lastActiveEmbeddingModelName; if (modelChanged) { await _initializedEmbeddingModel?.close(); @@ -279,19 +279,25 @@ class FlutterGemmaDesktop extends FlutterGemmaPlugin { // Load tokenizer - auto-detect format by file extension // SentencePieceConfig.gemma adds BOS + EOS tokens automatically if (tokenizerPath == null) { + interpreter.close(); throw StateError('Tokenizer path is required for desktop embeddings'); } final SentencePieceTokenizer tokenizer; - if (tokenizerPath.endsWith('.json')) { - tokenizer = await TokenizerJsonLoader.fromJsonFile( - tokenizerPath, - config: SentencePieceConfig.gemma, - ); - } else { - tokenizer = await SentencePieceTokenizer.fromModelFile( - tokenizerPath, - config: SentencePieceConfig.gemma, - ); + try { + if (tokenizerPath.endsWith('.json')) { + tokenizer = await TokenizerJsonLoader.fromJsonFile( + tokenizerPath, + config: SentencePieceConfig.gemma, + ); + } else { + tokenizer = await SentencePieceTokenizer.fromModelFile( + tokenizerPath, + config: SentencePieceConfig.gemma, + ); + } + } catch (e) { + interpreter.close(); + rethrow; } List tokenize(String text) { diff --git a/linux/scripts/setup_desktop.sh b/linux/scripts/setup_desktop.sh index 2e96774..b4fb577 100755 --- a/linux/scripts/setup_desktop.sh +++ b/linux/scripts/setup_desktop.sh @@ -59,9 +59,9 @@ JRE_URL="https://cdn.azul.com/zulu/bin/${JRE_ARCHIVE}" # JAR settings JAR_NAME="litertlm-server.jar" -JAR_VERSION="0.12.7" +JAR_VERSION="0.12.6" JAR_URL="https://github.com/DenisovAV/flutter_gemma/releases/download/v${JAR_VERSION}/${JAR_NAME}" -JAR_CHECKSUM="" +JAR_CHECKSUM="fefc53d076533de164b5ce07c65f9aedc4739f83efc93e67625f0d90029ae5b7" # Plugin root (parent of linux/) PLUGIN_ROOT=$(dirname "$PLUGIN_DIR") @@ -261,9 +261,16 @@ install_tflite() { local TFLITE_VERSION="0.12.7" local TFLITE_ARTIFACT="" + local TFLITE_CHECKSUM="" case "$ARCH" in - x86_64) TFLITE_ARTIFACT="libtensorflowlite_c_linux_amd64.so" ;; - aarch64) TFLITE_ARTIFACT="libtensorflowlite_c_linux_arm64.so" ;; + x86_64) + TFLITE_ARTIFACT="libtensorflowlite_c_linux_amd64.so" + TFLITE_CHECKSUM="2a26d1175db1d4304b963b91d8ce70cee06e3a3973c3e14e197b731e3632881b" + ;; + aarch64) + TFLITE_ARTIFACT="libtensorflowlite_c_linux_arm64.so" + TFLITE_CHECKSUM="1a3d3984c317237a7a35104eef8a99034abb933dc3807beb3d318276ea832941" + ;; *) echo "WARNING: TFLite C library not available for $ARCH" echo "Desktop embeddings will not work on this architecture" @@ -275,9 +282,6 @@ install_tflite() { mkdir -p "$TFLITE_CACHE" "$TFLITE_DIR" - # SHA256 checksum (fill from CI artifacts after build) - local TFLITE_CHECKSUM="" - local CACHED="$TFLITE_CACHE/$TFLITE_ARTIFACT" if [ ! -f "$CACHED" ]; then echo "Downloading TFLite C library..." diff --git a/macos/scripts/prepare_resources.sh b/macos/scripts/prepare_resources.sh index 30d2fbc..b603991 100755 --- a/macos/scripts/prepare_resources.sh +++ b/macos/scripts/prepare_resources.sh @@ -39,7 +39,7 @@ TFLITE_CACHE_DIR="$HOME/Library/Caches/flutter_gemma/tflite" # JAR settings JAR_NAME="litertlm-server.jar" -JAR_VERSION="0.12.7" +JAR_VERSION="0.12.6" JAR_URL="https://github.com/DenisovAV/flutter_gemma/releases/download/v${JAR_VERSION}/${JAR_NAME}" JAR_CHECKSUM="fefc53d076533de164b5ce07c65f9aedc4739f83efc93e67625f0d90029ae5b7" JAR_CACHE_DIR="$HOME/Library/Caches/flutter_gemma/jar" @@ -396,8 +396,8 @@ setup_tflite() { echo "Setting up TFLite C library..." mkdir -p "$TFLITE_CACHE_DIR" "$tflite_dest" - # SHA256 checksum (fill from CI artifacts after build) - local TFLITE_CHECKSUM="" + # SHA256 checksum from CI build (TF 2.19.0) + local TFLITE_CHECKSUM="465257ce5c11ef4bcc39e6b25ca02876523942fe797da8d785daf1c024c07680" local cached="$TFLITE_CACHE_DIR/$archive_name" if [[ ! -f "$cached" ]]; then diff --git a/macos/scripts/setup_desktop.sh b/macos/scripts/setup_desktop.sh index ff4ab3e..32391cc 100755 --- a/macos/scripts/setup_desktop.sh +++ b/macos/scripts/setup_desktop.sh @@ -58,7 +58,7 @@ JRE_CHECKSUM_X64="4a36280b411db58952bc97a26f96b184222b23d36ea5008a6ee34744989ff9 # JAR settings JAR_NAME="litertlm-server.jar" -JAR_VERSION="0.12.7" +JAR_VERSION="0.12.6" JAR_URL="https://github.com/DenisovAV/flutter_gemma/releases/download/v${JAR_VERSION}/${JAR_NAME}" JAR_CHECKSUM="fefc53d076533de164b5ce07c65f9aedc4739f83efc93e67625f0d90029ae5b7" JAR_CACHE_DIR="$HOME/Library/Caches/flutter_gemma/jar" @@ -495,7 +495,7 @@ setup_tflite() { mkdir -p "$tflite_cache" "$tflite_dest" # SHA256 checksum (fill from CI artifacts after build) - local TFLITE_CHECKSUM="" + local TFLITE_CHECKSUM="465257ce5c11ef4bcc39e6b25ca02876523942fe797da8d785daf1c024c07680" local cached="$tflite_cache/$archive_name" if [[ ! -f "$cached" ]]; then diff --git a/windows/scripts/setup_desktop.ps1 b/windows/scripts/setup_desktop.ps1 index 372c032..bb0ece2 100644 --- a/windows/scripts/setup_desktop.ps1 +++ b/windows/scripts/setup_desktop.ps1 @@ -87,7 +87,7 @@ $JreChecksums = @{ # JAR settings $JarName = "litertlm-server.jar" -$JarVersion = "0.12.7" +$JarVersion = "0.12.6" $JarUrl = "https://github.com/DenisovAV/flutter_gemma/releases/download/v$JarVersion/$JarName" $JarChecksum = "fefc53d076533de164b5ce07c65f9aedc4739f83efc93e67625f0d90029ae5b7" $JarCacheDir = "$env:LOCALAPPDATA\flutter_gemma\jar" @@ -545,8 +545,8 @@ function Install-TfLite { New-Item -ItemType Directory -Force -Path $tfliteCacheDir | Out-Null New-Item -ItemType Directory -Force -Path $tfliteDir | Out-Null - # SHA256 checksum (fill from CI artifacts after build) - $tfliteChecksum = "" + # SHA256 checksum from CI build (TF 2.19.0) + $tfliteChecksum = "44fb8b282f7e4b36bbf2cc30171f2354dcfea04792e4092573de14908771afb8" $cachedDll = "$tfliteCacheDir\$tfliteArtifact" if (-not (Test-Path $cachedDll)) {