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 from diffusers import Lumina2Transformer2DModel, Lumina2Pipeline
3from dfloat11 import DFloat11Model
4# from transformers.modeling_utils import no_init_weights # for transformers<5.0.0
5from transformers.initialization import no_init_weights # for transformers>=5.0.0
6
7with no_init_weights():
8 transformer = Lumina2Transformer2DModel.from_config(
9 Lumina2Transformer2DModel.load_config(
10 "neta-art/Neta-Lumina-diffusers", subfolder="transformer"
11 ),
12 torch_dtype=torch.bfloat16
13 ).to(torch.bfloat16)
14DFloat11Model.from_pretrained(
15 "mingyi456/Neta-Lumina-DF11",
16 device="cpu",
17 bfloat16_model=transformer,
18)
19pipe = Lumina2Pipeline.from_pretrained(
20 "neta-art/Neta-Lumina-diffusers",
21 transformer=transformer,
22 torch_dtype=torch.bfloat16
23)
24
25pipe.enable_model_cpu_offload()
26prompt = "You are an assistant designed to generate anime images based on textual prompts. <Prompt Start> 1girl, beautiful, detailed, high quality"
27negative_prompt = "You are an assistant designed to generate images based on textual prompts. <Prompt Start> A low quality, low resolution, ugly, and disgusting image with severe digital artifacts, blur, and noise. The subject is deformed, disfigured, and malformed, with bad anatomy, mutated limbs, and bad proportions. Features distorted, twisted, and unnatural hands and face, with extra or missing fingers. The style is amateurish, poorly drawn, childish, like a flat, unfinished sketch or a cheap, bad CGI render. The composition is bad, cropped, out of frame, and cluttered with text, watermarks, or signatures,"
28
29image = pipe(
30 prompt,
31 height=1024,
32 width=1024,
33 guidance_scale=5, # Increase guidance scale for better prompt adherence
34 num_inference_steps=50, # Increase inference steps for better quality
35 negative_prompt=negative_prompt,
36 generator=torch.Generator("cpu").manual_seed(114514)
37).images[0]
38image.save('image neta-lumina.png')pattern_dict for compression:1pattern_dict = {
2 r"noise_refiner\.\d+": (
3 "attn.to_q",
4 "attn.to_k",
5 "attn.to_v",
6 "attn.to_out.0",
7 "feed_forward.linear_1",
8 "feed_forward.linear_2",
9 "feed_forward.linear_3",
10 "norm1.linear"
11 ),
12 r"context_refiner\.\d+": (
13 "attn.to_q",
14 "attn.to_k",
15 "attn.to_v",
16 "attn.to_out.0",
17 "feed_forward.linear_1",
18 "feed_forward.linear_2",
19 "feed_forward.linear_3",
20 ),
21 r"layers\.\d+": (
22 "attn.to_q",
23 "attn.to_k",
24 "attn.to_v",
25 "attn.to_out.0",
26 "feed_forward.linear_1",
27 "feed_forward.linear_2",
28 "feed_forward.linear_3",
29 "norm1.linear"
30 ),
31 r"time_caption_embed\.caption_embedder": (
32 "1",
33 )
34}