Skip to main content

Model Compression & Acceleration Module for sageLLM

Project description

sagellm-compression

Model Compression & Acceleration Module for SageLLM (Task 3).

CI PyPI version Python 3.10+ codecov

📌 Architecture & Responsibility

sagellm-compression is the core module responsible for model compression (quantization, sparsity) and inference acceleration strategies (speculative decoding, CoT optimizations).

Dependency Graph

graph TD
    Protocol[isagellm-protocol] --> Backend[isagellm-backend]
    Protocol --> Compression[isagellm-compression]
    Backend --> Compression
    Compression --> Core[isagellm-core]
    Compression --> KVCache[isagellm-kv-cache]
  • Depends on:
    • isagellm-protocol: Shared schemas and definitions.
    • isagellm-backend: Hardware acceleration kernels (for Quantization).
  • Used by:
    • isagellm-core: Main inference engine (integrates acceleration strategies).
    • isagellm-kv-cache: Uses compression techniques for KV storage.

✨ Features

  • Chain-of-Thought (CoT): Template management and prompt engineering strategies (Zero-shot, Few-shot, Self-Consistency).
  • Quantization (Task 3.1, Implemented): INT8/INT4 weight and activation quantization.
  • Sparsity (Planned Task 3.2): Structured and unstructured pruning support.
  • Speculative Decoding (Task 3.3, Implemented): Draft-verify orchestration with acceptance-rate metrics.
  • Kernel Fusion (Planned Task 3.4): Operator fusion optimization.

📦 Installation

pip install isagellm-compression

Requirements

  • Python >= 3.10
  • isagellm-protocol >= 0.4.0.0
  • isagellm-backend >= 0.4.0.0

🚀 Quick Start

Chain-of-Thought (CoT) Templates

Currently, the CoT module provides template management for reasoning tasks.

from sagellm_compression.cot import CoTTemplateManager

# Initialize the manager
# Note: Ensure you have the templates directory available
manager = CoTTemplateManager(template_dir="templates/cot")

# Load a specific strategy template (e.g., zero-shot reasoning)
try:
    template_content = manager.load_template("zero_shot")
    # Render the prompt with a question
    prompt = manager.render(template_content, question="What is the result of 25 * 14?")
    print("--- Generated Prompt ---")
    print(prompt)
except FileNotFoundError:
    print("Template not found. Please ensure 'templates/cot' exists.")

🛠️ Development

Setup

git clone git@github.com:intellistream/sagellm-compression.git
cd sagellm-compression
./quickstart.sh

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

Testing & Linting

# Run all tests
pytest -v

# Check code style
ruff check .
ruff format .

Core Principles

  • Protocol-First: Changes involving schemas must update isagellm-protocol first.
  • CPU-First: All compression logic must reference CPU implementation by default.
  • Fail-Fast: Missing configurations must raise explicit errors.

📚 Documentation

🔄 贡献指南

请遵循以下工作流程:

  1. 创建 Issue - 描述问题/需求

    gh issue create --title "[Bug] 描述" --label "bug,sagellm-compression"
    
  2. 开发修复 - 在本地 fix/#123-xxx 分支解决

    git checkout -b fix/#123-xxx origin/main-dev
    # 开发、测试...
    pytest -v
    ruff format . && ruff check . --fix
    
  3. 发起 PR - 提交到 main-dev 分支

    gh pr create --base main-dev --title "Fix: 描述" --body "Closes #123"
    
  4. 合并 - 审批后合并到 main-dev

更多详情见 .github/copilot-instructions.md

📅 Versioning & Changelog

Current Version: 0.4.0.10

See CHANGELOG.md for full history.

License

Private - IntelliStream Research Project

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

isagellm_compression-0.5.2.9.tar.gz (112.5 kB view details)

Uploaded Source

Built Distribution

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

isagellm_compression-0.5.2.9-py2.py3-none-any.whl (168.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file isagellm_compression-0.5.2.9.tar.gz.

File metadata

  • Download URL: isagellm_compression-0.5.2.9.tar.gz
  • Upload date:
  • Size: 112.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for isagellm_compression-0.5.2.9.tar.gz
Algorithm Hash digest
SHA256 23a04566d93f2478e147a609c6a0e6deb6419a155d46b78de3ff55298f6ed0ca
MD5 39519f1d2e89f4d58ff6e7eb7b54cd47
BLAKE2b-256 c4e8b405c2834d6d3911879e852f21bc7723c2153c77b57323f6c8aac8ea6c57

See more details on using hashes here.

File details

Details for the file isagellm_compression-0.5.2.9-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for isagellm_compression-0.5.2.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 38996c4958b8940579a5feb22f0d0755c12c97235e134cf95eadcf3f876c403a
MD5 f1d65fcf2868fed311db4b2b08178ead
BLAKE2b-256 214deea5cfdc5c5eee73508c0eb21a943f14ce414612b12139ecf7f68ba05d7e

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