Skip to content

Commit 9e43a0f

Browse files
committed
minor
Signed-off-by: realAsma <[email protected]>
1 parent d979c5d commit 9e43a0f

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

modelopt/torch/quantization/algorithms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ class QuantRecipe(CustomHPType):
8686
8787
Args:
8888
quant_cfg: str or dict or None. dict is used for custom quantization formats.
89-
name: name for custom quantization formats. Ignored if quant_cfg is None or str.
89+
name: name for custom quantization formats. Only used if quantization format is a custom
90+
format not available in :mod:`modelopt.torch.quantization.config`.
9091
"""
9192

9293
def __init__(self, quant_cfg: str | dict[str, Any] | None = None, name: str | None = None):
9394
"""Initialize the QuantRecipe with the quantization configuration."""
94-
name = name or self.get_auto_name_for_config(quant_cfg)
95+
name = self.get_auto_name_for_config(quant_cfg) or name
9596

9697
if quant_cfg is None:
9798
quant_cfg = {"quant_cfg": {"*": {"enable": False}}}
@@ -179,7 +180,7 @@ def __init__(
179180
nn_modules: list[nn.Module] | None = None,
180181
) -> None:
181182
"""Initializes Hparam with original value and choices."""
182-
choices = sorted(set((choices if choices else []) + [QuantRecipe(quant_cfg=None)]))
183+
choices = sorted({*(choices if choices else []), QuantRecipe(quant_cfg=None)})
183184
super().__init__(choices, original=choices[0])
184185
self.nn_modules = nn_modules if nn_modules else []
185186

modelopt/torch/quantization/model_quant.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,11 @@ def forward_backward_step(model, batch) -> None:
413413

414414
name = QuantRecipe.get_auto_name_for_config(quant_cfg)
415415
if name is None:
416-
if isinstance(quant_cfg, str):
417-
raise ValueError(f"Invalid quantization format: {quant_cfg}")
418-
else:
419-
name = f"CUSTOM_{i}"
420-
warnings.warn(
421-
f"Received custom quantization formats for search, auto_quantize results may not be optimal. "
422-
f"This config will be displayed as {name}"
423-
)
416+
name = f"CUSTOM_{i}"
417+
warnings.warn(
418+
f"Received custom quantization formats for search, auto_quantize results may not be optimal. "
419+
f"This config will be displayed as {name}"
420+
)
424421
processed_quantization_formats.append((quant_cfg, name))
425422

426423
assert len(processed_quantization_formats) > 0, "`quantization_formats` should not be empty"

0 commit comments

Comments
 (0)