Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/build-tflite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
28 changes: 17 additions & 11 deletions lib/desktop/flutter_gemma_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<int> tokenize(String text) {
Expand Down
18 changes: 11 additions & 7 deletions linux/scripts/setup_desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -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..."
Expand Down
6 changes: 3 additions & 3 deletions macos/scripts/prepare_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions macos/scripts/setup_desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions windows/scripts/setup_desktop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down
Loading