Giter VIP home page Giter VIP logo

swift-coreml-diffusers's Introduction

Diffusion

This is a simple app that shows how to integrate Apple's Core ML Stable Diffusion implementation in a native Swift UI application. It can be used for faster iteration, or as sample code for other use cases.

This is what it looks like: App Screenshot

On first launch, the application downloads a zipped archive with a Core ML version of Runway's Stable Diffusion v1.5, from this location in the Hugging Face Hub. This process takes a while, as several GB of data have to be downloaded and unarchived.

For faster inference, we use a very fast scheduler: DPM-Solver++ that we ported to Swift. Since this scheduler is still not available in Apple's GitHub repository, the application depends on the following fork instead: https://github.com/pcuenca/ml-stable-diffusion. Our Swift port is based on Diffusers' DPMSolverMultistepScheduler, with a number of simplifications.

Compatibility

  • macOS Ventura 13.1, iOS/iPadOS 16.2, Xcode 14.2.
  • Performance (after initial generation, which is slower)
    • ~10s in macOS on MacBook Pro M1 Max (64 GB).
    • ~1 min 15s in iPhone 14 Pro.

Limitations

  • The UI does not expose a way to configure the scheduler, number of inference steps, or generation seed. These are all available in the underlying code.
  • A single model (Stable Diffusion v1.5) is considered. The Core ML compute units have been hardcoded to CPU and GPU, since that's what gives best results on my Mac (M1 Max MacBook Pro).
  • Sometimes generation returns a nil image. This needs to be investigated.

Next Steps

  • Improve UI. Allow the user to select generation parameters.
  • Allow other models to run. Provide a recommended "compute units" configuration based on model and platform.
  • Implement other interesting schedulers.
  • Implement negative prompts.
  • Explore other features (image to image, for example).

swift-coreml-diffusers's People

Contributors

pcuenca avatar julien-c avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.