Skip to main content

inferlet (Python)

The Python library for writing Pie inferlets — the small programs that run next to the model.

from inferlet import chat, model
from inferlet.eta import ForwardPass, Pipeline, StateGeometry, WorkingSet, intrinsics, reduce_argmax


async def main(input: dict) -> dict:
    tokens = chat.prefix() + model.encode(input.get("prompt", "The capital of France is"))
    max_tokens = int(input.get("max_tokens", 8))
    ws = WorkingSet()  # the sequence's state, whatever the model keeps
    pipe = Pipeline()

    done = 0  # tokens already in the working set
    for _ in range(max_tokens):
        fwd = ForwardPass()
        fwd.embed(tokens[done:])                        # the new tokens
        fwd.state([ws], StateGeometry.folding())        # appended, and final
        out = fwd.epilogue(lambda: reduce_argmax(intrinsics.output(0, "logits")))  # traced once, runs on the device
        pipe.submit(fwd)
        done = len(tokens)
        tokens.append(await out)
    pipe.close()

    return {"text": model.decode(tokens[-max_tokens:])}

That is examples/quickstart-py. Every line above stands for device state: embed(list) seeds the token and row channels, state([ws], ...) says where the rows land (by default after what the working set holds) and what freezes, and an epilogue that returns a tensor publishes it on a channel the host awaits. The explicit spellings — Channel.from_(..., dtype.u32), StateGeometry(slots=..., fold=...), ch.put(tensor) inside the stage — are the same objects and stay available; examples/text-completion-py uses them for a one-pass prefill and a device loop-carried decode.

A model receives two things per fire: inputs (device channels) and switches (a value from a finite set that picks the model's path). One ForwardPass holds every lane of one computation (a CFG denoise step's text and image lanes of both branches, say); switch(lane, name, value), input(lane, name, ch), media(lane, spans) and group(lane, id) address a lane by index, mask(rows) is pass-wide, and an epilogue reads a lane's outputs by the names the model gives them (output(lane, name), output_rows(lane, name, rows)). model.switches() lists a model's switches and model.lane(switches) says what a lane with those values binds: its inputs, whether it binds a working set (state), whether it embeds tokens, and the outputs it may read (logits, velocity, hidden, pixels by convention). Generative latents are the VAE's own [t, h, w, C]; patching and positions live in the model. A causal VAE decodes frame by frame into a working set, one latent frame per slot, and the runtime's fresh switch (cursor 0) picks its first-frame branch. A prologue runs before the forward, an epilogue after it.

What is here

Module Interface Notes
inferlet.eta forward, channel, working-set, pipeline The ETA authoring surface: Tensor + the op set, Channel, WorkingSet, StateGeometry, ForwardPass, Pipeline (submit, run_ahead), readout_spans, and eta.diffusion (a block-diffusion text's samplers 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 packages/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.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inferlet 0.6.0
File Size Uploaded Provenance Actions
inferlet-0.6.0.tar.gz 148.0 kB Without provenance Details for inferlet-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inferlet 0.6.0
File Interpreter ABI Platform Actions
inferlet-0.6.0-py3-none-any.whl Python 3 none any Details for inferlet-0.6.0-py3-none-any.whl

Total release size: 262.4 kB

Release files / inferlet-0.6.0.tar.gz

Download URL inferlet-0.6.0.tar.gz
Size 148.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7b982ef52215799ebf7db5bcbdbd5ae1358bdb8da36a8b0ec9d0d015b823c103
BLAKE2b-256 checksum
How to use checksums
a48c3ed249d36536606c1fde75879bafc34f4945ec56eed7c5190c6829a0a18e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / inferlet-0.6.0-py3-none-any.whl

Download URL inferlet-0.6.0-py3-none-any.whl
Size 114.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60b6cd2812256a07f6b7d8958fcd4e99dbb58a7cee30df53740309a8954aeadc
BLAKE2b-256 checksum
How to use checksums
84fc62e13c983c16534e8ad78eb60d365516e9657c833106a1073ee6e745467d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for inferlet 0.6.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page