Skip to main content

lmdec

lmdec is a Python library for implementing and exploring language-model decoding algorithms. The project currently focuses on correctness and clear implementations, with inference performance optimizations planned as it matures.

The package is available on PyPI.

Installation

lmdec requires Python 3.12 or newer.

pip install lmdec

Current API

The initial API provides batched greedy generation constrained by a regular expression. At each decoding step, regex_generate masks tokens that would make each generated text violate the expression. The same expression is applied to every prompt in the batch.

from transformers import AutoModelForCausalLM, AutoTokenizer

from lmdec import regex_generate

model_name = "HuggingFaceTB/SmolLM2-135M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

results = regex_generate(
    model=model,
    tokenizer=tokenizer,
    prompts=[
        "The first release date is ",
        "The second release date is ",
    ],
    regex=r"\d{4}-\d{2}-\d{2}",
    max_new_tokens=10,
)

print(results)
regex_generate(
    model,
    tokenizer,
    prompts: list[str],
    regex: str,
    max_new_tokens: int,
) -> list[str]

Roadmap

Planned areas of work include:

  • Structured generation beyond regular-expression constraints
  • Speculative decoding
  • Paged attention
  • Further inference and memory optimizations

The API is still early and may change as these capabilities are developed.

Development

Install the development dependencies and run the test suite with:

uv sync --dev
uv run pytest

Metadata

Release files for lmdec 0.1.4

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

Source distribution (sdist)

Source distribution for lmdec 0.1.4
File Size Uploaded Provenance Actions
lmdec-0.1.4.tar.gz 3.3 kB With provenance Details for lmdec-0.1.4.tar.gz

Built distribution (wheel)

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

Total release size: 7.5 kB

Release files / lmdec-0.1.4.tar.gz

Download URL lmdec-0.1.4.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e2dd8f3fe57d90c74d28c72bbe62fe372c7b4fa09acbddb3f4dd8e9656c409be
BLAKE2b-256 checksum
How to use checksums
a6ccc4f87361a7944d154ae8b1b4cdc851c359ea1fc6e680c9fd227c25310823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

Release files / lmdec-0.1.4-py3-none-any.whl

Download URL lmdec-0.1.4-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d93c033de7cff1a922abffbdc5d31bcf748bd8cdbed690b2d512bf688655c250
BLAKE2b-256 checksum
How to use checksums
0eb1519316210e306dde37221cb3df1e2b5f03b05c0cdd8469c0bf861aa6b4d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

Security for lmdec 0.1.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lmdec-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

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