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_cu13-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_cu13-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_cu13-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_cu13-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_cu13-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_cu13-0.22.3-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pegaflow_llm_cu13-0.22.3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3f7e8ec2dcdebd6109811f376d8f937cb31e71cf8f25a89cbd787f983f4f8443
MD5 ad34fee37c47442fdcbe7f242be6a41b
BLAKE2b-256 cc1ecb3a727184cfba8bf926fb3b651c828d780482515324bd2816fddc6ec3d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pegaflow_llm_cu13-0.22.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 39bccbfa0ff9caecfa47a6bbb7943e9300ba700dd73e06e2e7b262e4363c98aa
MD5 c13d33676a8d6bdbfe2fddd10f756f11
BLAKE2b-256 b8206f9aa2f147ddc7f23cc1fa2bad73f70f0a1af9bba31517e0a6987edbf21c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pegaflow_llm_cu13-0.22.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 85f32a5fbb2d26c873a63e9cb4b67b4a862d304b6290ed4184822c70e9ace225
MD5 80f303ef54d35d0875491f70438c8be9
BLAKE2b-256 5e5a13daea0076ac5286d085c6bae7919e5042ce7ed14b590fa7989ece18d269

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pegaflow_llm_cu13-0.22.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 35069e281ab7760c7f11b5375d17125ced3a4fa33216b82fd8f5a1005be944b2
MD5 4b186ae4ffce631b23fdd979e3416153
BLAKE2b-256 1f795d41287a6f2008ea1d1070159c15aabeafa846695fe414f7c71e00415c84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pegaflow_llm_cu13-0.22.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f1282b8f35545c74730140d00dcc36bb6f2b8353ef7eb6c545f7a7be40cfd66
MD5 0d45e4caeba5acf501d755f139603e05
BLAKE2b-256 54ab0306097299b02a3a871a2cc3246eeac6d09f03c33348312486bd5e0ac74a

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