我们推出了LongCat-Image-Edit-Turbo,它是LongCat-Image-Edit的蒸馏版本。该模型仅需8次函数评估(NFE,Number of Function Evaluations)即可实现高质量图像编辑,推理延迟极低。
pip install git+https://github.com/huggingface/diffusers[!CAUTION] 📝 文本渲染的特殊处理
对于涉及文本生成的文本到图像和图像编辑任务,必须将目标文本用单引号或双引号括起来(支持英文 '...' / "..." 和中文 ‘...’ / “...” 格式)。
原因:模型对引号内的内容采用专门的字符级编码策略。若未使用明确的引号,将无法触发此机制,从而严重影响文本渲染效果。
import torch
from PIL import Image
from diffusers import LongCatImageEditPipeline
if __name__ == '__main__':
device = torch.device('cuda')
pipe = LongCatImageEditPipeline.from_pretrained("meituan-longcat/LongCat-Image-Edit-Turbo", torch_dtype= torch.bfloat16 )
# pipe.to(device, torch.bfloat16) # Uncomment for high VRAM devices (Faster inference)
pipe.enable_model_cpu_offload() # Offload to CPU to save VRAM (Required ~18 GB); slower but prevents OOM
img = Image.open('assets/test.png').convert('RGB')
prompt = '将猫变成狗'
image = pipe(
img,
prompt,
negative_prompt='',
guidance_scale=1,
num_inference_steps=8,
num_images_per_prompt=1,
generator=torch.Generator("cpu").manual_seed(43)
).images[0]
image.save('./edit_example.png')