inferlet (Python)
The Python library for writing Pie inferlets — the small programs that run next to the model.
from inferlet import model
from inferlet.eta import *
async def main(input: dict) -> dict:
prompt = model.encode(input.get("prompt", "The capital of France is"))
n = len(prompt)
ws = WorkingSet()
ws.reserve(max(-(-(n + 9) // kv_page_size()), 1))
tokens = Channel.from_(prompt, dtype.i32)
indptr_ch = Channel.from_([0, n], dtype.u32)
kv_len = Channel.from_([n], dtype.u32)
tok_out = Channel([1], dtype.i32)
# ...pages / page_indptr / w_slot / w_off / positions as in
# examples/text-completion-py/main.py
fwd = ForwardPass() # picks the model's pass kind
fwd.embed(tokens, indptr_ch)
fwd.bind_state(ws, KvGeometry(kv_len=kv_len, ...))
@fwd.epilogue # traced once, runs on the device
def _():
tok_out.put(reshape(reduce_argmax(intrinsics.logits()), [1]))
pipe = Pipeline()
fwd.submit(pipe)
first = await tok_out.take_scalar()
pipe.close()
return {"text": model.decode([first])}
What is here
| Module | Interface | Notes |
|---|---|---|
inferlet.eta |
forward*, channel, working-set, pipeline |
The ETA authoring surface: Tensor + the op set, Channel, WorkingSet, RsWorkingSet, ForwardPass, Pipeline, run_ahead, prefill_chunks, and eta.diffusion (the diffusion pass's Mode plus entropy_bound_accept / stable_and_confident / linear_temperature). A port of the Rust eta-dsl/eta-ir crates and inferlet::eta; the container bytes it emits are byte-identical to the Rust inferlet crate's for the same program (tests/test_eta_goldens.py pins them), so a Python and a Rust inferlet share the host's program cache. |
inferlet.model / inferlet.tokenizer |
model, tokenizer |
The bound model's facts; model re-exports the tokenizer functions. |
inferlet.grammar / inferlet.mask |
grammar |
JSON-Schema / regex / EBNF constraints and the packed-bitmask helpers a masked_argmax epilogue reads. |
inferlet.chat / inferlet.reasoning / inferlet.tools |
chat, reasoning, tools |
The host's chat template, thinking-block and tool-call decoders. |
inferlet.media |
media |
Image / video / audio spans for multimodal models. |
inferlet.session |
session |
Client communication. |
Spelling differences from Rust: Channel.from_([...], dtype.u32) needs a
dtype for an integer sequence (the way a Rust literal needs a suffix);
scalars in arithmetic take the partner tensor's dtype; integer division is
x // y (ETA div truncates — / emits the same op, but // says so);
</<=/>/>= compare elementwise, while == stays Python identity —
elementwise equality is eq(a, b).
Running
A Python inferlet is its source: there is no build. pie run main.py (or
pie inferlet install main.py, or client.install_program(main_py, pie_toml))
hands the file to the server, which runs it under the Python language
component -- one wasm that bundles CPython, this package and the standard
library, built once by language/build.sh with stock
componentize-py >= 0.25 against crates/inferlet/wit, and installed at
~/.pie/languages/python.wasm. The world is component-model async, so
main may be async and host reads are awaited (await ch.take_host()).
From a client, a function can go straight up: decorate it with
pie_client.inferlet and hand it to PieClient.run (see
python/client).
Tests
PYTHONPATH=src python -m pytest tests
The stub wit_world in tests/conftest.py covers the unit tests; the
end-to-end twins live in examples/*-py in the pie repo
(tests/examples/test_twins.py --attach ws://127.0.0.1:8080).
Metadata
Release files for inferlet 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| inferlet-0.5.2.tar.gz | 145.2 kB | Without provenance | Details for inferlet-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| inferlet-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for inferlet-0.5.2-py3-none-any.whl |
Total release size: 260.8 kB
Release files / inferlet-0.5.2.tar.gz
| Download URL | inferlet-0.5.2.tar.gz |
|---|---|
| Size | 145.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f43b99c8c6b4c05b6a5c3ed8c6cb43d3f8f259f42ed5d8a58186de3981d374c6
|
|
BLAKE2b-256 checksum How to use checksums |
5334e975b9ec204621d1bf2cf38049d38080731b885d220e424be0941d5a0196
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / inferlet-0.5.2-py3-none-any.whl
| Download URL | inferlet-0.5.2-py3-none-any.whl |
|---|---|
| Size | 115.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d05ac5ba329f74de74192712e1d25f3ef5d4ff44907e54499444f66bb3d8099
|
|
BLAKE2b-256 checksum How to use checksums |
812f4a81951ead59e2dc96f8b5ffa95eeb5e54532398541bc2915b2bcc8fb98b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for inferlet 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.