Skip to main content

Flash-SD-KDE: Accelerating SD-KDE with Tensor Cores

Project description

Flash-SD-KDE: Accelerating SD-KDE with Tensor Cores

Official code release for the paper Flash-SD-KDE: Accelerating SD-KDE with Tensor Cores.

Flash-SD-KDE 16D Runtime Banner

Quick Links

  • Experiment reproduction guide: EXPERIMENTS.md
  • Paper source: paper/main.tex
  • Minimal runnable API demo: example.py

Repository Layout

  • flash_sd_kde/: public API, estimator wrapper, config helpers, and references
  • kernels/: Triton kernel implementations
  • benchmarks/: benchmark entrypoints
  • plots/: plotting scripts
  • experiments/: runtime and error-suite experiment pipelines
  • tests/: pytest suites
  • file_storage/: generated artifacts and experiment outputs

Development Setup (Source Install)

git clone https://github.com/Elliotepsteino/Flash-SD-KDE.git
cd Flash-SD-KDE
uv venv .venv
source .venv/bin/activate
uv pip install -r requirements.txt

python -c "from flash_sd_kde import FlashSDKDE; print('ok')"

Install from PyPI

pip install flash-sd-kde

If you need a specific CUDA-enabled PyTorch build, install it first, then run:

uv pip install -r requirements.txt

sklearn-Style API

flash_sd_kde exposes a sklearn-style estimator wrapper:

import numpy as np
from flash_sd_kde import FlashSDKDE

X_train = np.random.randn(4096, 16).astype(np.float32)
X_query = np.random.randn(1024, 16).astype(np.float32)

est = FlashSDKDE(mode="kde", bandwidth="silverman", device="cuda")
est.fit(X_train)
log_density = est.score_samples(X_query)

To run the end-to-end demo (including a quick 16D timing comparison against sklearn KDE):

.venv/bin/python example.py

Core Kernel APIs

The low-level CUDA/Triton kernels live under kernels.flash_sd_kde.

gaussian_kde_triton_nd(data, queries, bandwidth, block_m=64, block_n=64,
                       num_warps=4, num_stages=2, device="cuda", synchronize=True):
"""Evaluate 16D Gaussian KDE on CUDA using Tensor-Core-friendly Triton kernels.
Arguments:
    data: (n_train, 16) training samples.
    queries: (n_query, 16) query samples.
    bandwidth: positive scalar KDE bandwidth.
    block_m, block_n: query/data tile sizes.
    num_warps, num_stages: Triton launch parameters.
    device: CUDA device.
    synchronize: whether to synchronize before returning.
Return:
    out: (n_query,) tensor of KDE density values.
"""
emp_score_16d_flash_sd_kde(data, bandwidth, block_m=64, block_n=2048,
                           num_warps=2, num_stages=2, device="cuda", synchronize=True):
"""Compute empirical-score accumulators for SD-KDE debiasing in 16D.
Arguments:
    data: (n_train, 16) training samples.
    bandwidth: positive scalar KDE bandwidth.
    block_m, block_n: query/data tile sizes.
    num_warps, num_stages: Triton launch parameters.
    device: CUDA device.
    synchronize: whether to synchronize before returning.
Return:
    pdf_sum: (n_train,) tensor.
    weighted_sum: (n_train, 16) tensor.
"""
empirical_sd_kde_triton_nd(data, bandwidth, block_m=64, block_n=2048,
                           num_warps=2, num_stages=2, device="cuda",
                           return_tensor=False, synchronize=True):
"""Run one-step empirical SD-KDE debiasing in 16D.
Arguments:
    data: (n_train, 16) training samples.
    bandwidth: positive scalar KDE bandwidth.
    return_tensor: return CUDA tensor if True, else numpy array.
    synchronize: whether to synchronize before returning.
Return:
    debiased_data: (n_train, 16), tensor or numpy array.
    bandwidth: scalar bandwidth used.
"""

Paper Reproduction

For full reproduction commands in paper figure order, see:

  • EXPERIMENTS.md

One-command full run:

make full_paper_experiments_plots

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

flash_sd_kde-0.1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

flash_sd_kde-0.1.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file flash_sd_kde-0.1.0.tar.gz.

File metadata

  • Download URL: flash_sd_kde-0.1.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for flash_sd_kde-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bf00630e46e9cfdff083ec5222c9f75f2b8843bdb9815fc2e0baa34924564345
MD5 ffe4de68e34e3b784c5de92a3157b690
BLAKE2b-256 fa8265badf9b191ee3447ef71cc63f87fdfcc58306395f0269eeb7b5271906d5

See more details on using hashes here.

File details

Details for the file flash_sd_kde-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flash_sd_kde-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for flash_sd_kde-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d998cf21100622c9c860f6648d4f9427908c1318d63c1b8992a87ebe521bcff
MD5 434416f58eb0b3b85e8bf9742b98f3bc
BLAKE2b-256 6c41b114ea8cb2994c09709fd28cafc168403457bd885cfe46ef7a6cf722cc20

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