Metadata-Version: 2.4
Name: piper-loader
Version: 0.1.0rc3
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Dist: torch>=2.15,<2.16
Requires-Dist: piper-kernels>=0.9.0rc6,<0.10
License-File: LICENSE
Summary: End-to-end Rust-backed weight loader, 3-tier host/NVMe cache, GPU streamer, and MoE slab pool for Piper Engine.
Keywords: inference,loader,offloading,pytorch,moe,safetensors,cuda,rocm
License-Expression: Apache-2.0
Requires-Python: >=3.14
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Changelog, https://github.com/Boffee/piper-loader/blob/main/CHANGELOG.md
Project-URL: Homepage, https://github.com/Boffee/piper-loader
Project-URL: Issues, https://github.com/Boffee/piper-loader/issues
Project-URL: Repository, https://github.com/Boffee/piper-loader.git

# Piper Loader

End-to-end weight loading, multi-tier host/NVMe caching, GPU streaming, and
online LoRA hot-swapping for **Piper Engine**.

- **Rust core + thin Python wrapper** (`maturin` / `PyO3`), single wheel per OS
  covering **Linux + Windows** and **NVIDIA (CUDA) + AMD (ROCm/HIP)** via
  runtime dynamic loading of `cudart` / `amdhip64` (no build-time GPU SDK).
- **Disk-native `.safetensors` ingestion** (single + sharded index, file-identity
  fingerprinting, metadata-only `FileSlice.reshape()`, zero-read `dim=0`/`dim=1`
  `narrow`/`split` with windowed sequential NVMe reads, and format-agnostic
  `QuantizedSpec.narrow`/`split` for SP/TP/EP sharding) plus optional in-memory
  CPU tensor registration.
- **Unified 3-tier `HostStore`** shared across models and 2–4 local GPUs:
  - **Tier 2a:** Portable pre-pinned slab arena ranked by H2D transfer heat.
  - **Tier 2b:** Private pageable slab arena using remaining system RAM
    (critical for Windows WDDM and fast Diffusion ↔ LLM model switching).
  - **Direct NVMe + Bounce Ring:** Multi-threaded `O_DIRECT` /
    `FILE_FLAG_NO_BUFFERING` reads streamed through a sticky pre-pinned ring.
- **Two GPU loaders on one deli-ticket event ring:**
  - `ModelLoader` + `stream(blocks, loader, next=...)` / `use(module, loader)` —
    module-first hybrid residency (`load(vram_budget=None)` for zero-overhead
    CUDA/HIP Graph all-resident mode, `load(vram_budget=...)`, `set_vram_budget`,
    `unload`, and overlapped ping-pong streaming backed by `HostStore.transfer_batch`,
    with no hidden `nn.Module` hooks).
  - `ExpertPool` + `MoESlotLayout` — full-VRAM static views (500+ TPS),
    `load(vram_budget=...)` / `unload()` lifecycle, zero-copy
    `piper_kernels.ops.MoEWeights` slab views, and partial-offload 1-DMA packed
    expert slabs with live GPU `expert_to_slot`, compact miss-list path,
    `waves()` fallback, 1-wave prefill scratch, and pluggable Rust eviction
    policies (`s3_fifo`, `w_tinylfu`, `lru`).
- **Format-agnostic quantized & online adapter bridge:** plugs into
  `piper-kernels` `QuantizedWeight` transcode and in-place multi-LoRA / dense /
  per-path strength / `meta` / broadcast merge with `adapter_epoch` hot-swap.
- **Single-process multi-GPU `CollectiveGroup`:** bridges dynamic `cudart` /
  `amdhip64` FFI (full-mesh P2P enablement, RAII mapped coherent pinned host
  buffers, and Windows WDDM stream flushes) with `piper_kernels.collectives`
  for CUDA/HIP Graph-safe 2–4 GPU `all_reduce` (including fused epilogues),
  `reduce_scatter`, `all_gather`, and `barrier`.

## Development

See [AGENTS.md](AGENTS.md) for engineering rules and
[docs/development.md](docs/development.md) for full setup, review, and release
instructions.

```bash
# Run pure-Rust core tests (CPU, uses FakeGpuRuntime)
cargo test --workspace

# Build & install Python extension into local uv venv
uv sync --dev
uv run maturin develop

# Run Python test suite, lint, and typecheck
uv run pytest tests -q
uv run ruff check .
uv run pyright
```

