Views
No views yet
diffusers library, ComfyUI, or any other model), although models that use architectures which are unfamiliar to me might be more difficult.diffusers1import torch
2from diffusers import LongCatImageEditPipeline, LongCatImageTransformer2DModel
3
4# for newer versions of `transformers`, it seems that from transformers.initialization import no_init_weights is required instead
5from transformers.modeling_utils import no_init_weights
6
7with no_init_weights():
8 transformer = LongCatImageTransformer2DModel.from_config(
9 LongCatImageTransformer2DModel.load_config(
10 "meituan-longcat/LongCat-Image-Edit-Turbo", subfolder="transformer"
11 ),
12 torch_dtype=torch.bfloat16
13 ).to(torch.bfloat16)
14DFloat11Model.from_pretrained(
15 "mingyi456/LongCat-Image-Edit-Turbo-DF11",
16 device="cpu",
17 bfloat16_model=transformer,
18)
19pipe = LongCatImageEditPipeline.from_pretrained(
20 "meituan-longcat/LongCat-Image-Edit-Turbo",
21 transformer=transformer,
22 torch_dtype=torch.bfloat16
23)
24DFloat11Model.from_pretrained(
25 "mingyi456/Qwen2.5-VL-7B-Instruct-DF11",
26 device="cpu",
27 bfloat16_model=pipe.text_encoder,
28)
29pipe.enable_model_cpu_offload()
30img = Image.open('assets/test.png').convert('RGB')
31prompt = '将猫变成狗'
32image = pipe(
33 img,
34 prompt,
35 negative_prompt='',
36 guidance_scale=1.0,
37 num_inference_steps=8,
38 num_images_per_prompt=1,
39 generator=torch.Generator("cpu").manual_seed(43)
40).images[0]
41image.save('image longcat-image-edit.png')pattern_dict for compression:1pattern_dict = {
2 r"transformer_blocks\.\d+": (
3 "norm1.linear",
4 "norm1_context.linear",
5 "attn.to_q",
6 "attn.to_k",
7 "attn.to_v",
8 "attn.to_out.0",
9 "attn.add_q_proj",
10 "attn.add_k_proj",
11 "attn.add_v_proj",
12 "attn.to_add_out",
13 "ff.net.0.proj",
14 "ff.net.2",
15 "ff_context.net.0.proj",
16 "ff_context.net.2",
17 ),
18 r"single_transformer_blocks\.\d+": (
19 "norm.linear",
20 "proj_mlp",
21 "proj_out",
22 "attn.to_q",
23 "attn.to_k",
24 "attn.to_v",
25 ),
26}