Views
No views yet


| Task | Score |
|---|---|
| 🧠 GenEval | 0.83 |
| 🖼️ DPG-Bench | 83.7 |
| ✂️ GEditBench-EN | 6.31 |
| 🧪 ImgEdit-Bench | 3.95 |
1git clone https://github.com/SkyworkAI/UniPic
2cd UniPic-21conda create -n unipic python=3.10
2conda activate unipic
3pip install -r requirements.txt1import torch
2from PIL import Image
3from unipicv2.pipeline_stable_diffusion_3_kontext import StableDiffusion3KontextPipeline
4from unipicv2.transformer_sd3_kontext import SD3Transformer2DKontextModel
5from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
6from transformers import CLIPTextModelWithProjection, CLIPTokenizer, T5EncoderModel, T5TokenizerFast
7
8# Load model components
9pretrained_model_name_or_path = "Skywork/UniPic2-SD3.5M-Kontext-2B"
10
11transformer = SD3Transformer2DKontextModel.from_pretrained(
12 pretrained_model_name_or_path, subfolder="transformer", torch_dtype=torch.bfloat16).cuda()
13
14vae = AutoencoderKL.from_pretrained(
15 pretrained_model_name_or_path, subfolder="vae",
16 torch_dtype=torch.bfloat16, device_map="auto", low_cpu_mem_usage=True
17).cuda()
18
19# Load text encoders
20text_encoder = CLIPTextModelWithProjection.from_pretrained(
21 pretrained_model_name_or_path, subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="auto", low_cpu_mem_usage=True
22).cuda()
23tokenizer = CLIPTokenizer.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer")
24
25text_encoder_2 = CLIPTextModelWithProjection.from_pretrained(
26 pretrained_model_name_or_path, subfolder="text_encoder_2", torch_dtype=torch.bfloat16, device_map="auto", low_cpu_mem_usage=True
27).cuda()
28tokenizer_2 = CLIPTokenizer.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer_2")
29
30text_encoder_3 = T5EncoderModel.from_pretrained(
31 pretrained_model_name_or_path, subfolder="text_encoder_3", torch_dtype=torch.bfloat16, device_map="auto", low_cpu_mem_usage=True
32).cuda()
33tokenizer_3 = T5TokenizerFast.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer_3")
34
35scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(
36 pretrained_model_name_or_path, subfolder="scheduler"
37)
38
39# Create pipeline
40pipeline = StableDiffusion3KontextPipeline(
41 transformer=transformer, vae=vae,
42 text_encoder=text_encoder, tokenizer=tokenizer,
43 text_encoder_2=text_encoder_2, tokenizer_2=tokenizer_2,
44 text_encoder_3=text_encoder_3, tokenizer_3=tokenizer_3,
45 scheduler=scheduler)
46
47# Generate image
48image = pipeline(
49 prompt='a pig with wings and a top hat flying over a happy futuristic scifi city',
50 negative_prompt='blurry, low quality, low resolution, distorted, deformed, broken content, missing parts, damaged details, artifacts, glitch, noise, pixelated, grainy, compression artifacts, bad composition, wrong proportion, incomplete editing, unfinished, unedited areas.',
51 height=512, width=384,
52 num_inference_steps=50,
53 guidance_scale=3.5,
54 generator=torch.Generator(device=transformer.device).manual_seed(42)
55).images[0]
56
57image.save("text2image.png")
581# Load and preprocess image
2def fix_longer_edge(x, image_size, factor=32):
3 w, h = x.size
4 if w >= h:
5 target_w = image_size
6 target_h = h * (target_w / w)
7 target_h = round(target_h / factor) * factor
8 else:
9 target_h = image_size
10 target_w = w * (target_h / h)
11 target_w = round(target_w / factor) * factor
12 x = x.resize(size=(target_w, target_h))
13 return x
14
15image = Image.open("text2image.png")
16image = fix_longer_edge(image, image_size=512)
17
18negative_prompt = "blurry, low quality, low resolution, distorted, deformed, broken content, missing parts, damaged details, artifacts, glitch, noise, pixelated, grainy, compression artifacts, bad composition, wrong proportion, incomplete editing, unfinished, unedited areas."
19
20# Edit image
21edited_image = pipeline(
22 image=image,
23 prompt="remove the pig's hat",
24 negative_prompt=negative_prompt,
25 height=image.height, width=image.width,
26 num_inference_steps=50,
27 guidance_scale=3.5,
28 generator=torch.Generator(device=transformer.device).manual_seed(42)
29).images[0]
30
31edited_image.save("edited_img.png")
32@misc{wang2025skyworkunipicunifiedautoregressive,
title={Skywork UniPic: Unified Autoregressive Modeling for Visual Understanding and Generation},
author={Peiyu Wang and Yi Peng and Yimeng Gan and Liang Hu and Tianyidan Xie and Xiaokun Wang and Yichen Wei and Chuanxin Tang and Bo Zhu and Changshi Li and Hongyang Wei and Eric Li and Xuchen Song and Yang Liu and Yahui Zhou},
year={2025},
eprint={2508.03320},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2508.03320},
}
@misc{wei2025skyworkunipic20building,
title={Skywork UniPic 2.0: Building Kontext Model with Online RL for Unified Multimodal Model},
author={Hongyang Wei and Baixin Xu and Hongbo Liu and Cyrus Wu and Jie Liu and Yi Peng and Peiyu Wang and Zexiang Liu and Jingwen He and Yidan Xietian and Chuanxin Tang and Zidong Wang and Yichen Wei and Liang Hu and Boyi Jiang and William Li and Ying He and Yang Liu and Xuchen Song and Eric Li and Yahui Zhou},
year={2025},
eprint={2509.04548},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2509.04548},
}