Skip to main content

Beam Search over Efficient llama.cpp generations

Theory

Forthcoming...

Example Usage

from llama_cpp_beamsearch.completion import BeamSearchCompletion
from llama_cpp_beamsearch.config import BeamSearchConfig
from llama_cpp import Llama, LlamaGrammar, ChatCompletionRequestMessage

model = Llama.from_pretrained(
    repo_id="unsloth/Qwen3-0.6B-GGUF",
    filename="*Q4_0.gguf",
    verbose=False,
    logits_all=True,
)
allowed_tokens = ["Wrench", "Screwdriver", "Ornament"]
allowed_tokens_str = " | ".join(f'"{t}"' for t in allowed_tokens)
grammar = LlamaGrammar(
    _grammar=f"""
    root ::= allowed_tokens
    start ::= ( allowed_tokens " "  )*
    allowed_tokens ::= {allowed_tokens_str}
    """
)
config = BeamSearchConfig(
    max_depth=1,
    end_token=None,
    k_progress=[2, 3],
)
completion = BeamSearchCompletion(model, grammar, config)

message = "Hello?"

result = completion.completion_beam_search(message, max_tokens=5)
assert re.match(r"^((Wrench|Screwdriver|Ornament) ?)*$", result)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_cpp_beam_search-0.1.0.tar.gz (140.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_cpp_beam_search-0.1.0-py3-none-any.whl (159.5 kB view details)

Uploaded Python 3

File details

Details for the file llama_cpp_beam_search-0.1.0.tar.gz.

File metadata

  • Download URL: llama_cpp_beam_search-0.1.0.tar.gz
  • Upload date:
  • Size: 140.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llama_cpp_beam_search-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7273af30f48df38fa015d41a27aa267e0027f97fdde6860e0755ce0f0625fd77
MD5 650a0770e5786e5b9645e4eb194d8957
BLAKE2b-256 3d74ddf24a250a5fecf13d6806c022e783377259137773f0357bf0ca7675a85d

See more details on using hashes here.

Provenance

The following attestation bundles were made for llama_cpp_beam_search-0.1.0.tar.gz:

Publisher: python-publish.yml on Dakantz/CHASTE

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llama_cpp_beam_search-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_cpp_beam_search-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0867b529a92ec00fdfb0334a80ddc029141ad8b9c466b5f0516cd1702b71d78
MD5 46dc2e6d337f2780f51a82cbf31d3d35
BLAKE2b-256 b24ec2fcff566c3fadbfa858fa7fd81ece8decc985a3553894dc94b12b5a5473

See more details on using hashes here.

Provenance

The following attestation bundles were made for llama_cpp_beam_search-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on Dakantz/CHASTE

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

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