CodecOPSD-H3-Image / README.md
HikariDawn's picture
Link Space demo
aa4c4c2 verified
|
Raw History Blame Contribute Delete
5.82 kB
---
license: other
license_name: minimax-h3-image-community-license-agreement
license_link: LICENSE
base_model: MiniMaxAI/MiniMax-H3-Image
base_model_relation: adapter
pipeline_tag: image-to-image
language:
- en
tags:
- lora
- image-generation
- reference-to-image
- token-pruning
- distillation
- minimax-h3
---
<div align="center">
<img width="100%" src="assets/codecopsd_header.gif" alt="CodecOPSD">
</div>
<p align="center">
<a href="https://github.com/Kiteretsu77/CodecOPSD" target="_blank"><img src="https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white" alt="GitHub"></a>
<a href="https://kiteretsu77.github.io/CodecOPSD_website/" target="_blank"><img src="https://img.shields.io/badge/Project%20Page-E91E63?logo=googlechrome&logoColor=white" alt="Project Page"></a>
<a href="https://arxiv.org/abs/2611.31184" target="_blank"><img src="https://img.shields.io/badge/arXiv-2611.31184-b31b1b?logo=arxiv&logoColor=white" alt="Paper"></a>
<a href="https://huggingface.co/spaces/HikariDawn/CodecOPSD-H3-Image" target="_blank"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Space-Demo-FF9D00" alt="Space"></a>
<a href="https://huggingface.co/collections/HikariDawn/codecopsdopsd-6b04b49f98f5b4b68c5f7f9a"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Models-FFD21E" alt="Models"></a>
</p>
# CodecOPSD-H3-Image
**On-Policy Codec Distillation for Efficient All-in-One Video Generation**
Sequence-wise generators (MiniMax-H3 Ref2VA, MiniMax-H3-Image, Qwen-Image 2.1, FLUX 3 Image Klein) append every
reference picture or video to the input token sequence, so the token cost grows sharply as more references are added.
We propose **CodecOPSD** to prune the redundant condition tokens with a video codec, and we train a small LoRA on the
kept tokens via on-policy self-distillation.
On average, CodecOPSD drops about 70% of the condition tokens on MiniMax-H3 Ref2VA with almost unchanged quality and
1.87x faster denoising, and up to 8.4x faster with more conditions (three reference videos, higher-resolution
references, more frames, and a higher drop rate).
On MiniMax-H3-Image, it drops about 65% of the reference tokens and makes denoising about 2x faster.
This repo holds the CodecOPSD LoRA for **MiniMax-H3-Image** (reference-to-image generation).
⭐ **If you like CodecOPSD, please help ⭐⭐star⭐⭐ the [GitHub repo](https://github.com/Kiteretsu77/CodecOPSD). Thanks!** 🤗
## Model Variants
| Variant | Base model | Task | Weights |
|---|---|---|---|
| **CodecOPSD-H3-Ref2VA** | [MiniMax-H3](https://huggingface.co/MiniMaxAI/MiniMax-H3) Ref2VA | Reference-to-video generation | [HikariDawn/CodecOPSD-H3-Ref2VA](https://huggingface.co/HikariDawn/CodecOPSD-H3-Ref2VA) |
| **CodecOPSD-H3-Image** (this repo) | [MiniMax-H3-Image](https://huggingface.co/MiniMaxAI/MiniMax-H3-Image) | Reference-to-image generation | [HikariDawn/CodecOPSD-H3-Image](https://huggingface.co/HikariDawn/CodecOPSD-H3-Image) |
| CodecOPSD on Cosmos 3 Nano | Cosmos 3 Nano | | Coming soon |
| CodecOPSD on Qwen-Image 2.1 | Qwen-Image 2.1 | | Coming soon |
| CodecOPSD on FLUX 3 Image Klein | FLUX 3 Image Klein | | Coming soon |
## Gallery
<a href="https://kiteretsu77.github.io/CodecOPSD_website/#gallery-h3img" target="_blank"><img src="assets/gallery_image.jpg" width="100%" alt="CodecOPSD MiniMax-H3-Image gallery"></a>
Click the gallery to open it on the <a href="https://kiteretsu77.github.io/CodecOPSD_website/#gallery-h3img" target="_blank">project page</a>.
## Run it
Install the [CodecOPSD code](https://github.com/Kiteretsu77/CodecOPSD) and download the base models into `models/`:
```bash
git clone https://github.com/Kiteretsu77/CodecOPSD.git && cd CodecOPSD
pip install -e ".[app]"
python -m codecopsd.download minimax_h3_image --no-examples
python app.py ref2image # Gradio demo
```
The CodecOPSD pipeline is a diffusers `DiffusionPipeline` on diffusers' own MiniMax-H3 modules, with codec pruning in
front of the transformer:
```python
import torch
from PIL import Image
from codecopsd import MiniMaxH3ImageCodecOPSDPipeline
pipe = MiniMaxH3ImageCodecOPSDPipeline.from_minimax_h3_image(
"models/MiniMax-H3-Image", text_encoder_fp8="fp8",
text_encoder_path="models/MiniMax-H3-ModelOpt-Mixed9-Dynamic-FP8/Ref2VA/text_encoder")
pipe.load_condition_lora("HikariDawn/CodecOPSD-H3-Image", weight_name="codecopsd_minimax_h3_image.safetensors")
pipe.enable_model_cpu_offload()
image = pipe(
prompt="Put the lamp <Picture 1> on the desk in <Picture 2>.",
images=[Image.open("lamp.jpg"), Image.open("desk.jpg")],
generator=torch.Generator().manual_seed(42),
).images[0]
image.save("output.png")
```
## Weights
| File | Base trunk | Format |
|---|---|---|
| `codecopsd_minimax_h3_image.safetensors` | MiniMax-H3-Image `transformer_diffusers` | FP32 LoRA, rank / alpha 128, 2.6 GB |
| `config.json` | | Base model, LoRA rank and alpha, version |
| `LICENSE`, `NOTICE` | | The MiniMax-H3-Image Community License Agreement and its required notice |
## License
These LoRA weights are Model Derivatives of MiniMax-H3-Image and are distributed under the
[MiniMax-H3-Image Community License Agreement](https://huggingface.co/MiniMaxAI/MiniMax-H3-Image/blob/492fd8c4eca666f1085f57e30738c1e0d86b3439/LICENSE).
See [NOTICE](NOTICE) for the required MiniMax notice and the CodecOPSD authors' copyright statement. The CodecOPSD code
is on [GitHub](https://github.com/Kiteretsu77/CodecOPSD) under its own license.
## Citation
```bibtex
@article{wang2026codecopsd,
title = {On-Policy Codec Distillation for Efficient All-in-One Video Generation},
author = {Wang, Boyang and Blackburn-Matzen, Kevin and Saha, Oindrila and Gadelha, Matheus and Cheng, Zezhou},
journal = {arXiv preprint arXiv:2611.31184},
year = {2026}
}
```