CoolFace
Modelpublic

WaveCut/Cosmos3-Super-Text2Image-ModelOpt-FP8-Transformer

sourceHugging Faceotherupdated 4mo agoView on Hugging Face
0likes
Model Card

Cosmos3-Super-Text2Image NVIDIA ModelOpt FP8 Transformer

This repository contains a transformer-only NVIDIA ModelOpt FP8 quantization for nvidia/Cosmos3-Super-Text2Image.

It does not repeat the original model card. Read NVIDIA's model card, prompt-format guidance, license, and safety notes here: nvidia/Cosmos3-Super-Text2Image.

Only transformer/ is provided as a weight artifact. The VAE, scheduler, tokenizers, safety checker, and other components are loaded from the base model.

Recipe

SettingValue
QuantizerNVIDIA ModelOpt
ModelOpt version0.44.0
Quant typeFP8_DEFAULT_CFG
Weight-onlyTrue
CompressedTrue
Quantized modules inserted2709
Quantization time1.34s
Compress time0.45s
Save time65.99s
Transformer checkpoint size61.06 GiB

The checkpoint includes ModelOpt state in transformer/modelopt_state.pth.

Assemble The Pipeline

Install ModelOpt in the same environment as Diffusers:

bash
pip install "nvidia_modelopt[hf]"

The current tested runtime requires a small compatibility helper for ModelOpt QTensorWrapper restoration with Diffusers and Accelerate. Important: load the quantized transformer without passing torch_dtype; otherwise Diffusers casts FP8 tensors back to BF16 during state-dict loading.

python
import json
import torch
from diffusers import Cosmos3OmniPipeline, Cosmos3OmniTransformer
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
from modelopt.torch.quantization.qtensor.base_qtensor import QTensorWrapper
import modelopt.torch.opt as mto


def patch_modelopt_qtensor_loader():
    import accelerate.utils.modeling as accelerate_modeling
    import diffusers.models.model_loading_utils as diffusers_loading

    original = accelerate_modeling.set_module_tensor_to_device
    if getattr(original, "_cosmos3_modelopt_patch", False):
        return

    def patched(module, tensor_name, device, value=None, dtype=None, fp16_statistics=None,
                tied_params_map=None, non_blocking=False, clear_cache=True):
        leaf_module = module
        leaf_name = tensor_name
        if "." in tensor_name:
            parts = tensor_name.split(".")
            for part in parts[:-1]:
                leaf_module = getattr(leaf_module, part)
            leaf_name = parts[-1]
        old_value = getattr(leaf_module, leaf_name) if hasattr(leaf_module, leaf_name) else None
        if isinstance(old_value, QTensorWrapper) and value is not None:
            leaf_module._parameters[leaf_name] = QTensorWrapper(
                value.to(device, non_blocking=non_blocking),
                metadata=old_value.metadata,
            )
            return
        return original(module, tensor_name, device, value, dtype, fp16_statistics,
                        tied_params_map, non_blocking, clear_cache)

    patched._cosmos3_modelopt_patch = True
    accelerate_modeling.set_module_tensor_to_device = patched
    diffusers_loading.set_module_tensor_to_device = patched


def cast_modelopt_runtime_tensors(model, dtype=torch.bfloat16):
    for module in model.modules():
        for name, param in list(module._parameters.items()):
            if isinstance(param, QTensorWrapper):
                param.metadata["dtype"] = dtype
            elif param is not None and param.is_floating_point():
                module._parameters[name] = torch.nn.Parameter(
                    param.detach().to(dtype),
                    requires_grad=param.requires_grad,
                )
        for name, buf in list(module._buffers.items()):
            if buf is not None and buf.is_floating_point():
                module._buffers[name] = buf.to(dtype)
    return model


patch_modelopt_qtensor_loader()
mto.enable_huggingface_checkpointing()

