MalayKedia's picture
Upload cli_quant.py with huggingface_hub
a993b50 verified
Raw History Blame Contribute Delete
1.94 kB
"""Shared argparse flags for recipes that call ``quantize_checkpoint``."""
from __future__ import annotations
import argparse
import os
def add_base_quant_args(ap: argparse.ArgumentParser, *,
method: str = "gptq",
bits: int = 4,
group_size: int = 128) -> None:
ap.add_argument("--sparsity", type=float, default=0.0,
help="ignored; compress.sbatch always passes it")
ap.add_argument("--method", default=method, choices=("none", "rtn", "gptq"))
ap.add_argument("--bits", type=int, default=bits)
ap.add_argument("--group-size", type=int, default=group_size)
ap.add_argument("--exclude", default="",
help="comma-separated groups left at native precision")
ap.add_argument("--no-rtn-rest", action="store_true",
help="with --method gptq, leave embedding/vision/mtp bf16")
ap.add_argument("--calib", default=None,
help="calibration jsonl; defaults to $EFFAI_CALIB")
ap.add_argument("--asym", action="store_true",
help="ignored; asymmetric is the default")
ap.add_argument("--sym", action="store_true",
help="symmetric GPTQ (default is asymmetric)")
ap.add_argument("--desc-act", action="store_true",
help="GPTQ act-order")
ap.add_argument("--no-embed-first", action="store_true",
help="quantize embedding after GPTQ (default: before)")
def kwargs_from_base_args(args: argparse.Namespace) -> dict:
return dict(
method=args.method,
bits=args.bits,
group_size=args.group_size,
exclude=tuple(g for g in args.exclude.split(",") if g),
rtn_rest=not args.no_rtn_rest,
calib=args.calib or os.environ.get("EFFAI_CALIB"),
sym=args.sym,
embed_first=not args.no_embed_first,
desc_act=args.desc_act,
)