Skip to content

[BUG] modelopt restore using 'from_pretrained' doesn't work in diffusers #185

@ishan-modi

Description

@ishan-modi

Describe the bug

Restore functionality doesnt work for from_pretrained function of huggingface/diffusers

Steps/Code to reproduce bug

from diffusers import SanaTransformer2DModel
import modelopt.torch.quantization as mtq

checkpoint = "Efficient-Large-Model/Sana_600M_1024px_diffusers"
model = SanaTransformer2DModel.from_pretrained(checkpoint, subfolder="transformer")

config = mtq.FP8_DEFAULT_CFG
config['quant_cfg']['*weight_quantizer'].update({'fake_quant': False})
model = mtq.quantize(model, config)
mtq.compress(model)
model.save_pretrained("test_modelopt_quant")

model = SanaTransformer2DModel.from_pretrained("test_modelopt_quant")

Error Trace

    155 if force_quantize:
    156     m.weight_quantizer._dequantize = False
--> 157 assert not m.weight.is_meta, (
    158     "Real quantization does not support tensors on meta device."
    159 )
    160 real_quant_tensor = m.weight_quantizer(m.weight)
    161 m.weight = QTensorWrapper(real_quant_tensor)

AssertionError: Real quantization does not support tensors on meta device.

It seems like weights are on meta device for diffusers unlike transformers where they are on cpu when we restore modelopt_state

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions