DenisovAV / flutter_gemma

The Flutter plugin allows running the Gemma AI model locally on a device from a Flutter application.
MIT License
55 stars 17 forks source link

Failed to build iOS app #5

Open edenko opened 5 months ago

edenko commented 5 months ago

image

Is there another way? I added the settings to the main, but what am I missing?


import Foundation import MediaPipeTasksGenAI

final class InferenceModel { private var inference: LlmInference!

init(maxTokens: Int, temperature: Float, randomSeed: Int, topK: Int) {
    let fileManager = FileManager.default
    let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
    let filePath = documentDirectory.appendingPathComponent("model.bin").path

    do {
        let llmOptions = LlmInference.Options(modelPath: filePath)
        llmOptions.maxTokens = maxTokens
        llmOptions.temperature = temperature
        llmOptions.randomSeed = randomSeed
        llmOptions.topk = topK
        self.inference = try LlmInference(options: llmOptions)
    } catch {
        print("Failed to initialize LlmInference: \(error)")
    }
}

func generateResponse(prompt: String) throws -> String {
    return try inference.generateResponse(inputText: prompt)
}

func generateResponseAsync(prompt: String, progress: @escaping (_ partialResponse: String?, _ error: Error?) -> Void, completion: @escaping (() -> Void)) throws {
    do {
        try inference.generateResponseAsync(inputText: prompt, progress: progress, completion: completion)
    } catch {
        throw error
    }
}

}

This is a build

DenisovAV commented 5 months ago

Do you run an example or your own project? Could you tell me your XCode and MacOS versions? I have no such error.

edenko commented 5 months ago

I am running my own project. My Xcode version is 15.4 (15F31d) and macOS version is 14.1.2.

hypen-flutter commented 2 months ago

Same issue. Mac 15.0, Xcode 16.0

DenisovAV commented 1 month ago

please check 0.2.2 version

dsx1986 commented 1 month ago

I am using 0.2.2 and I got similar error:

Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'temperature' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.2/ios/Classes/InferenceModel.swift:13:19

Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'randomSeed' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.2/ios/Classes/InferenceModel.swift:14:19

Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'topk' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.2/ios/Classes/InferenceModel.swift:15:19

DenisovAV commented 1 month ago

I looks like the rootcause in an incompatibility of mediapipe version, I fixed the version at 0.2.3, please try

dsx1986 commented 1 month ago

The error is the same: Failed to build iOS app Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'temperature' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.3/ios/Classes/InferenceModel.swift:13:19

Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'randomSeed' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.3/ios/Classes/InferenceModel.swift:14:19

Swift Compiler Error (Xcode): Value of type 'LlmInference.Options' has no member 'topk' /Users/simon/.pub-cache/hosted/pub.dev/flutter_gemma-0.2.3/ios/Classes/InferenceModel.swift:15:19

Encountered error while archiving for device.

DenisovAV commented 1 month ago

Can you share Podfile.lock with me, to check version number of MediaPipeTasksGenAI

dsx1986 commented 1 month ago

flutter_gemma: dependency: "direct main" description: name: flutter_gemma sha256: f0ebe363161599fdc69df47cfc07bec317e20a502a47959aecd14e1c9cfc17ca url: "https://pub.dev" source: hosted version: "0.2.3"

Installing MediaPipeTasksGenAI (0.10.16)

Installing MediaPipeTasksGenAIC (0.10.16)

DenisovAV commented 1 month ago

It should be MediaPipeTasksGenAI (0.10.12) as in configuration, try to do flutter clean, delete Podfile.lock, run flutter pub get again and check. Probably this is a cached version

DenisovAV commented 1 month ago

I'm going to update the version of MediaPipeTasksGenAI to the latest one, but it will be in a couple of weeks, after downloading model implemetation

dsx1986 commented 1 month ago

It should be MediaPipeTasksGenAI (0.10.12) as in configuration, try to do flutter clean, delete Podfile.lock, run flutter pub get again and check. Probably this is a cached version

Yes, I deleted local pub cache and Cocoa pods cache, and build foldler, Podfile.lock. It is still installing 0.10.16 version:

Installing MediaPipeTasksGenAI (0.10.16) Installing MediaPipeTasksGenAIC (0.10.16)

DenisovAV commented 1 month ago

I hard fixed the version in 0.2.4 could you please try?

dsx1986 commented 1 month ago

yes, it is working. it has some version conflict with flutter_secure_storage but I avoid using flutter_secure_storage and now it is working on android.

dsx1986 commented 1 month ago

ios run successful. I put my model in cloud and download it to device when need it. Right now we have to rename model name to model.bin to make it work, can you change the interface to allow file name

dsx1986 commented 1 month ago

cpu version is too slow on physical device. Is there option to enable GPU?

DenisovAV commented 1 month ago

In the next version, you will be able to use a model from the cloud out of the box, I will publish it today. Regarding GPU, try to use GPU model.

image
dsx1986 commented 1 month ago

thanks. I have gpu model and tried, now it works both on simulator and physical device for both CPU and GPU

DenisovAV commented 1 month ago

I checked my physical device, everything is fine, I have iPhone 14 Pro. and btw check 0.3.0, there is implemented upload model feature

DenisovAV commented 3 hours ago

@dsx1986 can you check with the last version of the plugin?