transformer = Cosmos3OmniTransformer.from_pretrained(
    "WaveCut/Cosmos3-Super-Text2Image-ModelOpt-FP8-Transformer",
    subfolder="transformer",
    use_safetensors=False,
)
transformer = cast_modelopt_runtime_tensors(transformer, torch.bfloat16)

pipe = Cosmos3OmniPipeline.from_pretrained(
    "nvidia/Cosmos3-Super-Text2Image",
    transformer=transformer,
    torch_dtype=torch.bfloat16,
    device_map="cuda",
    enable_safety_checker=True,
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=3.0)
pipe.to("cuda")

json_caption = {
    "subjects": [],
    "background_setting": "A concise scene description.",
    "comprehensive_t2i_caption": "A detailed natural-language caption.",
    "resolution": {"H": 1024, "W": 1024},
    "aspect_ratio": "1,1",
}

with torch.autocast("cuda", dtype=torch.bfloat16):
    result = pipe(
        prompt=json.dumps(json_caption),
        negative_prompt="",
        num_frames=1,
        height=1024,
        width=1024,
        num_inference_steps=50,
        guidance_scale=4.0,
        generator=torch.Generator(device="cuda").manual_seed(1143),
    )
result.video[0].save("cosmos3_modelopt_fp8.png")

Benchmarks

Measured on one RunPod NVIDIA B200 instance with local container storage, cached model files, PyTorch 2.9.1+cu130, 1024x1024 image generation, 50 inference steps, guidance scale 4.0, flow_shift=3.0, system prompt enabled. The ModelOpt FP8 runtime uses BF16 autocast around the pipeline forward.

Transformer Component Load

VariantLoad to CUDAVRAM after loadTorch allocatedTorch reservedTransformer weights
BF16 base transformer41.83s122,758 MiB122,121 MiB122,132 MiB119.21 GiB
NVIDIA ModelOpt FP8 transformer21.95s63,550 MiB62,907 MiB62,924 MiB61.06 GiB

Full Pipeline Generation

The stress set is ten handwritten JSON-caption prompts designed to stress Cyrillic text, reflections, multi-object composition, anatomy, small details, and scene-following.

VariantFull pipeline loadVRAM after loadTorch allocated after loadAvg generation timeMin / max generation timePeak sampled VRAMImages
BF16 base pipeline31.31s125,134 MiB124,386 MiB16.05s15.51s / 17.97s141,104 MiB10
NVIDIA ModelOpt FP8 pipeline35.49s65,810 MiB65,171 MiB45.57s45.07s / 47.28s81,854 MiB10

Original NVIDIA Example Caption

The original model repository provides `assets/example_caption.json`. The images below are generated locally with the same JSON-caption, seed 1143, 1024x1024, 50 steps, guidance scale 4.0.

VariantPipeline loadGeneration timePeak sampled VRAM
BF16 base pipeline35.41s18.01s141,098 MiB
NVIDIA ModelOpt FP8 pipeline35.28s47.20s71,470 MiB

BF16 reference output:

[image]

NVIDIA ModelOpt FP8 output:

[image]

Stress Prompt Outputs

Stress promptNVIDIA ModelOpt FP8 output
01 metro archive reading room[image]
02 arctic greenhouse night shift[image]
03 control room restoration[image]
04 rain market cross section[image]
05 manuscript restoration table[image]
06 robotic assembly line signage[image]
07 kitchen storm chess table[image]
08 orbital cockpit cyrillic ui[image]
09 flood command center[image]
10 cyrillic newspaper press[image]

Notes

  • Treat this as an experimental ModelOpt FP8 transformer artifact. The upstream NVIDIA card documents BF16 as the tested precision.
  • Do not pass torch_dtype=torch.bfloat16 when loading this quantized transformer; cast runtime metadata after loading as shown above.
  • The safety checker is not included in this repository; load it from the base model if your use case requires it.
  • Text rendering, especially exact Cyrillic text, remains a hard case for this model family and should be evaluated visually for the target prompt distribution.