Skip to content

Hadamard Group Size must be a power of 2 #20

Description

@tin2tin

Running this snippet: https://github.com/asomoza/diffusers-recipes/blob/main/models/krea2_turbo/scripts/t2i_sdnq.py gave me the following error:

Loading weights: 100%|██████████████████████████████████████████████████████████| 1425/1425 [00:00<00:00, 30210.08it/s]
Loading pipeline components...:  60%|███████████████████████████████▏                    | 3/5 [00:01<00:00,  2.26it/s]
01:21.969  operator         | ERROR Python: Traceback (most recent call last):
                            |   File "..\site-packages\huggingface_hub\utils\_validators.py", line 88, in _inner_fn
                            |     return fn(*args, **kwargs)
                            |   File "..\site-packages\diffusers\pipelines\pipeline_utils.py", line 1057, in from_pretrained
                            |     loaded_sub_model = load_sub_model(
                            |         library_name=library_name,
                            |     ...<24 lines>...
                            |         trust_remote_code=trust_remote_code,
                            |     )
                            |   File "..\site-packages\diffusers\pipelines\pipeline_loading_utils.py", line 910, in load_sub_model
                            |     loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
                            |   File "..\site-packages\huggingface_hub\utils\_validators.py", line 88, in _inner_fn
                            |     return fn(*args, **kwargs)
                            |   File "..\site-packages\diffusers\models\modeling_utils.py", line 1393, in from_pretrained
                            |     hf_quantizer.preprocess_model(
                            |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
                            |         model=model,
                            |         ^^^^^^^^^^^^
                            |         device_map=device_map,
                            |         ^^^^^^^^^^^^^^^^^^^^^^
                            |         keep_in_fp32_modules=keep_in_fp32_modules,
                            |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            |     )
                            |     ^
                            |   File "..\site-packages\diffusers\quantizers\base.py", line 204, in preprocess_model
                            |     return self._process_model_before_weight_loading(model, **kwargs)
                            |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
                            |   File "..\site-packages\sdnq\quantizer.py", line 664, in _process_model_before_weight_loading
                            |     model = sdnq_post_load_quant(model, torch_dtype=self.torch_dtype, pre_quantized=True, **get_quant_args_from_config(self.quantization_config))
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quantizer.py", line 514, in sdnq_post_load_quant
                            |     model, quantization_config = apply_sdnq_to_module(model, quantization_config, torch_dtype=torch_dtype)
                            |                                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quantizer.py", line 439, in apply_sdnq_to_module
                            |     module, quantization_config = apply_sdnq_to_module(module, quantization_config, torch_dtype=torch_dtype, full_param_name=param_name)
                            |                                   ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quantizer.py", line 434, in apply_sdnq_to_module
                            |     module, quantization_config = sdnq_quantize_layer(module, quantization_config, torch_dtype=torch_dtype, param_name=param_name)
                            |                                   ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quantizer.py", line 384, in sdnq_quantize_layer
                            |     weight_data = sdnq_quantize_layer_weight(layer.weight, **quant_kwargs)
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quantizer.py", line 145, in sdnq_quantize_layer_weight
                            |     weight, use_hadamard, hadamard_group_size = apply_hadamard(weight, group_size=hadamard_group_size, hadamard=hadamard, layer_class_name=layer_class_name)
                            |                                                 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quant_utils.py", line 164, in apply_hadamard
                            |     weight = rotate_hadamard(weight, group_size=group_size, hadamard=hadamard, is_conv=is_conv)
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quant_utils.py", line 129, in rotate_hadamard
                            |     hadamard = get_hadamard(group_size, dtype=weight.dtype, device=weight.device)
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quant_utils.py", line 121, in get_hadamard
                            |     H = build_hadamard(n, dtype=dtype, device=device)
                            |   File "..\site-packages\torch\utils\_contextlib.py", line 120, in decorate_context
                            |     return func(*args, **kwargs)
                            |   File "..\site-packages\sdnq\quant_utils.py", line 108, in build_hadamard
                            |     raise RuntimeError("Hadamard Group Size must be a power of 2.")
                            | RuntimeError: Hadamard Group Size must be a power of 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions