Your Name commited on
Commit
ff1b4cf
·
1 Parent(s): b8f54c5

updates readme

Browse files
Files changed (1) hide show
  1. README.md +106 -15
README.md CHANGED
@@ -6,28 +6,40 @@ tags:
6
  - LCM
7
  - stable-diffusion
8
  ---
9
- # Stable Diffusion 1.5 Latent Consistency Model for RKNN2
10
 
11
- Run the Stable Diffusion 1.5 LCM image generation model using RKNPU2!
12
 
13
- - Inference speed (RK3588, single NPU core):
14
- - 384x384: Text encoder 0.05s + U-Net 2.36s/it + VAE Decoder 5.48s
15
- - 512x512: Text encoder 0.05s + U-Net 5.65s/it + VAE Decoder 11.13s
16
- - Memory usage:
17
- - 384x384: About 5.2GB
18
- - 512x512: About 5.6GB
19
 
20
- ## Usage
21
 
22
- ### 1. Clone or download this repository to your local machine
23
 
24
- ### 2. Install dependencies
25
 
26
- ```bash
27
- pip install diffusers pillow numpy<2 rknn-toolkit-lite2
28
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- ### 3. Run
31
 
32
  ```bash
33
  python ./run_rknn-lcm.py -i ./model -o ./images --num-inference-steps 4 -s 512x512 --prompt "Majestic mountain landscape with snow-capped peaks, autumn foliage in vibrant reds and oranges, a turquoise river winding through a valley, crisp and serene atmosphere, ultra-realistic style."
@@ -35,6 +47,85 @@ python ./run_rknn-lcm.py -i ./model -o ./images --num-inference-steps 4 -s 512x5
35
 
36
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6319d0860d7478ae0069cd92/50jwBxv0Edf7x0WoHmpwi.png)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  ## Model Conversion
40
 
 
6
  - LCM
7
  - stable-diffusion
8
  ---
 
9
 
10
+ # Stable Diffusion 1.5 Latent Consistency Model (LCM-SD) for RKNN2
11
 
12
+ Run the **Stable Diffusion 1.5 Latent Consistency Model (LCM-SD)** on **Rockchip RKNPU2 (RK3588)** using RKNN2.
 
 
 
 
 
13
 
14
+ This repository supports **command-line inference** and a **production-ready HTTP server** optimized specifically for **LCM-SD**.
15
 
16
+ ---
17
 
18
+ ## Performance (RK3588, single NPU core)
19
 
20
+ | Resolution | Text Encoder | U-Net (per step) | VAE Decoder |
21
+ |-----------:|-------------:|-----------------:|------------:|
22
+ | 384×384 | ~0.05s | ~2.36s | ~5.48s |
23
+ | 512×512 | ~0.05s | ~5.65s | ~11–14s |
24
+
25
+ > NOTE: VAE decode latency is a known RKNN limitation and is not caused by layout, server, or postprocessing overhead.
26
+
27
+ ---
28
+
29
+ ## LCM-SD Optimizations & Quirks (Specific to This Repo)
30
+
31
+ - Correct tensor layouts:
32
+ - Text encoder: **NCHW**
33
+ - U-Net: **NHWC**
34
+ - VAE decoder: **NHWC**
35
+ - All RKNN runtime auto-conversion warnings eliminated
36
+ - One RKNN runtime context per worker (safe multi-context usage)
37
+ - Deterministic generation via explicit `numpy.RandomState(seed)`
38
+ - VAE decode slowness is a **known RKNN behavior** and unaffected by toolkit version
39
+
40
+ ---
41
 
42
+ ## Command-Line Usage (LCM-SD Only)
43
 
44
  ```bash
45
  python ./run_rknn-lcm.py -i ./model -o ./images --num-inference-steps 4 -s 512x512 --prompt "Majestic mountain landscape with snow-capped peaks, autumn foliage in vibrant reds and oranges, a turquoise river winding through a valley, crisp and serene atmosphere, ultra-realistic style."
 
47
 
48
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6319d0860d7478ae0069cd92/50jwBxv0Edf7x0WoHmpwi.png)
49
 
50
+ ## LCM-SD HTTP Server
51
+
52
+ ### Start the Server (Command Line)
53
+
54
+ ```bash
55
+ export MODEL_ROOT=./model
56
+ export NUM_WORKERS=3
57
+ export PORT=4200
58
+
59
+ python lcm_server.py
60
+ ```
61
+
62
+ The server listens on:
63
+
64
+ ```bash
65
+ http://0.0.0.0:4200
66
+ ```
67
+
68
+ ## Server Endpoints (LCM-SD Only)
69
+
70
+ ### POST /generate
71
+
72
+ Generate a PNG image using LCM-SD.
73
+
74
+ Request body (JSON):
75
+
76
+ ```json
77
+ {
78
+ "prompt": "a cinematic forest at sunrise",
79
+ "size": "512x512",
80
+ "num_inference_steps": 4,
81
+ "guidance_scale": 1.0,
82
+ "seed": 1234
83
+ }
84
+ ```
85
+
86
+ Response:
87
+ • HTTP 200
88
+ • Content-Type: image/png
89
+ • Binary PNG payload
90
+
91
+ ### curl Example (LCM-SD Server Only)
92
+
93
+ ```bash
94
+ curl -X POST http://node1.lan:4200/generate \
95
+ -H "Content-Type: application/json" \
96
+ -o output.png \
97
+ -d '{
98
+ "prompt": "a cinematic forest at sunrise",
99
+ "size": "512x512",
100
+ "num_inference_steps": 4,
101
+ "guidance_scale": 1.0,
102
+ "seed": 1234
103
+ }'
104
+ ```
105
+
106
+ ## Docker Usage (LCM-SD Server)
107
+
108
+ ### Build Image
109
+
110
+ ```bash
111
+ docker build \
112
+ -t rknn-lcm-sd .
113
+ ```
114
+
115
+ ### Run Container
116
+
117
+ ```bash
118
+ docker run --rm -it \
119
+ --device /dev/dri \
120
+ --device /dev/rknpu \
121
+ -v ./model:/models \
122
+ -e MODEL_ROOT=/models \
123
+ -e NUM_WORKERS=3 \
124
+ -p 4200:4200 \
125
+ rknn-lcm-sd
126
+ ```
127
+
128
+ Additionally, a docker-compose.yml is provided.
129
 
130
  ## Model Conversion
131