Skip to content

Commit f78ac50

Browse files
committed
fix: address review feedback on layerwise detection + header + input validation
- examples/llm_ptq/hf_ptq.py: replace dict-inspection layerwise detection with a small recursive helper accepting ModelOptPTQRecipe directly, handling list-form QuantizeAlgoCfgType (per coderabbitai, jenchen13). - examples/llm_ptq/hf_ptq.py: convert recipe-type assert to explicit if/raise TypeError so validation is not stripped under python -O (per cjluo-nv). - modelopt_recipes/general/ptq/nvfp4_experts_only-fp8_kv_layerwise.yaml: bump new-file copyright header to 2026 per LICENSE_HEADER (per cjluo-nv). Signed-off-by: realAsma <akuriparambi@nvidia.com>
1 parent 1377465 commit f78ac50

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

examples/llm_ptq/hf_ptq.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,19 @@ def quantize_main(
960960
if args.recipe is not None and not args.auto_quantize_bits:
961961
print(f"Use recipe {args.recipe} for quantization")
962962
recipe = load_recipe(args.recipe)
963-
assert isinstance(recipe, ModelOptPTQRecipe), (
964-
f"Expected PTQ recipe, but got {type(recipe).__name__} from {args.recipe}"
965-
)
963+
if not isinstance(recipe, ModelOptPTQRecipe):
964+
raise TypeError(
965+
f"Expected PTQ recipe, but got {type(recipe).__name__} from {args.recipe}"
966+
)
967+
968+
def _is_layerwise(obj):
969+
if isinstance(obj, ModelOptPTQRecipe):
970+
return _is_layerwise(obj.quantize.algorithm)
971+
if isinstance(obj, list):
972+
return any(_is_layerwise(a) for a in obj)
973+
return bool(getattr(obj, "layerwise", False))
966974

967-
recipe_algorithm = recipe.quantize.model_dump().get("algorithm") if recipe else None
968-
is_layerwise = isinstance(recipe_algorithm, dict) and recipe_algorithm.get("layerwise", False)
975+
is_layerwise = _is_layerwise(recipe)
969976

970977
if args.batch_size == 0:
971978
# For VL models with image-text calibration, skip automatic batch size detection

modelopt_recipes/general/ptq/nvfp4_experts_only-fp8_kv_layerwise.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)