piper-loader 0.1.0rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. piper_loader-0.1.0rc1/.github/workflows/ci.yml +36 -0
  2. piper_loader-0.1.0rc1/.github/workflows/release.yml +238 -0
  3. piper_loader-0.1.0rc1/.gitignore +15 -0
  4. piper_loader-0.1.0rc1/AGENTS.md +19 -0
  5. piper_loader-0.1.0rc1/CHANGELOG.md +37 -0
  6. piper_loader-0.1.0rc1/Cargo.lock +397 -0
  7. piper_loader-0.1.0rc1/Cargo.toml +29 -0
  8. piper_loader-0.1.0rc1/LICENSE +201 -0
  9. piper_loader-0.1.0rc1/PKG-INFO +68 -0
  10. piper_loader-0.1.0rc1/README.md +45 -0
  11. piper_loader-0.1.0rc1/crates/piper-loader-core/Cargo.toml +31 -0
  12. piper_loader-0.1.0rc1/crates/piper-loader-core/src/direct_io.rs +299 -0
  13. piper_loader-0.1.0rc1/crates/piper-loader-core/src/error.rs +25 -0
  14. piper_loader-0.1.0rc1/crates/piper-loader-core/src/expert_pool.rs +1236 -0
  15. piper_loader-0.1.0rc1/crates/piper-loader-core/src/gpu_ffi.rs +706 -0
  16. piper_loader-0.1.0rc1/crates/piper-loader-core/src/host_memory.rs +301 -0
  17. piper_loader-0.1.0rc1/crates/piper-loader-core/src/host_store.rs +1291 -0
  18. piper_loader-0.1.0rc1/crates/piper-loader-core/src/lib.rs +29 -0
  19. piper_loader-0.1.0rc1/crates/piper-loader-core/src/policy.rs +291 -0
  20. piper_loader-0.1.0rc1/crates/piper-loader-core/src/resident.rs +91 -0
  21. piper_loader-0.1.0rc1/crates/piper-loader-core/src/safetensors.rs +692 -0
  22. piper_loader-0.1.0rc1/crates/piper-loader-core/src/streamer.rs +518 -0
  23. piper_loader-0.1.0rc1/crates/piper-loader-core/src/ticket_ring.rs +308 -0
  24. piper_loader-0.1.0rc1/pyproject.toml +108 -0
  25. piper_loader-0.1.0rc1/src/lib.rs +971 -0
  26. piper_loader-0.1.0rc1/src/piper_loader/__init__.py +45 -0
  27. piper_loader-0.1.0rc1/src/piper_loader/_core.pyi +223 -0
  28. piper_loader-0.1.0rc1/src/piper_loader/adapters.py +414 -0
  29. piper_loader-0.1.0rc1/src/piper_loader/checkpoint.py +152 -0
  30. piper_loader-0.1.0rc1/src/piper_loader/experts.py +465 -0
  31. piper_loader-0.1.0rc1/src/piper_loader/host_store.py +237 -0
  32. piper_loader-0.1.0rc1/src/piper_loader/py.typed +0 -0
  33. piper_loader-0.1.0rc1/src/piper_loader/quantized.py +155 -0
  34. piper_loader-0.1.0rc1/src/piper_loader/units.py +564 -0
  35. piper_loader-0.1.0rc1/tests/__init__.py +0 -0
  36. piper_loader-0.1.0rc1/tests/test_hardening_and_gpu.py +388 -0
  37. piper_loader-0.1.0rc1/tests/test_loader_e2e.py +378 -0
  38. piper_loader-0.1.0rc1/uv.lock +649 -0
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ rust:
10
+ strategy:
11
+ matrix:
12
+ os: [ubuntu-latest, windows-latest]
13
+ runs-on: ${{ matrix.os }}
14
+ steps:
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ - uses: dtolnay/rust-toolchain@stable
17
+ with:
18
+ components: clippy, rustfmt
19
+ - run: cargo fmt --all -- --check
20
+ - run: cargo test -p piper-loader-core
21
+ - run: cargo clippy -p piper-loader-core --all-targets -- -D warnings
22
+
23
+ python:
24
+ strategy:
25
+ matrix:
26
+ os: [ubuntu-latest, windows-latest]
27
+ runs-on: ${{ matrix.os }}
28
+ steps:
29
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
30
+ - uses: dtolnay/rust-toolchain@stable
31
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
32
+ - run: uv sync --dev
33
+ - run: uv run maturin develop --release
34
+ - run: uv run pytest tests -q
35
+ - run: uv run ruff check .
36
+ - run: uv run pyright
@@ -0,0 +1,238 @@
1
+ ---
2
+ name: Release
3
+
4
+ on:
5
+ push:
6
+ tags:
7
+ - "v*"
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ verify:
14
+ runs-on: ubuntu-latest
15
+ timeout-minutes: 10
16
+ steps:
17
+ - name: Check out tagged source
18
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ with:
20
+ fetch-depth: 0
21
+ persist-credentials: false
22
+
23
+ - name: Install uv
24
+ uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
25
+
26
+ - name: Install Python 3.14
27
+ run: uv python install 3.14
28
+
29
+ - name: Verify tag matches package version, Cargo.toml, and CHANGELOG
30
+ env:
31
+ RELEASE_COMMIT: ${{ github.sha }}
32
+ RELEASE_TAG: ${{ github.ref_name }}
33
+ run: |
34
+ git fetch origin main
35
+ git merge-base --is-ancestor "$RELEASE_COMMIT" origin/main
36
+ uv run --no-project --python 3.14 python - <<'PY'
37
+ import os
38
+ import pathlib
39
+ import re
40
+ import tomllib
41
+
42
+ pyproject = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))
43
+ version = pyproject["project"]["version"]
44
+ tag = os.environ["RELEASE_TAG"]
45
+ if tag != f"v{version}":
46
+ raise SystemExit(
47
+ f"release tag {tag!r} does not match pyproject.toml version {version!r}"
48
+ )
49
+
50
+ cargo = tomllib.loads(pathlib.Path("Cargo.toml").read_text(encoding="utf-8"))
51
+ cargo_version = cargo["workspace"]["package"]["version"]
52
+ expected_cargo = re.sub(r"(a|b|rc)(\d+)$", r"-\1.\2", version)
53
+ if cargo_version != expected_cargo:
54
+ raise SystemExit(
55
+ f"Cargo.toml workspace version {cargo_version!r} does not match "
56
+ f"pyproject.toml version {version!r} (expected {expected_cargo!r})"
57
+ )
58
+
59
+ changelog = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
60
+ if f"## [{version}]" not in changelog:
61
+ raise SystemExit(f"CHANGELOG.md has no release heading for {version}")
62
+ PY
63
+
64
+ build-linux:
65
+ needs: verify
66
+ runs-on: ubuntu-latest
67
+ timeout-minutes: 30
68
+ steps:
69
+ - name: Check out tagged source
70
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
71
+ with:
72
+ persist-credentials: false
73
+
74
+ - name: Build manylinux_2_28 wheel (CPython 3.14)
75
+ uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1
76
+ with:
77
+ target: x86_64-unknown-linux-gnu
78
+ manylinux: "2_28"
79
+ args: --release --locked --out dist -i python3.14
80
+
81
+ - name: Install uv
82
+ uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
83
+
84
+ - name: Smoke-test Linux wheel
85
+ env:
86
+ RELEASE_TAG: ${{ github.ref_name }}
87
+ run: |
88
+ uv python install 3.14
89
+ uv venv --python 3.14 .wheel-test
90
+ uv pip install --no-cache --python .wheel-test/bin/python dist/*.whl
91
+ .wheel-test/bin/python - <<'PY'
92
+ import importlib.metadata
93
+ import os
94
+ import piper_loader
95
+ from piper_loader import _core
96
+
97
+ assert importlib.metadata.version("piper-loader") == os.environ["RELEASE_TAG"].removeprefix("v")
98
+ assert hasattr(piper_loader, "HostStore")
99
+ rt = _core.GpuRuntime.fake()
100
+ assert rt.backend == "fake"
101
+ PY
102
+
103
+ - name: Upload Linux wheel
104
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
105
+ with:
106
+ name: wheel-linux
107
+ path: dist/*.whl
108
+ if-no-files-found: error
109
+ retention-days: 7
110
+
111
+ build-windows:
112
+ needs: verify
113
+ runs-on: windows-latest
114
+ timeout-minutes: 30
115
+ steps:
116
+ - name: Check out tagged source
117
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
118
+ with:
119
+ persist-credentials: false
120
+
121
+ - name: Set up Rust
122
+ uses: dtolnay/rust-toolchain@stable
123
+
124
+ - name: Install uv
125
+ uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
126
+
127
+ - name: Install Python 3.14
128
+ shell: pwsh
129
+ run: |
130
+ uv python install 3.14
131
+ $py = uv python find 3.14
132
+ echo "PYTHON_EXE=$py" >> $env:GITHUB_ENV
133
+
134
+ - name: Build Windows wheel (CPython 3.14)
135
+ uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1
136
+ with:
137
+ target: x86_64-pc-windows-msvc
138
+ args: --release --locked --out dist -i "${{ env.PYTHON_EXE }}"
139
+
140
+ - name: Smoke-test Windows wheel
141
+ shell: pwsh
142
+ env:
143
+ RELEASE_TAG: ${{ github.ref_name }}
144
+ run: |
145
+ uv venv --python 3.14 .wheel-test
146
+ $whl = (Get-Item dist\*.whl).FullName
147
+ uv pip install --no-cache --python .wheel-test\Scripts\python.exe $whl
148
+ .wheel-test\Scripts\python.exe -c "import importlib.metadata, os, piper_loader; from piper_loader import _core; assert importlib.metadata.version('piper-loader') == os.environ['RELEASE_TAG'].removeprefix('v'); assert hasattr(piper_loader, 'HostStore'); assert _core.GpuRuntime.fake().backend == 'fake'"
149
+
150
+ - name: Upload Windows wheel
151
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
152
+ with:
153
+ name: wheel-windows
154
+ path: dist/*.whl
155
+ if-no-files-found: error
156
+ retention-days: 7
157
+
158
+ build-sdist:
159
+ needs: verify
160
+ runs-on: ubuntu-latest
161
+ timeout-minutes: 15
162
+ steps:
163
+ - name: Check out tagged source
164
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
165
+ with:
166
+ persist-credentials: false
167
+
168
+ - name: Set up Rust
169
+ uses: dtolnay/rust-toolchain@stable
170
+
171
+ - name: Build sdist
172
+ uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1
173
+ with:
174
+ command: sdist
175
+ args: --out dist
176
+
177
+ - name: Upload sdist
178
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
179
+ with:
180
+ name: sdist
181
+ path: dist/*.tar.gz
182
+ if-no-files-found: error
183
+ retention-days: 7
184
+
185
+ publish:
186
+ needs: [build-linux, build-windows, build-sdist]
187
+ runs-on: ubuntu-latest
188
+ timeout-minutes: 10
189
+ environment:
190
+ name: pypi
191
+ url: https://pypi.org/project/piper-loader/
192
+ permissions:
193
+ contents: read
194
+ id-token: write
195
+
196
+ steps:
197
+ - name: Download all distributions
198
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
199
+ with:
200
+ pattern: "*"
201
+ merge-multiple: true
202
+ path: dist/
203
+
204
+ - name: Install uv
205
+ uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
206
+
207
+ - name: Validate distribution metadata
208
+ run: uvx --from twine==7.0.0 twine check --strict dist/*
209
+
210
+ - name: Publish to PyPI
211
+ uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
212
+
213
+ github-release:
214
+ needs: publish
215
+ runs-on: ubuntu-latest
216
+ timeout-minutes: 10
217
+ permissions:
218
+ contents: write
219
+
220
+ steps:
221
+ - name: Download all distributions
222
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
223
+ with:
224
+ pattern: "*"
225
+ merge-multiple: true
226
+ path: dist/
227
+
228
+ - name: Create GitHub release
229
+ env:
230
+ GH_TOKEN: ${{ github.token }}
231
+ RELEASE_REPOSITORY: ${{ github.repository }}
232
+ RELEASE_TAG: ${{ github.ref_name }}
233
+ run: |
234
+ release_flags=(--verify-tag --generate-notes --title "$RELEASE_TAG")
235
+ if [[ "$RELEASE_TAG" == *rc* ]]; then
236
+ release_flags+=(--prerelease --latest=false)
237
+ fi
238
+ gh release create "$RELEASE_TAG" dist/* --repo "$RELEASE_REPOSITORY" "${release_flags[@]}"
@@ -0,0 +1,15 @@
1
+ /target/
2
+ /dist/
3
+ /build/
4
+ /*.egg-info/
5
+ /.venv/
6
+ /.venv*/
7
+ /.pytest_cache/
8
+ /.ruff_cache/
9
+ /__pycache__/
10
+ *.pyc
11
+ *.pyo
12
+ *.so
13
+ *.pyd
14
+ *.dll
15
+ .DS_Store
@@ -0,0 +1,19 @@
1
+ # Piper Loader — Engineering Rules
2
+
3
+ - **Scope:** Built exclusively for Piper Engine on Linux + Windows with NVIDIA
4
+ (CUDA) and AMD (ROCm/HIP). No third-party `nn.Module` forward hooks, no GGUF,
5
+ no Apple MPS, no mid-forward VRAM budget resizing.
6
+ - **Ownership boundary:** PyTorch owns VRAM allocations (`torch.empty`); Rust
7
+ owns checkpoint byte ranges, Tier 2a/2b/NVMe host memory, cache metadata,
8
+ H2D/D2D transfers, and deli-ticket GPU event synchronization. `piper-kernels`
9
+ owns quantized math, GPU transcoding, and in-place LoRA merge kernels.
10
+ - **Safety invariants:**
11
+ - Never overwrite a GPU slot until its `last_reader_ticket` has completed on
12
+ the copy stream.
13
+ - Never release/evict a Tier 2a/2b host slab span while an async H2D DMA
14
+ referencing it is in flight.
15
+ - Clear host-synchronized ready tickets on full-VRAM load so CUDA/HIP Graph
16
+ capture streams never execute cross-stream waits.
17
+ - Restrict `resize()` and budget shrinks to step/request boundaries.
18
+ - **Validation:** Run `cargo test --workspace`, `cargo clippy --workspace --all-targets`,
19
+ `uv run pytest tests -q`, `uv run ruff check .`, and `uv run pyright`.
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to Piper Loader are documented here.
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.0rc1] - 2026-12-03
8
+
9
+ ### Added
10
+
11
+ - Initial Rust-core + thin Python (`maturin` / `PyO3`) release of `piper-loader`
12
+ for Piper Engine on Linux and Windows with NVIDIA (CUDA) and AMD (ROCm/HIP)
13
+ runtime dynamic loading (`cudart` / `amdhip64`, zero build-time GPU SDK).
14
+ - Handle-free `.safetensors` single and sharded index parser (`SafetensorsIndex`,
15
+ `FileSlice`) with depth-bounded JSON checks, optional symlink containment,
16
+ OS `FileFingerprint` mutation checks, and zero-copy dim-0 `narrow`/`split`
17
+ for SP/TP/EP sharding.
18
+ - Unified 3-tier `HostStore` shared across models and 1-4 local GPUs:
19
+ portable-pinned Tier 2a slabs ranked by H2D transfer heat, Tier 2b private
20
+ pageable slabs (for Windows WDDM and paused model caching), multi-threaded
21
+ Linux `O_DIRECT` / Windows `FILE_FLAG_NO_BUFFERING` direct I/O with buffered
22
+ fallback, sticky Bounce Ring, 2-hit scan resistance, and 1-DMA packed records.
23
+ - Monotonic deli-ticket GPU event ring (`TicketRing`) and deterministic CPU
24
+ `GpuRuntime.fake()` backend for GPU-free CI testing.
25
+ - `UnitLoader` (`use_unit(name, prefetch=...)`, `install_all()`, selective
26
+ `set_adapters()`) for DiTs and dense LLM models with `adapter_epoch` hot-swap
27
+ and zero-overhead CUDA/HIP Graph capture in all-resident mode.
28
+ - Format-agnostic `piper-kernels` `QuantizedWeight` storage and GPU transcoding
29
+ bridge (`QuantizedSpec`, `ConvRotInt8Tensor`, `ConvRotTrellisTensor`) plus
30
+ online multi-LoRA, dense delta, per-path strength, optional `meta`, broadcast
31
+ FP, and quantized in-place merge support routed through `HostStore` Tier 2a.
32
+ - 1-DMA packed MoE `ExpertPool` (`SlotSchema`, `ResidentExpertViews`,
33
+ `ExpertWave`) supporting full-VRAM CUDA/HIP Graph sessions (`resident_views`),
34
+ zero-stall 50/50 partial offload (`stage_misses` with live GPU `expert_to_slot`),
35
+ hit-first `waves()`, prefill scratch isolation (`bypass=True`), `prefetch()`,
36
+ `pin()`/`unpin()`, step-boundary `resize()`, and pluggable Rust eviction
37
+ policies (`s3_fifo`, `w_tinylfu`, `lru`).