Views
No views yet
6.48% on SD3.5-large and 7.75% on HunyuanImage-2.1, while adding only about 0.00002x block-level FLOPs for base reinjection and 0.088x for the full aligned variant.prompt forgetting.


3.10+ and one environment per model family.1python3.10 -m venv .venv
2source .venv/bin/activate
3pip install --upgrade pippip install -e .pip install -r requirements.txt1pip install -r requirements/sd3.txt
2pip install -r requirements/sd3.5.txt
3pip install -r requirements/flux.txt
4pip install -r requirements/qwen.txt
5pip install -r requirements/hunyuanimage.txttorch and torchvision first from the official PyTorch channel, then rerun one of the commands above.requirements/hunyuanimage.txt:1git clone https://github.com/Tencent-Hunyuan/HunyuanImage-2.1.git
2pip install -r HunyuanImage-2.1/requirements.txt
3pip install flash-attn==2.7.3 --no-build-isolation
4pip install -r requirements/hunyuanimage.txt--model-path in open-source usage.sd3, sd3.5, flux, qwen: --model-path /path/to/modelhunyuanimage: --model-path /path/to/HunyuanImage-2.1 and optional --model-namehunyuanimage, --model-path can point either to the HunyuanImage runtime root or to its ckpts directory.1bash prompt_reinjection/test_reinjection.sh \
2 --model sd3 \
3 --model-path /path/to/SD3 \
4 --prompt "A photo of a couch below a potted plant."--model values: sd3, sd3.5, flux, qwen, hunyuanimage.1bash prompt_reinjection/test_reinjection.sh \
2 --model sd3 \
3 --model-path /path/to/SD3 \
4 --prompt "A photo of a couch below a potted plant." \
5 --reinjection offflux and qwen: pass --cpu-offload model or --cpu-offload sequentialflux and qwen: optionally add --vae-slicing, --vae-tiling, or --attention-slicing autohunyuanimage: pass --enable-offload1bash prompt_reinjection/test_reinjection.sh \
2 --model flux \
3 --model-path /path/to/FLUX.1-dev \
4 --prompt "A photo of a couch below a potted plant." \
5 --cpu-offload model \
6 --vae-slicing1python -m prompt_reinjection.run_sample \
2 --model sd3 \
3 --model-path /path/to/SD3 \
4 --prompt "A photo of a couch below a potted plant." \
5 --output outputs/manual_sd3.png \
6 --steps 28 \
7 --cfg 7.0 \
8 --residual_origin_layer 1 \
9 --residual_target_layers $(seq 2 23) \
10 --residual_weights 0.025 \
11 --residual_use_anchoring 1 \
12 --residual_procrustes_path prompt_reinjection/rotations/sd3_coco5k_o1.pt--cpu-offload model or --cpu-offload sequential, and HunyuanImage only enables its runtime offload when you pass --enable-offload.sd3 and flux: use the released Procrustes-aligned Prompt Reinjection settings.sd3.5, qwen, and hunyuanimage: use the most basic Prompt Reinjection variant without anchoring and without rotation. It already works well and adds almost zero inference cost.1python SD3/compute.py \
2 --model /path/to/SD3 \
3 --dataset coco \
4 --datadir data \
5 --num-samples 5000 \
6 --origin-layer 1 \
7 --target-layer-start 2 \
8 --col-center \
9 --output outputs/procrustes_rotations/sd3_coco5k_o1.pt1python FLUX/compute.py \
2 --model /path/to/FLUX.1-dev \
3 --dataset coco \
4 --datadir data \
5 --num-samples 5000 \
6 --origin-layer 2 \
7 --target-layer-start 3 \
8 --col-center \
9 --output outputs/procrustes_rotations/flux_coco5k_o2.ptprompt_reinjection/rotations/ with:1hf download LewisYao/PromptReinjection \
2 sd3_coco5k_o1.pt \
3 flux_coco5k_o2.pt \
4 --local-dir prompt_reinjection/rotationsprompt_reinjection/rotations/.--reinjection on. Use --reinjection off for the plain base model, or edit the config file if you want to change the released settings globally.1python -m prompt_reinjection.run_geneval \
2 --model sd3 \
3 --model-path /path/to/SD3 \
4 --metadata_file /path/to/geneval/metadata.jsonl \
5 --outdir outputs/geneval_sd31python -m prompt_reinjection.run_geneval \
2 --model sd3 \
3 --model-path /path/to/SD3 \
4 --metadata_file /path/to/geneval/metadata.jsonl \
5 --outdir outputs/geneval_sd3_base \
6 --reinjection off1python -m prompt_reinjection.run_dpg \
2 --model sd3.5 \
3 --model-path /path/to/SD3.5-large \
4 --prompt_dir /path/to/dpg/prompts \
5 --save_dir outputs/dpg_sd351python -m prompt_reinjection.run_t2i \
2 --model qwen \
3 --model-path /path/to/Qwen-Image \
4 --dataset_dir /path/to/t2i-compbench/prompts \
5 --outdir_base outputs/t2i_qwenadapter.py that implements the adapter interface used in prompt_reinjection/adapter_api.py and follows the existing examples in SD3/adapter.py, FLUX/adapter.py, and Qwen/adapter.py.set_residual_config(...) so it can receive residual_origin_layer, residual_target_layers, residual_weights, residual_use_anchoring, and residual_rotation_matrices, as shown in SD3/pipeline.py, FLUX/pipeline.py, and Qwen/pipeline.py.run_sample, run_geneval, run_dpg, run_t2i, and compute_procrustes.compute.py and expose it as the adapter’s compute_script, so python -m prompt_reinjection.compute_procrustes --model YOUR_MODEL ... can dispatch correctly.origin = 1target = 2-lastweight = 0.025no anchoringno rotationL blocks indexed from 0 to L-1, the default starting rule is:1residual_origin_layer = 1
2residual_target_layers = [2, 3, ..., L-1]
3residual_weights = 0.025
4residual_use_anchoring = 0
5residual_procrustes_path = ""1python -m prompt_reinjection.run_sample \
2 --model your_model \
3 --model-path /path/to/your/model \
4 --prompt "A photo of a couch below a potted plant." \
5 --output outputs/your_model_base_reinjection.png \
6 --residual_origin_layer 1 \
7 --residual_target_layers $(seq 2 LAST_LAYER) \
8 --residual_weights 0.025 \
9 --residual_use_anchoring 0 \
10 --residual_procrustes_path ""LAST_LAYER with the last text-processing block index of your model. For example, if the model has 24 blocks indexed from 0 to 23, use $(seq 2 23).--residual_use_anchoring 1. This is usually the safest first upgrade when the model shows cross-layer scale or shift mismatch.--residual_procrustes_path. This is useful when shallow and deep text features differ not only in scale, but also in feature geometry.1@inproceedings{yao2026prompt,
2 title={Prompt Reinjection: Alleviating Prompt Forgetting in Multimodal Diffusion Transformers},
3 author={Yao, Yuxuan and Chen, Yuxuan and Li, Hui and Cheng, Kaihui and Guo, Qipeng and Sun, Yuwei and Dong, Zilong and Wang, Jingdong and Zhu, Siyu},
4 booktitle={International Conference on Machine Learning (ICML)},
5 year={2026}
6}