WeGen2中文

WeGen2 inference guide

English overview · Project Page · Weights · 中文使用说明

Quick start

1. Install

Use Python 3.10 or later. Install matching builds of PyTorch and torchvision for your inference device, then install WeGen2 in the same environment. The code and weights currently require repository access.

git clone https://github.com/zhuangshaobin/WeGen2.git
cd WeGen2
python -m pip install -e .

2. Download both models

One download includes WeGen2 and Qwen3-VL-30B-A3B-Instruct. The latter reads the request and its references, then supplies an instruction to WeGen2. Both models use BF16 weights.

hf auth login
hf download GrayShine/WeGen2 --local-dir ./weights/WeGen2

The download puts the image model and its prompt enhancer in this layout:

weights/WeGen2/
├── config.json
├── tokenizer.json
├── model.safetensors.index.json
├── model-*.safetensors
└── prompt_enhancer/
    ├── config.json
    ├── preprocessor_config.json
    ├── tokenizer.json
    └── *.safetensors

If you already have the WeGen2 checkpoint, download only the enhancer:

hf download GrayShine/WeGen2 --include 'prompt_enhancer/*' --local-dir ./weights/WeGen2

Allow about 186 GB of disk space for the weights, plus space for outputs and caches. The enhancer loads locally on the first image request and stays loaded for subsequent edits. Its weights alone occupy about 58 GiB. It defaults to CPU memory. For faster decoding, set the global option --pe-device (or Python’s pe_device) to a BF16-capable accelerator with enough free memory for the weights and working space. Use --devices separately to place WeGen2.

Write the intended change in ordinary language. Quote text that must appear verbatim. For an edit, name what should stay the same. For a composition, give the references in order and describe what each supplies.

3. Generate an image

wegen2 --model ./weights/WeGen2 --devices auto generate \
  --prompt "A luminous underwater opera house, elaborate coral architecture, cinematic lighting" \
  --size 1024 1024 --seed 42 --output ./outputs/opera.png

Image editing

wegen2 --model ./weights/WeGen2 --devices auto generate \
  --image ./input.png \
  --prompt "Change the red mug to cobalt blue. Preserve the table, napkin, lighting, and composition." \
  --size 512 512 --seed 42 --output ./outputs/edit.png

Reference images keep their aspect ratio, subject to patch alignment and the reference pixel budget. Output sizes are WIDTH HEIGHT; both dimensions must be multiples of 32.

Multiple references

Supply references in the order used by your instruction:

wegen2 --model ./weights/WeGen2 --devices auto generate \
  --image ./subject.png --image ./setting.png \
  --prompt "Place the subject from the first image in the setting of the second image." \
  --size 1024 768 --output ./outputs/composition.png

The model accepts more than two references. Reference count and image size increase memory use and context length.

Multi-turn creation

wegen2 --model ./weights/WeGen2 --devices auto sequence \
  --request ./examples/story.json --output ./outputs/story

A JSON request lists ordered turns. Each generated image becomes context for the next turn; no manual image path is needed between turns. Additional images paths are resolved relative to the request file. The output directory must be new. Each image turn records the original prompt, the instruction passed to WeGen2, and the output filename in results.json. The enhancer receives the previous image and recent conversation on follow-up edits. Start a new session (or call session.reset()) for an unrelated image. Each call to pipe.generate(...) already starts a fresh session.

[
  { "prompt": "A small fox beside a lighthouse at sunset.", "size": [1024, 768] },
  { "prompt": "Add a red sailboat at the dock. Preserve the fox and lighthouse.", "size": [1024, 768] }
]

Python API

from wegen2 import SamplingConfig, WeGen2Pipeline

pipe = WeGen2Pipeline.from_pretrained("./weights/WeGen2", devices="auto")

image = pipe.generate(
    "A cinematic underwater opera house, intricate coral architecture.",
    size=(1024, 1024),
    sampling=SamplingConfig(seed=42),
)
image.save("opera.png")

session = pipe.session()
first = session.generate("A glossy blue mug beside a white napkin on an oak table.")
second = session.generate("Add a lemon to the right of the mug. Preserve the scene.")
third = session.generate("Place a silver spoon on the napkin. Keep the mug and lemon.")
third.save("third-turn.png")
session.reset()

For a single edit, pass images=["input.png"] to pipe.generate(...). For multiple references, pass an ordered list. If omitted, sampling uses text guidance 4.0 and 50 schedule points (49 Euler updates); reference-conditioned requests select the corresponding guidance rescaling automatically. A fixed seed supports reproducibility within the same runtime and device configuration.