refactor algorithm cli - #2140
Conversation
Signed-off-by: n1ck-guo <heng.guo@intel.com>
Signed-off-by: n1ck-guo <heng.guo@intel.com>
Signed-off-by: n1ck-guo <heng.guo@intel.com>
Signed-off-by: n1ck-guo <heng.guo@intel.com>
Signed-off-by: n1ck-guo <heng.guo@intel.com>
Signed-off-by: n1ck-guo <heng.guo@intel.com> # Conflicts: # test/unit/test_cuda/transform/test_spinquant.py
…d TypeError - Revert the strict TypeError raised for kwargs that don't match the selected alg_configs (e.g. disable_opt_rtn passed with a non-RTN algorithm). This broke real callers (llm-compressor's AutoRoundModifier always passes disable_opt_rtn regardless of iters) and our own test_audio_model.py test. Log via logger.error and ignore instead, same as before the earlier hardening pass. The auto-discovery mechanism (_discover_alg_config_fields / _owning_algorithm_names) is unchanged. - Remove the stray disable_opt_rtn=True left over from copy-paste in test_quantize_with_tuning (iters=1 selects SignRound, so the RTN-only flag never applied). - Fix pylint line-too-long (148/120) in AWQConfig.register_args help text. Signed-off-by: n1ck-guo <heng.guo@intel.com>
7cee70a to
8c8dee3
Compare
Signed-off-by: n1ck-guo <heng.guo@intel.com> # Conflicts: # auto_round/autoround.py # auto_round/cli/algorithms.py
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Is rotation always applied before quantization regardless document the canonical execution order (pre-processors → rotation → block |
| def register_args(cls, registry: AlgorithmParameterRegistry) -> None: | ||
| mutex = registry.add_mutually_exclusive_group() | ||
| mutex.add_argument( | ||
| "--disable_opt_rtn", |
There was a problem hiding this comment.
Each config now declares parameters twice: once in __init__ (the kwargs) and again in
register_args (the CLI). For example RTNConfig declares disable_opt_rtn /
enable_opt_rtn in both places; SignRoundConfig re-lists ~15 fields.
These two lists must be kept in sync by hand; nothing enforces it. A field added to
__init__ but forgotten in register_args is silently unavailable from the CLI (and
vice-versa).
how about consider driving both from a single source of truth — pydantic Field(...) /
dataclass field(metadata=...) — so the CLI declaration is derived from the config
fields, not maintained alongside them.
for example
from pydantic import BaseModel, Field
class RTNConfig(BaseModel):
group_size: int = Field(
default=128,
description="quant group size"
)
symmetric: bool = Field(
default=True,
description="symmetric quantization"
)
auto generate cli args:
for field in RTNConfig.model_fields:
parser.add_argument(...)
There was a problem hiding this comment.
This is a good design, thanks. I will consider it. I had considered a similar approach before, but handling aliases is a bit difficult.
let me evaluate it.
There was a problem hiding this comment.
If the algorithm does not provide customized cli arguments, it would be better to fall back to this approach. The potential issue is that some parameters may have the same name, so we should automatically add a prefix to those parameters to avoid conflicts.
# Conflicts: # auto_round/autoround.py # auto_round/cli/algorithms.py # test/unit/test_cpu/core/test_autoround_entry.py
| """ | ||
| from auto_round.algorithms.registry import iter_algorithm_entries | ||
|
|
||
| result = [] |
There was a problem hiding this comment.
As the entry of AutoRound, personally I don't like there are too many helper functions at the beginning of the file
| seqlen: int = None, | ||
| alg_configs=None, | ||
| **kwargs, | ||
| ) -> "BaseCompressor": |
There was a problem hiding this comment.
We should annotate this class as thoroughly as possible, e.g., explaining the meaning of each argument, what can be passed in kwargs, and providing some examples.
| from auto_round.algorithms.transforms.spinquant.preprocessor import SpinQuantConfig | ||
|
|
||
| register_algorithm("rtn", aliases=("rtn",), config_factory=RTNConfig, summary="Round-To-Nearest quantization.") | ||
| register_algorithm( |
There was a problem hiding this comment.
To follow the principle that each algorithm should only modify the files it owns, I’d suggest splitting this code into the respective algorithm files.
| ) | ||
| group.add_argument( | ||
| "--awq_clip_as_init", | ||
| dest="awq_clip_as_init", |
There was a problem hiding this comment.
Thanks for the refinements. The current version looks better.
Signed-off-by: n1ck-guo <heng.guo@intel.com>
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Description
refactor algorithm config and cli
SpinQuantConfig(...)directly and pass it toalg_configs.Type of Change
Refactor
Related Issues
Fixes or relates to #
Checklist Before Submitting
/azp run Unit-Test-CUDA-AutoRound.