apple / ml-stable-diffusion

Stable Diffusion with Core ML on Apple Silicon
MIT License
16.79k stars 935 forks source link

How to modify or update the model weight in swift? #307

Open simon5u opened 9 months ago

simon5u commented 9 months ago

Hi, we are developing a swift app in ipad where we managed to load the stable diffusion model into the app, but we want to partially change the model weight when running the app. For example, we want to change different loras with base model SD1.5 on the fly, instead of compiling everything into coreml .mlmodel from beginning and load the model using loadedModel = try MLModel(contentsOf: modelURL, configuration: configuration). The latter is very slow every time we want to change a lora, it is not user friendly and the app is not very responsive.

Is it possible to update model weight using swift and functions given in mlmodel.h? The only related class is class var weights: MLParameterKey { get }, but there is no "set" method.

If not possible, is it we have to do it from scratch using objective c++?

Please advise. Thanks.

yyyoungman commented 9 months ago

Hi, we are developing a swift app in ipad where we managed to load the stable diffusion model into the app, but we want to partially change the model weight when running the app. For example, we want to change different loras with base model SD1.5 on the fly, instead of compiling everything into coreml .mlmodel from beginning and load the model using loadedModel = try MLModel(contentsOf: modelURL, configuration: configuration). The latter is very slow every time we want to change a lora, it is not user friendly and the app is not very responsive.

Is it possible to update model weight using swift and functions given in mlmodel.h? The only related class is class var weights: MLParameterKey { get }, but there is no "set" method.

If not possible, is it we have to do it from scratch using objective c++?

Please advise. Thanks.

@simon5u Hi, we are trying to do the same thing and haven't found a way yet. Did you mean it's possible to do this in objective c++? Could you please show how? Thanks!

Vimy commented 9 months ago

Did one of you find a solution?