I made a local real-time webcam stream instruct editor with Flux.2-Klein model and bunch of custom optimizations.
The project is called Flux Real-Time (FluxRT) and can run with 30 FPS on one RTX 5090. 4090 and 3090 cards are also supported.
Flux.2-Klein-4B is a small AI diffusion model that takes several images as "references" along with the prompt. The prompt is instruction, e.g. "This man is now wearing this jacket".
But Flux is an image model. Generation of a single frame takes about 0.4 seconds on 5090.
To make it run in 30 FPS several things were added:
"Spatial-aware KV cache" that allows to recompute only small areas of frames where something has changed. This alone gives 1.5-2.5 speedup.
Frame interpolation that also works in real-time (like DLSS) and just multiplies FPS by a factor of 4.
Model compilation, shared memory buffers, multiprocessing, int8 quantization and other minor optimizations.
Gradio demo and some helpful scripts are already there.