Skip to content

refactor algorithm cli - #2140

Open
n1ck-guo wants to merge 11 commits into
mainfrom
hengguo/refactor_cli
Open

refactor algorithm cli#2140
n1ck-guo wants to merge 11 commits into
mainfrom
hengguo/refactor_cli

Conversation

@n1ck-guo

@n1ck-guo n1ck-guo commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

refactor algorithm config and cli

  1. add register_args in alg config, automatically parses parameters, no need to manually add them in the CLI.
  2. remove deprecated args: algorithm
  3. remove rotation_config, pass by alg_config
old new
AutoRound(m, rotation_config="quarot") AutoRound(m, alg_configs=["auto_round", "quarot"])
AutoRound(m, rotation_config="default") AutoRound(m, alg_configs=["auto_round", "hadamard"])
AutoRound(m, rotation_config="random_hadamard") AutoRound(m, alg_configs=["auto_round", "random_hadamard"])
AutoRound(m, rotation_config=SpinQuantConfig(...)) AutoRound(m, alg_configs=["auto_round", SpinQuantConfig(...)])
AutoRound(m, rotation_config={"algorithm": "spinquant", ...}) dictionary format is no longer supported. construct SpinQuantConfig(...) directly and pass it to alg_configs.

Type of Change

Refactor

Related Issues

Fixes or relates to #

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

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>
@chensuyue chensuyue added this to the 0.16.0 milestone Aug 11, 2026
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>
@n1ck-guo
n1ck-guo force-pushed the hengguo/refactor_cli branch from 7cee70a to 8c8dee3 Compare August 12, 2026 05:29
Signed-off-by: n1ck-guo <heng.guo@intel.com>

# Conflicts:
#	auto_round/autoround.py
#	auto_round/cli/algorithms.py
@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lkk12014402

lkk12014402 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

refactor algorithm config and cli

  1. add register_args in alg config, automatically parses parameters, no need to manually add them in the CLI.
  2. remove deprecated args: algorithm
  3. remove rotation_config, pass by alg_config

old new
AutoRound(m, rotation_config="quarot") AutoRound(m, alg_configs=["auto_round", "quarot"])
AutoRound(m, rotation_config="default") AutoRound(m, alg_configs=["auto_round", "hadamard"])
AutoRound(m, rotation_config="random_hadamard") AutoRound(m, alg_configs=["auto_round", "random_hadamard"])
AutoRound(m, rotation_config=SpinQuantConfig(...)) AutoRound(m, alg_configs=["auto_round", SpinQuantConfig(...)])
AutoRound(m, rotation_config={"algorithm": "spinquant", ...}) dictionary format is no longer supported. construct SpinQuantConfig(...) directly and pass it to alg_configs.

Type of Change

Refactor

Related Issues

Fixes or relates to #

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

Is rotation always applied before quantization regardless
of position (["quarot", "auto_round"] == ["auto_round", "quarot"])?

document the canonical execution order (pre-processors → rotation → block
quantizer) and make it independent of list position, or make position meaningful and say
so. This directly affects how rotation members are ordered in AlgorithmComposer.members().

def register_args(cls, registry: AlgorithmParameterRegistry) -> None:
mutex = registry.add_mutually_exclusive_group()
mutex.add_argument(
"--disable_opt_rtn",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...)

@n1ck-guo n1ck-guo Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment thread auto_round/autoround.py
"""
from auto_round.algorithms.registry import iter_algorithm_entries

result = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the entry of AutoRound, personally I don't like there are too many helper functions at the beginning of the file

Comment thread auto_round/autoround.py
seqlen: int = None,
alg_configs=None,
**kwargs,
) -> "BaseCompressor":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread auto_round/algorithms/registry.py Outdated
from auto_round.algorithms.transforms.spinquant.preprocessor import SpinQuantConfig

register_algorithm("rtn", aliases=("rtn",), config_factory=RTNConfig, summary="Round-To-Nearest quantization.")
register_algorithm(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refinements. The current version looks better.

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants