### Build and Serve Documentation Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/contributing.md Install documentation dependencies and start a local server to preview the documentation. ```bash uv sync --extra docs uv run mkdocs serve ``` -------------------------------- ### Run Quantization with QEP for Improved Quality Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/gptq.md Integrate GPTQ with the Runner and ModelConfig, enabling QEP (Quantization Error Propagation) for potentially higher quality results. This example demonstrates a full setup for running quantization. ```python from onecomp import Runner, ModelConfig model_config = ModelConfig(model_id="meta-llama/Llama-2-7b-hf", device="cuda:0") gptq = GPTQ(wbits=3, groupsize=128) runner = Runner( model_config=model_config, quantizer=gptq, qep=True, ) runner.run() ``` -------------------------------- ### Install uv and Set Up Project Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Install uv, clone the repository, and sync dependencies including extras for development and visualization. ```bash # Install uv (macOS or Linux) curl -LsSf https://astral.sh/uv/install.sh | sh # Clone and set up git clone https://github.com/FujitsuResearch/OneCompression.git cd OneCompression uv sync --extra cu128 --extra dev --extra visualize ``` -------------------------------- ### Runner: Manual Quantization Pipeline Setup Source: https://context7.com/fujitsuresearch/onecompression/llms.txt Set up the manual quantization pipeline using ModelConfig and a specific Quantizer (GPTQ). Includes optional logger setup. ```python from onecomp import ModelConfig, Runner, GPTQ, setup_logger setup_logger() # optional: enable progress logging model_config = ModelConfig( model_id="TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T", device="cuda:0", ) gptq = GPTQ(wbits=4, groupsize=128) runner = Runner(model_config=model_config, quantizer=gptq) ``` -------------------------------- ### Basic QEP Implementation Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/qep.md Demonstrates the basic setup for using QEP with a specified model and quantizer. Ensure necessary imports are included. ```python from onecomp import ModelConfig, Runner, GPTQ model_config = ModelConfig(model_id="meta-llama/Llama-2-7b-hf", device="cuda:0") gptq = GPTQ(wbits=3) runner = Runner( model_config=model_config, quantizer=gptq, qep=True, ) runner.run() ``` -------------------------------- ### Logging Setup Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/api/utilities.md Sets up the logging configuration for the library. ```APIDOC ## Logging ::: onecomp.log.setup_logger options: show_source: false ``` -------------------------------- ### Install vLLM with pip Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/vllm-inference.md Install vLLM as an optional dependency using pip. ```bash pip install vllm ``` -------------------------------- ### Install OneComp with Visualization Extras Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Install OneComp with matplotlib for visualization features. ```bash pip install onecomp[visualize] ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Installs dependencies required for building documentation, including CUDA support and documentation tools, then serves the documentation locally. ```bash uv sync --extra cu128 --extra dev --extra docs uv run mkdocs serve ``` -------------------------------- ### Clarify CalibrationConfig Usage in Examples Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Adds `NOTE` comments to all example scripts to clarify that compact `CalibrationConfig` settings are for demonstration purposes and recommend default settings for real quantization. Also advises on using `batch_size` for chunked calibration with large datasets. ```python Added NOTE comments across all example/ scripts (example_gptq.py, example_qep_gptq.py, example_jointq.py, example_autobit.py, example_save_load.py, example_lpcd_gptq.py, example_custom_calibration.py, post_process/example_blockwise_ptq.py, post_process/example_lora_sft.py, post_process/example_lora_sft_knowledge.py, pre_process/example_preprocess_save_load.py, vllm_inference/example_gptq_vllm_inference.py) clarifying that the compact CalibrationConfig(max_length=512, num_calibration_samples=128) settings are demo-only and recommending the CalibrationConfig() defaults (max_length=2048, num_calibration_samples=512) for real quantisation; qep=False examples additionally recommend setting batch_size so that Runner.quantize_with_calibration_chunked is used with large calibration data ``` -------------------------------- ### Install uv and Sync Dependencies Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Installs uv using a curl script and then synchronizes project dependencies, including optional extras like CUDA support, development tools, and visualization libraries. ```bash # install uv (for macOS or Linux) curl -LsSf https://astral.sh/uv/install.sh | sh git clone https://github.com/FujitsuResearch/OneCompression.git cd OneCompression uv sync --extra cu128 --extra dev --extra visualize ``` -------------------------------- ### Install Hydra Core Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/README.md Install the Hydra core library using pip. This is a prerequisite for managing benchmark configurations. ```bash pip install hydra-core ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/contributing.md Install the necessary development dependencies, including specific CUDA versions and development tools. ```bash uv sync --extra cu128 --extra dev ``` -------------------------------- ### Developer Installation with pip Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Clone the repository and install OneComp in editable mode with development dependencies. ```bash git clone https://github.com/FujitsuResearch/OneCompression.git cd OneCompression # Install PyTorch with CUDA support pip install torch --index-url https://download.pytorch.org/whl/cu128 # Install onecomp with development dependencies pip install -e ".[dev]" ``` -------------------------------- ### Basic LPCD with GPTQ + QEP Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/lpcd.md This snippet demonstrates the basic setup for using LPCD with GPTQ quantization and QEP error compensation. It initializes the model, quantizer, and LPCD configurations, then runs the optimization process. ```python from onecomp import ( CalibrationConfig, GPTQ, LPCDConfig, ModelConfig, Runner, setup_logger, ) setup_logger() model_config = ModelConfig( model_id="TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T", device="cuda:0", ) gptq = GPTQ(wbits=3, groupsize=128) lpcd_config = LPCDConfig( enable_residual=True, perccorr=0.5, percdamp=0.01, use_closed_form=True, device="cuda:0", ) runner = Runner( model_config=model_config, quantizer=gptq, calibration_config=CalibrationConfig(max_length=512, num_calibration_samples=128), qep=True, lpcd=True, lpcd_config=lpcd_config, ) runner.run() ``` -------------------------------- ### Example: End-to-End LPCD GPTQ Quantization Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Provides an end-to-end example of TinyLlama GPTQ 3-bit quantization with QEP and LPCD, including residual-only closed-form refinement and reporting of original, dequantized, and quantized perplexity. ```python example/example_lpcd_gptq.py: TinyLlama GPTQ 3-bit (groupsize=128) + QEP + LPCD end-to-end example (residual-only closed-form refinement, original / dequantized / quantized perplexity reporting) ``` -------------------------------- ### Install Hydra Extra Source: https://github.com/fujitsuresearch/onecompression/blob/main/model_validation/autobit/README.md Install the Hydra extra for managing configurations. Replace `` with your specific CUDA variant (e.g., `cpu`, `cu118`, `cu121`). ```bash # uv uv sync --extra --extra hydra # pip pip install "onecomp[hydra]" ``` -------------------------------- ### Example Usage of AutoBit Quantization Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md A sample script demonstrating how to use the AutoBit quantization feature. ```python example/example3.py ``` -------------------------------- ### DBF Quick Start with TinyLlama Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/dbf.md Use this configuration for a first run with a small model like TinyLlama to verify the pipeline end-to-end. It requires minimal GPU memory. ```python from onecomp import CalibrationConfig, ModelConfig, Runner from onecomp.quantizer.dbf import DBF model_config = ModelConfig( model_id="TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T", device="cuda:0", ) calib_config = CalibrationConfig( max_length=512, num_calibration_samples=128, ) dbf = DBF(target_bits=1.5) runner = Runner( model_config=model_config, quantizer=dbf, calibration_config=calib_config, ) runner.run() ``` -------------------------------- ### Install PyTorch with CUDA 12.8 Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Install PyTorch with CUDA 12.8 support. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 ``` -------------------------------- ### Example: Custom Calibration Dataset for Quantization Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Demonstrates using `CalibrationConfig` with a custom Python code-based calibration dataset. Compares quantization quality with default C4 data versus custom data. ```python example/example_custom_calibration.py: Demonstrates CalibrationConfig with a custom calibration dataset (Python code snippets in example/data/python_calibration.txt). Quantizes TinyLlama with GPTQ 3-bit using both default C4 and custom Python-code calibration, then compares inference outputs across multiple prompts to show how calibration data choice affects quantization quality. ``` -------------------------------- ### Start vLLM API Server and Query Source: https://context7.com/fujitsuresearch/onecompression/llms.txt Launch an OpenAI-compatible HTTP endpoint using vLLM to serve the quantized model. Disable FP8 warmup by setting `VLLM_USE_DEEP_GEMM=0` and `VLLM_DEEP_GEMM_WARMUP=skip`. ```bash # Step 2a: API server — OpenAI-compatible HTTP endpoint export VLLM_USE_DEEP_GEMM=0 # disable FP8 warmup (not needed for GPTQ) export VLLM_DEEP_GEMM_WARMUP=skip vllm serve ./Llama-3.1-8B-Instruct-gptq-4bit # Query the server curl http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "./Llama-3.1-8B-Instruct-gptq-4bit", "messages": [{"role": "user", "content": "What is post-training quantization?"}], "max_tokens": 128 }' ``` -------------------------------- ### Install PyTorch with CUDA 12.4 Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Install PyTorch with CUDA 12.4 support. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 ``` -------------------------------- ### Example: GPTQ 4-bit with BlockWisePTQ Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Illustrates GPTQ 4-bit quantization combined with BlockWisePTQ, including Phase 1 greedy and Phase 2 CBQ, and reports Perplexity (PPL) comparison. ```python example/post_process/example_blockwise_ptq.py: GPTQ 4-bit quantization + BlockWisePTQ (Phase 1 greedy + Phase 2 CBQ) with PPL comparison ``` -------------------------------- ### Install vLLM with uv Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/vllm-inference.md Install vLLM as an optional dependency using uv. Ensure you use the `cu130` extra for compatibility with recent PyTorch versions. ```bash uv sync --extra cu130 --extra vllm ``` -------------------------------- ### Quick Start: Rotation Preprocessing and Quantization Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/pre-process.md This snippet demonstrates the basic workflow for rotation preprocessing followed by quantization using the Runner pipeline. Ensure wbits, groupsize, and sym parameters match between preprocessing and quantization steps. ```python from onecomp import ModelConfig, Runner, GPTQ, prepare_rotated_model, setup_logger setup_logger() # Step 1: Rotation preprocessing model_config = ModelConfig(model_id="meta-llama/Llama-2-7b-hf", device="cuda:0") rotated_config = prepare_rotated_model( model_config=model_config, save_directory="./rotated_model", wbits=4, groupsize=128, ) # Step 2: Quantize (wbits/groupsize/sym must match Step 1) gptq = GPTQ(wbits=4, groupsize=128) runner = Runner(model_config=rotated_config, quantizer=gptq) runner.run() ``` -------------------------------- ### Install OneComp with Hydra, CUDA, and vLLM Extras Source: https://github.com/fujitsuresearch/onecompression/blob/main/model_validation/gptq/README.md Install OneComp with 'hydra' and 'vllm' extras for full validation capabilities, including vLLM inference. Replace with your specific CUDA variant. ```bash # uv uv sync --extra --extra hydra --extra vllm # pip pip install "onecomp[hydra]" vllm ``` -------------------------------- ### Launch Open WebUI with pip Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/vllm-inference.md Alternative method to launch Open WebUI using pip. Requires Python 3.11 or 3.12 and a dedicated virtual environment to avoid dependency conflicts. This installs and serves the application. ```bash # Create a dedicated venv (uv auto-downloads Python 3.12 if needed) uv venv ~/open-webui-env --python 3.12 source ~/open-webui-env/bin/activate # Install and launch uv pip install open-webui open-webui serve --port 3000 ``` -------------------------------- ### Install onecomp Package Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Install the onecomp Python package using pip after PyTorch has been successfully installed. ```bash pip install onecomp ``` -------------------------------- ### Install PyTorch and OneCompression with Pip Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Installs PyTorch with CUDA support and then installs the OneCompression package in editable mode with development dependencies using pip. ```bash git clone cd OneCompression # First, install PyTorch with CUDA support for your environment pip install torch --index-url https://download.pytorch.org/whl/cu128 # Then install onecomp with development dependencies pip install -e ".[dev]" ``` -------------------------------- ### Install vLLM with CUDA 13.0 Support Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Install vLLM with specific CUDA version support for uv users. For pip users, a standard installation is provided. ```bash uv sync --extra cu130 --extra vllm ``` ```bash pip install vllm ``` -------------------------------- ### Initialize Runner with GPTQ, QEP, and LPCD Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/overview.md Configure the Runner with GPTQ quantization, QEP, and Layer-Projected Coordinate Descent (LPCD) for submodule refinement. LPCD requires a configuration object. ```python from onecomp import GPTQ, LPCDConfig, Runner runner = Runner( model_config=model_config, quantizer=GPTQ(wbits=3, groupsize=128), qep=True, lpcd=True, lpcd_config=LPCDConfig(), ) runner.run() ``` -------------------------------- ### Verify onecomp Installation Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/cli.md Check if the onecomp CLI is installed correctly by displaying its version. ```bash onecomp --version ``` ```bash python -m onecomp --version ``` -------------------------------- ### Install PyTorch with CUDA 13.0 Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Use this command to install PyTorch with CUDA 13.0 support. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130 ``` -------------------------------- ### Install PyTorch with CUDA 12.6 Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Use this command to install PyTorch with CUDA 12.6 support. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 ``` -------------------------------- ### Install PyTorch with CUDA 12.1 Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/installation.md Use this command to install PyTorch with CUDA 12.1 support. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 ``` -------------------------------- ### Initialize QEPConfig Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/configuration.md Instantiate QEPConfig to control Quantization Error Propagation behavior. The default `general=False` uses a faster, architecture-aware implementation. ```python from onecomp import QEPConfig qep_config = QEPConfig( general=False, percdamp=0.01, perccorr=0.5, device="cuda:0", exclude_layer_keywords=["mlp.down_proj"], ) ``` -------------------------------- ### Install PyTorch CPU-only Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Install the CPU-only version of PyTorch, torchvision, and torchaudio. This is suitable for systems without a CUDA-enabled GPU. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu ``` -------------------------------- ### Initialize Runner with GPTQ and QEP Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/overview.md Instantiate the Runner with a specific quantizer (GPTQ) and enable Quantization Error Propagation (QEP). ```python runner = Runner( model_config=model_config, quantizer=GPTQ(wbits=3), qep=True, ) ``` -------------------------------- ### Launch Open WebUI with Docker Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/vllm-inference.md Recommended method to launch Open WebUI using Docker. The `--add-host` flag is necessary on Linux to allow the container to access the vLLM server running on the host machine. ```bash docker run -d -p 3000:8080 \ --add-host=host.docker.internal:host-gateway \ --name open-webui \ ghcr.io/open-webui/open-webui:latest ``` -------------------------------- ### Verify Hydra Installation Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/README.md Verify the Hydra installation by checking its version. This ensures Hydra is correctly set up before proceeding with benchmarks. ```python python -c "import hydra; print(hydra.__version__)" ``` -------------------------------- ### Install PyTorch CUDA-enabled Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Install the CUDA-enabled version of PyTorch, torchvision, and torchaudio. Choose the command that matches your system's CUDA version. ```bash pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### Run Quantization with Runner Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/basic-usage.md Initialize a `Runner` with the `ModelConfig` and `Quantizer`, then call `runner.run()` to perform the quantization. Optional logging can be enabled using `setup_logger()`. ```python from onecomp import Runner, setup_logger setup_logger() # Optional: enable logging output runner = Runner(model_config=model_config, quantizer=gptq) runner.run() ``` -------------------------------- ### Basic Quantization (Defaults) Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/cli.md Quantize a model using default settings, including AutoBit mixed-precision and QEP, with VRAM auto-estimation. ```bash onecomp TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T ``` -------------------------------- ### Run Fixed Lambda Benchmark (Lambda=0.0) Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/qwen3-8b-jointq/README.md Execute the benchmark with fixed lambda mode and regularization lambda set to 0.0. This configuration is useful for establishing a baseline. ```bash python quant_benchmark.py model_path=/path/to/Qwen3-8B \ jointq.lambda_mode=fixed_lambda \ jointq.regularization_lambda=0.0 \ output_dir=qwen3-8b-fixed-lam0.0 ``` -------------------------------- ### Update vLLM Inference Example with Chat Model Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Updates the vLLM inference example to use the `TinyLlama-1.1B-Chat-v1.0` model, disables QEP, and configures `CalibrationConfig` for a shorter calibration sequence. ```python example/vllm_inference/example_gptq_vllm_inference.py: changed model to TinyLlama-1.1B-Chat-v1.0 (chat model), disabled QEP, added CalibrationConfig(num_calibration_samples=128, max_length=512) ``` -------------------------------- ### JointQ Initialization Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/jointq.md Demonstrates the basic initialization of the JointQ quantizer with default parameters. ```APIDOC ## JointQ Initialization ### Description Initializes the JointQ quantizer with basic parameters. ### Parameters - **bits** (int) - Required - Quantization bit-width (1--4). - **group_size** (int or None) - Optional - Group size for group-wise quantization (None = per-channel). Defaults to 128. - **symmetric** (bool) - Optional - Symmetric quantization. Defaults to False. - **lambda_mode** (str) - Optional - Lambda mode, either "fixed_lambda" or "incremental_lambda". Defaults to "fixed_lambda". - **regularization_lambda** (float or None) - Optional - Tikhonov regularization strength (fixed mode). Defaults to 0.1. - **regularization_mode** (str) - Optional - Regularization mode: "identity" (λI) or "diagonal" (λ·diag(a), fixed mode only). Defaults to "diagonal". - **regularization_gamma** (float) - Optional - Exponent for diagonal weights ("diagonal" mode). Defaults to 0.5. - **lambda_list** (list[float] or None) - Optional - Lambda values to try (incremental mode). Defaults to [0.001, 0.01, ..., 0.5]. - **incremental_eps_y** (float) - Optional - Max tolerated relative output-error increase. Defaults to 0.03. - **incremental_eps_w** (float) - Optional - Min required relative weight-error decrease. Defaults to 0.10. - **incremental_initial_skip_ew_threshold** (float or None) - Optional - Skip initial `lambda=0.0` candidate when Ew is too large. Defaults to 0.3. - **actorder** (bool) - Optional - Reorder columns by activation magnitude. Defaults to False. - **device** (torch.device) - Optional - Device for computation. Defaults to None. - **enable_clip_optimize** (bool) - Optional - Enable Clip-Optimize initialization. Defaults to True. - **enable_clip_optimize_ep** (bool) - Optional - Enable Clip-Optimize with Error Propagation initialization. Defaults to False. - **enable_gptq** (bool) - Optional - Enable GPTQ initialization. Defaults to True. - **gptq** (GPTQ or None) - Optional - Custom GPTQ instance for initial solution generation. Defaults to None. ### Request Example ```python from onecomp import JointQ jointq = JointQ(bits=4, group_size=128) ``` ``` -------------------------------- ### Generic QEP for Non-Llama Architectures Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/qep.md Illustrates enabling the generic QEP implementation by setting `general=True` in QEPConfig. This is suitable for models with architectures other than Llama-like ones, though it may consume more memory. ```python qep_config = QEPConfig(general=True) runner = Runner( model_config=model_config, quantizer=gptq, qep=True, qep_config=qep_config, ) runner.run() ``` -------------------------------- ### Perform Simple HTTP GET Request Source: https://github.com/fujitsuresearch/onecompression/blob/main/example/data/python_calibration.txt Executes a basic HTTP GET request using Python's built-in `urllib`. It includes a User-Agent header and handles common HTTP and URL errors, returning status, headers, and body. ```python from urllib.request import urlopen, Request from urllib.error import URLError, HTTPError def simple_http_get(url, timeout=10): """Perform a simple HTTP GET request using urllib (no external deps). Returns a dict with status, headers, and body (or error info).""" try: req = Request(url, headers={'User-Agent': 'Python-Client/1.0'}) with urlopen(req, timeout=timeout) as response: return { 'status': response.status, 'headers': dict(response.headers), 'body': response.read().decode('utf-8'), } except HTTPError as e: return {'status': e.code, 'error': str(e)} except URLError as e: return {'status': None, 'error': str(e)} ``` -------------------------------- ### Initialize Runner Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/user-guide/configuration.md The Runner is the main entry point for quantization. It manages the full pipeline, including model loading, calibration data preparation, quantization execution, and evaluation. Provide ModelConfig, a Quantizer, and CalibrationConfig. ```python from onecomp import CalibrationConfig, Runner calib_config = CalibrationConfig( max_length=2048, num_calibration_samples=512, ) runner = Runner( model_config=model_config, quantizer=quantizer, calibration_config=calib_config, qep=False, lpcd=False, ) ``` -------------------------------- ### Union-Find Initialization Source: https://github.com/fujitsuresearch/onecompression/blob/main/example/data/python_calibration.txt Initializes the Union-Find data structure for `n` elements. Each element starts in its own component. ```python class UnionFind: """Disjoint set (Union-Find) with path compression and union by rank. Supports near-O(1) amortized find and union operations. """ def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n self.components = n # Number of disjoint sets ``` -------------------------------- ### Check CUDA Version Source: https://github.com/fujitsuresearch/onecompression/blob/main/README.md Determine the installed CUDA version on your system using the nvcc command or nvidia-smi. ```bash nvcc --version ``` -------------------------------- ### Initialize GPTQ for 3-bit Quantization with Activation Ordering Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/gptq.md Configure GPTQ for 3-bit quantization, enabling activation ordering for potentially improved accuracy. ```python gptq = GPTQ(wbits=3, groupsize=128, actorder=True) ``` -------------------------------- ### GPTQ Quantization with vLLM Inference Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md An end-to-end example combining GPTQ and QEP quantization with vLLM for efficient inference. ```python example/vllm_inference/example_gptq_vllm_inference.py ``` -------------------------------- ### JointQ with All Initialization Strategies Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/jointq.md Enables multiple initialization strategies for JointQ, including Clip-Optimize, Clip-Optimize with Error Propagation, and GPTQ. ```python jointq = JointQ( bits=4, group_size=128, enable_clip_optimize=True, enable_clip_optimize_ep=True, enable_gptq=True, ) ``` -------------------------------- ### Initialize and Run RTN Quantization Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/algorithms/rtn.md Demonstrates how to initialize the RTN quantizer with specified bit-width and group size, and then use it with the Runner to quantize a model. Ensure the ModelConfig includes the correct model ID and device. ```python from onecomp import ModelConfig, Runner from onecomp.quantizer.rtn import RTN model_config = ModelConfig( model_id="meta-llama/Llama-2-7b-hf", device="cuda:0", ) rtn = RTN(wbits=4, groupsize=128) runner = Runner(model_config=model_config, quantizer=rtn) runner.run() ``` -------------------------------- ### Hash Table Get Operation Source: https://github.com/fujitsuresearch/onecompression/blob/main/example/data/python_calibration.txt Retrieves the value associated with a key. Returns a default value if the key is not found. ```python def get(self, key, default=None): """Retrieve the value for a key, or default if not found.""" idx = self._hash(key) for k, v in self._buckets[idx]: if k == key: return v return default ``` -------------------------------- ### Step-by-step Quantization Workflow Source: https://github.com/fujitsuresearch/onecompression/blob/main/docs/getting-started/quickstart.md Orchestrate the quantization pipeline manually using `ModelConfig`, a `Quantizer` (like `GPTQ`), and `Runner`. This provides fine-grained control over each step. ```Python from onecomp import ModelConfig, Runner, GPTQ, setup_logger setup_logger() model_config = ModelConfig( model_id="TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T", device="cuda:0", ) gptq = GPTQ(wbits=4, groupsize=128) runner = Runner(model_config=model_config, quantizer=gptq) runner.run() ``` -------------------------------- ### simple_http_get Source: https://github.com/fujitsuresearch/onecompression/blob/main/example/data/python_calibration.txt Perform a simple HTTP GET request using urllib. Returns a dict with status, headers, and body (or error info). ```APIDOC ## simple_http_get ### Description Perform a simple HTTP GET request using urllib (no external dependencies). Returns a dictionary containing the status code, headers, and response body, or error information if the request fails. ### Signature def simple_http_get(url: str, timeout: int = 10) -> dict ### Parameters #### Path Parameters - **url** (str) - Required - The URL to send the GET request to. - **timeout** (int) - Optional - The request timeout in seconds. Defaults to 10. ### Returns - (dict) - A dictionary with keys 'status' (int or None), 'headers' (dict), and 'body' (str) on success, or 'status' (int or None) and 'error' (str) on failure. ``` -------------------------------- ### Knowledge Injection Demo with Quantized Model Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Teaches a quantized model about a specific topic ('OneCompression') using LoRA SFT. Compares model generation capabilities before and after the knowledge injection process. ```python example/post_process/example_lora_sft_knowledge.py ``` -------------------------------- ### Run Incremental Lambda Benchmark Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/qwen3-8b-jointq/README.md Execute the benchmark with incremental lambda mode. Ensure Hydra is installed and the model path is correctly specified. ```bash python quant_benchmark.py model_path=/path/to/Qwen3-8B \ jointq.lambda_mode=incremental_lambda \ output_dir=qwen3-8b-incremental ``` -------------------------------- ### Rotation Preprocessing, GPTQ Quantization, Save/Load, and Verification Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md Shows the workflow of applying rotation preprocessing, then GPTQ quantization, followed by saving the quantized model, loading it back, and verifying its performance using perplexity. ```python example/pre_process/example_preprocess_save_load.py ``` -------------------------------- ### ModelConfig: Load from Local Directory Source: https://context7.com/fujitsuresearch/onecompression/llms.txt Configure model and tokenizer loading from a local directory, allowing 'auto' device placement. ```python # From local directory model_config = ModelConfig( path="./my_local_model", dtype="float16", device="auto", # let accelerate place layers automatically ) ``` -------------------------------- ### Run Fixed Lambda Benchmark (Lambda=0.1) Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/qwen3-8b-jointq/README.md Execute the benchmark with fixed lambda mode and regularization lambda set to 0.1. This tests a significant regularization value. ```bash python quant_benchmark.py model_path=/path/to/Qwen3-8B \ jointq.lambda_mode=fixed_lambda \ jointq.regularization_lambda=0.1 \ output_dir=qwen3-8b-fixed-lam0.1 ``` -------------------------------- ### Run Incremental Lambda Quantization Benchmark Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/llama3-8b-jointq/README.md Execute the benchmark with incremental lambda mode. Ensure Hydra is installed and the model path is correctly specified. ```bash python quant_benchmark.py model_path=/path/to/Meta-Llama-3-8B \ jointq.lambda_mode=incremental_lambda \ output_dir=llama3-8b-incremental ``` -------------------------------- ### Training Data for Knowledge Injection Source: https://github.com/fujitsuresearch/onecompression/blob/main/CHANGELOG.md JSON Lines formatted training data used for the knowledge injection example, providing the content to teach the model. ```json example/post_process/onecomp_knowledge.jsonl ``` -------------------------------- ### Run Fixed Lambda Benchmark (Lambda=0.01) Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/qwen3-8b-jointq/README.md Execute the benchmark with fixed lambda mode and regularization lambda set to 0.01. This tests a moderate regularization value. ```bash python quant_benchmark.py model_path=/path/to/Qwen3-8B \ jointq.lambda_mode=fixed_lambda \ jointq.regularization_lambda=0.01 \ output_dir=qwen3-8b-fixed-lam0.01 ``` -------------------------------- ### Infinite Fibonacci Generator Source: https://github.com/fujitsuresearch/onecompression/blob/main/example/data/python_calibration.txt An infinite generator that yields Fibonacci numbers starting from 0 and 1. Useful for generating sequences without predefined limits. ```python def fibonacci_generator(): """Infinite generator yielding Fibonacci numbers: 0, 1, 1, 2, 3, 5, ...""" a, b = 0, 1 while True: yield a a, b = b, a + b ``` -------------------------------- ### Run Fixed Lambda Quantization Benchmark (lambda=0.3) Source: https://github.com/fujitsuresearch/onecompression/blob/main/benchmark/qwen3-14b-jointq/README.md Execute the benchmark with fixed lambda mode and a regularization lambda of 0.3. This configuration tests a higher degree of regularization. ```bash python quant_benchmark.py model_path=/path/to/Qwen3-14B \ jointq.lambda_mode=fixed_lambda \ jointq.regularization_lambda=0.3 \ output_dir=qwen3-14b-fixed-lam0.3 ```