mingyi456's picture
Update README.md
5242ec6 verified
|
Raw
History Blame Contribute Delete
3.8 kB
metadata
license: other
license_name: nvidia-open-model-license
license_link: >-
  https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license/
language:
  - en
pipeline_tag: text-to-image
tags:
  - diffusion-single-file
base_model:
  - nvidia/Cosmos-Predict2-2B-Text2Image
base_model_relation: quantized
library_name: diffusers

For more information (including how to compress models yourself), check out https://huggingface.co/DFloat11 and https://github.com/LeanModels/DFloat11

Feel free to request for other models for compression as well (for either the diffusers library, ComfyUI, or any other model), although models that use architectures which are unfamiliar to me might be more difficult.

How to Use

diffusers

import torch
from diffusers import Cosmos2TextToImagePipeline, CosmosTransformer3DModel
from dfloat11 import DFloat11Model
# from transformers.modeling_utils import no_init_weights # for transformers version < 5.0.0
from transformers.initialization import no_init_weights # for transformers version >= 5.0.0
with no_init_weights():
    transformer = CosmosTransformer3DModel.from_config(
        CosmosTransformer3DModel.load_config(
            "nvidia/Cosmos-Predict2-2B-Text2Image", subfolder="transformer"
        ),
        torch_dtype=torch.bfloat16
    ).to(torch.bfloat16)
DFloat11Model.from_pretrained(
    "mingyi456/Cosmos-Predict2-2B-Text2Image-DF11",
    device="cpu",
    bfloat16_model=transformer,
)
pipe = Cosmos2TextToImagePipeline.from_pretrained(
    "nvidia/Cosmos-Predict2-2B-Text2Image",
    transformer=transformer, 
    torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess."
negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
image = pipe(
    prompt,
    negative_prompt=negative_prompt,
    max_sequence_length=256,
    generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save("Cosmos-Predict2-2B-Text2Image.png")

ComfyUI

Refer to this model instead.

Compression details

This is the pattern_dict for compression:

pattern_dict={
    r"transformer_blocks\.\d+": (
        "norm1.linear_1",
        "norm1.linear_2",
        "attn1.to_q",
        "attn1.to_k",
        "attn1.to_v",
        "attn1.to_out.0",
        "norm2.linear_1",
        "norm2.linear_2",
        "attn2.to_q",
        "attn2.to_k",
        "attn2.to_v",
        "attn2.to_out.0",
        "norm3.linear_1",
        "norm3.linear_2",
        "ff.net.0.proj",
        "ff.net.2"
    ),
    r"time_embed\.t_embedder": (
        "linear_1",
        "linear_2",
    )
}