apple / ml-stable-diffusion

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

Support for negative prompts in Swift CLI #60

Open mfellner opened 1 year ago

mfellner commented 1 year ago

As far as I could see, the Swift CLI implementation currently doesn't support negative prompts.

In the Python implementation, the negative prompt argument is tokenised, encoded into uncond_embeddings, and prepended to the text embeddings of the regular prompt: https://github.com/apple/ml-stable-diffusion/blob/583cc04ece3dce9e1e8d44449f58d2eb7edef11c/python_coreml_stable_diffusion/pipeline.py#L145-L165

The Swift implementation on the other hand does not handle a negative prompt argument: https://github.com/apple/ml-stable-diffusion/blob/583cc04ece3dce9e1e8d44449f58d2eb7edef11c/swift/StableDiffusion/pipeline/StableDiffusionPipeline.swift#L76-L84

I don't really know how Stable Diffusion (v2) deals with negative prompts but how would one add support for them to the Swift implementation? The Core ML model seems to support it after all.

JustinMeans commented 1 year ago

I just opened a PR with the Swift implementation. See: #61