Skip to main content

Causal Salience-Aware Quantization — gradient×activation-informed interaction-graph LLM weight quantization targeting exact bit budgets

Project description

CSAQ: Causal Salience-Aware Quantization

PyPI version License: MIT

Causal Salience-Aware Quantization (CSAQ) is a high-performance LLM weight quantization engine designed to hit perfectly defined fractional bit-budgets (e.g., exactly 4.0 bits/weight) by utilizing mixed-precision formats. Unlike magnitude-based proxies like AWQ or GPTQ, CSAQ uses first-order Taylor approximations to measure actual causal salience combined with advanced co-activation interaction graphs.

Features

  • Multi-Bit Mixed Precision: Replaces static quantization settings. Automatically distributes available bit thresholds (1, 2, 4, 8, 16) based heavily on impact, significantly minimizing degradation on critical model pathways.
  • Top-K Jaccard Co-Activation Graphs: Discovers sets of weights that commonly fire together using "Atomic Cliques".
  • Shared-Scale Architecture: Assigns low-precision bits to trailing follower weights by recycling the Quantization Scaling Factors ($S$) and Zero-Points ($Z$) of the clique's high-salience Leader, aggressively compressing parameters without losing scale context.
  • Constant Memory Footprint: Tracks Jaccard activation sparsification using an online bit-vector union/intersection accumulator, avoiding disastrous Out-Of-Memory (OOM) errors during calibration.

Installation

Install using pip:

pip install csaq-quant

Quick Start

1. Python API

You can programmatically apply CSAQ using the core export quantize and managing constraints with CSAQConfig:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from csaq import quantize, CSAQConfig, build_calibration_data

# 1. Load your standard HF LLM
model_id = "Qwen/Qwen1.5-0.5B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cpu")

# 2. Extract representative calibration data
calib_data = build_calibration_data(tokenizer, n=32, seq_len=128)

# 3. Configure fractional Bit-Budget and allowed bits (e.g., target exactly 4 bits on average)
config = CSAQConfig(
    target_bits=4.0, 
    bit_options=[1, 2, 4, 8, 16],
    clique_threshold=0.85
)

# 4. Fire the Quantization Pipeline
quantized_model, info = quantize(
    model=model, 
    calib_data=calib_data, 
    config=config, 
    verbose=True
)

# Optional: Generate metrics report and export to safetensors
from csaq.utils import generate_csaq_report, export_csaq_model
generate_csaq_report(info, save_path="./CSAQ_Report.json")
export_csaq_model(quantized_model, config, info["budget"], "./csaq_output")

2. Command Line Interface (CLI)

CSAQ includes a seamless CLI for quantizing models directly from the terminal without writing a single script.

Basic Usage:

python -m csaq \
  --model_path Qwen/Qwen1.5-0.5B \
  --wbits 4.0 \
  --options 1,2,4,8,16 \
  --save_path ./csaq_export

CLI Arguments Breakdown:

  • --model_path: (Required) The path to a local Hugging Face model directory or a Hub repository ID (e.g., meta-llama/Llama-3-8B).
  • --wbits: (Optional) The target average bit-width per weight across the entire network. Defaults to 4.0.
  • --options: (Optional) Comma-separated list of discrete bit formats the constraint solver is allowed to assign. Defaults to 1,2,4,8,16. High-salience cliques get higher bits.
  • --save_path: (Required) The local directory where the safetensors model, config modifications, and CSAQ_Report.json will be saved.

Example for deep quantization:

python -m csaq --model_path meta-llama/Llama-3-8B --wbits 2.5 --options 1,2,4 --save_path ./llama3-2.5bit

Advanced Details

Early Stopping Heuristic: The profiling phase evaluates the Spearman rank correlation of accumulated salience gradients over calibration batches. CSAQ will automatically stop processing subsets once weights theoretically stabilize, saving enormous amounts of compute.

Outputs: The engine spits out a CSAQ_Report.json providing metric insights regarding constraint mapping, Bit-Distribution Histograms, Pareto Efficiency estimation, and Clique generation sizes.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csaq_quant-0.1.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csaq_quant-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file csaq_quant-0.1.1.tar.gz.

File metadata

  • Download URL: csaq_quant-0.1.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for csaq_quant-0.1.1.tar.gz
Algorithm Hash digest
SHA256 01cb26b36e38aee56409c0145babc0e4e3cc1bbee3dfb683358def68282b18ce
MD5 873fe8faf19db67d7186d2e03f175da7
BLAKE2b-256 0724e85f9f19d2f3df2857ae06de6324c0f9dd648a68359bbf2feb183bba8fac

See more details on using hashes here.

File details

Details for the file csaq_quant-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: csaq_quant-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for csaq_quant-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cd530086c4c8ce30bd49f4ff3cc3768799025e3a272accaea7f67df6bc1de86
MD5 ed3d2b1fdb7ac9917d4dc064f4eab635
BLAKE2b-256 69bdc14ac27f2f60a18d5dc6c38064bdccfa277e4268f4a1e8cf2c708a6f54cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page