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 greedy generation constrained by a regular expression. At each decoding step, regex_generate masks tokens that would make the generated text violate the expression.

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)

result = regex_generate(
    model=model,
    tokenizer=tokenizer,
    prompt="The release date is ",
    regex=r"\d{4}-\d{2}-\d{2}",
    max_new_tokens=10,
)

print(result)
regex_generate(
    model,
    tokenizer,
    prompt: str,
    regex: str,
    max_new_tokens: int = 64,
) -> 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.3

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.3
File Size Uploaded Provenance Actions
lmdec-0.1.3.tar.gz 2.6 kB With provenance Details for lmdec-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 6.2 kB

Release files / lmdec-0.1.3.tar.gz

Download URL lmdec-0.1.3.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c996b58f27fc34ac48b84a93c6072017048b95af1f0a14ad79c1a8e40c2cf117
BLAKE2b-256 checksum
How to use checksums
b864783e48a74533d7a9f892d8643f6f962e4eb0218d0a03210384a257388d83
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 16, 2026.

Transparency log

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

Download URL lmdec-0.1.3-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a51e0273fb5461f49433ce342a5179148859d545281fe85cbc5b0c0cfac9c7c8
BLAKE2b-256 checksum
How to use checksums
3a3935137d5cd2b2f19a2473384413d110db90917def76001125cf317467ab66
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 16, 2026.

Transparency log

Security for lmdec 0.1.3

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.3.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 16, 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