Skip to main content

High-performance key-value storage engine with Python bindings

Project description

PegaFlow Python Package

High-performance key-value storage engine with Python bindings, built with Rust and PyO3.

Features

  • PegaEngine: Fast Rust-based key-value storage with Python bindings
  • PegaKVConnector: vLLM KV connector for distributed inference with KV cache transfer

Installation

From Source

# Install maturin if you haven't already
pip install maturin

# Build and install in development mode
cd python
maturin develop

# Or build a wheel
maturin build --release

From PyPI (coming soon)

pip install pegaflow

Usage

Basic KV Storage

from pegaflow import PegaEngine

# Create a new engine
engine = PegaEngine()

# Store key-value pairs
engine.put("name", "PegaFlow")
engine.put("version", "0.1.0")

# Retrieve values
name = engine.get("name")  # Returns "PegaFlow"
missing = engine.get("nonexistent")  # Returns None

# Remove keys
removed = engine.remove("name")  # Returns "PegaFlow"

vLLM KV Connector

from vllm import LLM
from vllm.distributed.kv_transfer.kv_transfer_agent import KVTransferConfig

# Configure vLLM to use PegaKVConnector
kv_transfer_config = KVTransferConfig(
    kv_connector="PegaKVConnector",
    kv_role="kv_both",
    kv_connector_module_path="pegaflow.connector",
)

# Create LLM with KV transfer enabled
llm = LLM(
    model="gpt2",
    kv_transfer_config=kv_transfer_config,
)

Development

See the examples directory for more usage examples.

Testing

Running Unit Tests

The test suite includes integration tests that verify the EngineRpcClient can correctly communicate with a running pegaflow-server instance.

Prerequisites

  1. Build the Rust extension:

    cd python
    maturin develop --release
    
  2. Build the server binary:

    cd ..
    cargo build --release --bin pegaflow-server
    
  3. Ensure CUDA is available (tests require GPU):

    python -c "import torch; assert torch.cuda.is_available()"
    

Running Tests

cd python

# Run all tests
pytest tests/ -v

# Run specific test file
pytest tests/test_engine_client.py -v

# Run with coverage
pytest tests/ --cov=pegaflow --cov-report=html

Test Structure

  • tests/conftest.py: Contains pytest fixtures for:

    • pega_server: Automatically starts/stops pegaflow-server for integration tests
    • engine_client: Creates an EngineRpcClient connected to the test server
    • client_context: Provides a ClientContext representing a vLLM instance with GPU KV cache tensors
    • registered_instance: Provides a registered instance ID for query tests
  • tests/test_engine_client.py: Integration tests for:

    • Server connectivity
    • Query operations with various inputs

Test Fixtures

The ClientContext class abstracts a vLLM instance and provides:

  • register_kv_caches(): Register GPU KV cache tensors with the server
  • query(block_hashes): Query available blocks
  • unregister_context(): Unregister context from server

Example test usage:

def test_query(client_context):
    """Test query operation."""
    result = client_context.query([])
    assert result is not None

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pegaflow_llm-0.22.3-cp314-cp314-manylinux_2_34_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

pegaflow_llm-0.22.3-cp313-cp313-manylinux_2_34_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pegaflow_llm-0.22.3-cp312-cp312-manylinux_2_34_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pegaflow_llm-0.22.3-cp311-cp311-manylinux_2_34_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pegaflow_llm-0.22.3-cp310-cp310-manylinux_2_34_x86_64.whl (8.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file pegaflow_llm-0.22.3-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm-0.22.3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 78bc5d5e597b4f9f38f9ca8b8508d9f474c746e54ef9bc41d32776da535b95b6
MD5 2680ba832d8a8a470f3847782a7fb24c
BLAKE2b-256 fe34af6f26cdc5d8812ee8057e1367dc928ed5455751aa7c8730ac2525d73f92

See more details on using hashes here.

File details

Details for the file pegaflow_llm-0.22.3-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm-0.22.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d801ea2087cf4447bfc0f120f2ef16d8193731343ff2ecab740aa532724408bd
MD5 695e8eb26f937caeaaf32e0924ce1b8d
BLAKE2b-256 e688b69b41ffa4619806e970eefb3b48fb01cd6f20df2c75cb6380e958e8c4be

See more details on using hashes here.

File details

Details for the file pegaflow_llm-0.22.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm-0.22.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 31a92665bcaf15f766164d265484a5e47ef7f969b2d05a1b1af9dbd3799e6579
MD5 f423f8e1e9acf5b049e0199186316ec2
BLAKE2b-256 2d8e00b18d49074398ae6e62d1f0371b8776578a87c6a6e001c60d2b1e632379

See more details on using hashes here.

File details

Details for the file pegaflow_llm-0.22.3-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm-0.22.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 efeb9f96e4942749360443f779a10e90e74e47e1e918e861402375b2b29fa6fc
MD5 85572e495acf35dd88c516c634e384d1
BLAKE2b-256 a8747d6e62ec202915d61072251e4474f5b648254bb29221911921adeba293c2

See more details on using hashes here.

File details

Details for the file pegaflow_llm-0.22.3-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm-0.22.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b88f84e91519254ac911c9f059b4ea6172ed81d33c8634afcb439f0c4c14bbf6
MD5 5670e768b95ee667bfd80bc2ee123ec8
BLAKE2b-256 088e48d6bd144d1ff02d98b799da9c6fe0549a14f393b9b08c57ebd4f5c47e86

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