web-stable-diffusion  by mlc-ai

Browser-based Stable Diffusion demo with no server support

created 2 years ago
3,674 stars

Top 13.5% on sourcepulse

GitHubView on GitHub
Project Summary

This project enables Stable Diffusion image generation directly within web browsers, eliminating the need for server-side infrastructure. It targets web developers and users seeking privacy-preserving, cost-effective AI image generation capabilities, leveraging client-side hardware for computation.

How It Works

The project utilizes Apache TVM Unity, a machine learning compilation framework, to convert Stable Diffusion models (specifically Runway's v1-5) into a WebAssembly runtime. It employs TorchDynamo and Torch FX for model capture, TVM's TensorIR and MetaSchedule for shader optimization, and Emscripten for WebAssembly compilation. This approach allows models to run natively on client GPUs via WebGPU, with optimized shaders and static memory planning for efficient browser execution.

Quick Start & Requirements

  • Install TVM Unity: pip3 install mlc-ai-nightly -f https://mlc.ai/wheels or build from source.
  • Prerequisites: Emscripten, Rust, wasm-pack, Jekyll, Chrome Canary.
  • Build & Deploy:
    • python3 build.py (for local GPU) or python3 build.py --target webgpu (for WebGPU).
    • ./scripts/local_deploy_site.sh for web deployment.
  • Demo: Run localhost:8888 in Chrome Canary with specific flags.
  • Documentation: Walkthrough Notebook

Highlighted Details

  • World's first Stable Diffusion implementation running entirely in the browser.
  • Leverages WebGPU for native GPU acceleration in web environments.
  • Python-first development workflow for model optimization and deployment.
  • Supports local GPU runtime deployment for comparison and native use.

Maintenance & Community

  • Actively developed within the Apache TVM ecosystem.
  • Benefits from contributions from the Hugging Face, PyTorch, WebAssembly, and Rust communities.
  • Related project: Web LLM.

Licensing & Compatibility

  • Primarily licensed under Apache-2.0 (TVM Unity).
  • Compatible with commercial use and closed-source linking, as the core runtime is WebAssembly.

Limitations & Caveats

  • WebGPU is still evolving and may require specific browser versions (Chrome Canary) and flags (--enable-dawn-features=disable_robustness) for optimal performance.
  • Requires a GPU with at least 8GB of RAM.
  • Performance on Apple Silicon via WebGPU shows a ~3x degradation compared to native GPU without specific flags due to robustness checks.
  • Only tested on Apple Silicon; broader platform compatibility is not guaranteed.
Health Check
Last commit

1 year ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
24 stars in the last 90 days

Explore Similar Projects

Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Georgios Konstantopoulos Georgios Konstantopoulos(CTO, General Partner at Paradigm), and
2 more.

gpu.cpp by AnswerDotAI

0.2%
4k
C++ library for portable GPU computation using WebGPU
created 1 year ago
updated 2 weeks ago
Starred by Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), and
2 more.

serve by pytorch

0.1%
4k
Serve, optimize, and scale PyTorch models in production
created 5 years ago
updated 3 weeks ago
Feedback? Help us improve.