Skip to main content

Standalone LFM ONNX inference with first-run Hugging Face download and local cache

Project description

LFM ONNX HF Library

Install

pip install lfm-onnx-hf

Python Usage

Basic Prompt (sync, stream=False)

from lfm_onnx_hf import LFMOnnxEngine, GenerationConfig

engine = LFMOnnxEngine()

text = engine.basic_prompt(
    "What is the capital of France?",
    stream=False,
    generation=GenerationConfig(
        max_new_tokens=64,
        temperature=0.0,
        top_k=50,
        repetition_penalty=1.05,
        seed=42,
    ),
)
print(text)

Basic Prompt (sync, stream=True)

from lfm_onnx_hf import LFMOnnxEngine

engine = LFMOnnxEngine()

for chunk in engine.basic_prompt("Write a one-line poem about the sea.", stream=True):
    print(chunk, end="", flush=True)
print()

Basic Prompt + Assistant Prefill

from lfm_onnx_hf import LFMOnnxEngine

engine = LFMOnnxEngine()

text = engine.basic_prompt(
    "Return strict JSON with fields city and country.",
    assistant_prefill="```json\n",
    stop_tokens=["```"],
    stream=False,
)
print(text)

Chat Input (sync, stream=False)

from lfm_onnx_hf import LFMOnnxEngine

engine = LFMOnnxEngine()

turns = [
    {"role": "user", "content": "My name is Ana."},
    {"role": "user", "content": "What is my name?"},
]

text = engine.chat_input(turns, stream=False)
print(text)

Chat Input (sync, stream=True)

from lfm_onnx_hf import LFMOnnxEngine

engine = LFMOnnxEngine()

turns = [{"role": "user", "content": "Give me 3 short productivity tips."}]

for chunk in engine.chat_input(turns, stream=True):
    print(chunk, end="", flush=True)
print()

Full Generate API (sync)

from lfm_onnx_hf import LFMOnnxEngine

engine = LFMOnnxEngine()

messages = [{"role": "user", "content": "Explain recursion in 2 sentences."}]
text, stats = engine.generate(
    messages=messages,
    max_new_tokens=80,
    temperature=0.1,
    top_k=50,
    repetition_penalty=1.05,
    seed=7,
    assistant_prefill="",
    stop_tokens=["```"],
)

print(text)
print(stats)

Async Usage (stream=False and stream=True)

import asyncio
from lfm_onnx_hf import LFMOnnxEngine


async def main():
    engine = LFMOnnxEngine()

    # async non-stream
    text = await engine.basic_prompt_async(
        "One word for water in French?",
        stream=False,
        stop_tokens=["```"],
    )
    print(text)

    # async stream
    stream_iter = await engine.chat_input_async(
        [{"role": "user", "content": "List 5 planets."}],
        stream=True,
    )
    async for chunk in stream_iter:
        print(chunk, end="", flush=True)
    print()


asyncio.run(main())

Hugging Face Source

By default, first use downloads from:

  • Repo: cnmoro/LFM-Q4-GGUFS
  • Subfolder: 2_5_350m
  • Model: model_q4.slim.spec.strip.min.onnx

CLI Usage

Basic

lfm-onnx-hf \
  --prompt "What is the capital of France?" \
  --max-new-tokens 64 \
  --temperature 0.0

Stream Output

lfm-onnx-hf \
  --prompt "Write a short haiku about rain" \
  --stream

Assistant Prefill

lfm-onnx-hf \
  --prompt "Return strict JSON with fields city and country" \
    --assistant-prefill '```json\n' \
    --stop-token '```'

Multi-turn Messages

lfm-onnx-hf \
  --messages-json '[{"role":"system","content":"Be concise."},{"role":"user","content":"Summarize photosynthesis in one paragraph."}]'

HF Options

lfm-onnx-hf \
  --repo-id cnmoro/LFM-Q4-GGUFS \
  --subfolder 2_5_350m \
  --model model_q4.slim.spec.strip.min.onnx \
  --download-max-retries 8 \
  --download-initial-backoff 1.5

Common CLI Options

  • --repo-id
  • --subfolder
  • --model
  • --revision
  • --token
  • --cache-root
  • --prompt
  • --system
  • --messages-json
  • --max-new-tokens
  • --temperature
  • --top-k
  • --repetition-penalty
  • --seed
  • --stream
  • --assistant-prefill
  • --stop-token (repeatable)
  • --benchmark-runs
  • --provider
  • --intra-op-threads
  • --inter-op-threads
  • --download-max-retries
  • --download-initial-backoff

Project details


Download files

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

Source Distribution

lfm_onnx_hf-0.1.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

lfm_onnx_hf-0.1.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file lfm_onnx_hf-0.1.2.tar.gz.

File metadata

  • Download URL: lfm_onnx_hf-0.1.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for lfm_onnx_hf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d74d97ce90343f5c6be0a025735d0fe480867a3d77c5effbac88cdd11c7f4d09
MD5 d3e349e8e8495839ffa0dff846bbf443
BLAKE2b-256 2269823f0212bdb4692eecf1f4f2448a402ac1a3e39e4e97d3d0ca906d558e71

See more details on using hashes here.

File details

Details for the file lfm_onnx_hf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lfm_onnx_hf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for lfm_onnx_hf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c951b163ab6a5bcb0e755f222fa254b06c410afc8ab7023fd55b3d46fa8fa7b
MD5 867b3d5a36e9de23632b0f023a41dedd
BLAKE2b-256 dcb5571686cbcdd0c278633287e27a76d45e41d31fdd594bc9aacbba36d7475e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page