multimodalart HF Staff commited on
Commit
4e809bd
·
verified ·
1 Parent(s): 6cd5923

Move bnb Params4bit.shape fix to a runtime shim in app.py; restore pristine bundled diffusers

Browse files
app.py CHANGED
@@ -19,6 +19,24 @@ from huggingface_hub import hf_hub_download
19
 
20
  from diffusers import Ideogram4Pipeline
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  MODEL_ID = "diffusers-internal-dev/ideogram-4-nf4-v2"
23
  LM_HEAD_REPO = "multimodalart/qwen3-vl-8b-instruct-lm-head"
24
  AOTI_REPO = "multimodalart/i4-block-aoti"
 
19
 
20
  from diffusers import Ideogram4Pipeline
21
 
22
+ # Runtime shim (keeps the bundled diffusers pristine): cu130-era bitsandbytes returns Params4bit.shape as a
23
+ # plain tuple, but diffusers' check_quantized_param_shape calls .numel() on it. math.prod handles both, so
24
+ # this is a no-op once diffusers/bnb fix it upstream.
25
+ import math # noqa: E402
26
+
27
+ from diffusers.quantizers.bitsandbytes.bnb_quantizer import BnB4BitDiffusersQuantizer # noqa: E402
28
+
29
+
30
+ def _check_quantized_param_shape(self, param_name, current_param, loaded_param):
31
+ n = math.prod(tuple(current_param.shape))
32
+ inferred_shape = (n,) if "bias" in param_name else ((n + 1) // 2, 1)
33
+ if tuple(loaded_param.shape) != tuple(inferred_shape):
34
+ raise ValueError(f"Expected flattened shape of {param_name} to be {inferred_shape}, got {tuple(loaded_param.shape)}.")
35
+ return True
36
+
37
+
38
+ BnB4BitDiffusersQuantizer.check_quantized_param_shape = _check_quantized_param_shape
39
+
40
  MODEL_ID = "diffusers-internal-dev/ideogram-4-nf4-v2"
41
  LM_HEAD_REPO = "multimodalart/qwen3-vl-8b-instruct-lm-head"
42
  AOTI_REPO = "multimodalart/i4-block-aoti"
diffusers_src/src/diffusers/quantizers/bitsandbytes/bnb_quantizer.py CHANGED
@@ -16,7 +16,6 @@ Adapted from
16
  https://github.com/huggingface/transformers/blob/c409cd81777fb27aadc043ed3d8339dbc020fb3b/src/transformers/quantizers/quantizer_bnb_4bit.py
17
  """
18
 
19
- import math
20
  from typing import TYPE_CHECKING, Any
21
 
22
  from ...utils import get_module_from_name
@@ -210,8 +209,7 @@ class BnB4BitDiffusersQuantizer(DiffusersQuantizer):
210
  current_param_shape = current_param.shape
211
  loaded_param_shape = loaded_param.shape
212
 
213
- # newer bitsandbytes returns Params4bit.shape as a plain tuple (no .numel()); math.prod handles both.
214
- n = math.prod(current_param_shape)
215
  inferred_shape = (n,) if "bias" in param_name else ((n + 1) // 2, 1)
216
  if loaded_param_shape != inferred_shape:
217
  raise ValueError(
 
16
  https://github.com/huggingface/transformers/blob/c409cd81777fb27aadc043ed3d8339dbc020fb3b/src/transformers/quantizers/quantizer_bnb_4bit.py
17
  """
18
 
 
19
  from typing import TYPE_CHECKING, Any
20
 
21
  from ...utils import get_module_from_name
 
209
  current_param_shape = current_param.shape
210
  loaded_param_shape = loaded_param.shape
211
 
212
+ n = current_param_shape.numel()
 
213
  inferred_shape = (n,) if "bias" in param_name else ((n + 1) // 2, 1)
214
  if loaded_param_shape != inferred_shape:
215
  raise ValueError(