Skip to main content

Myelin — bio-mimetic dynamic layer-masking local LLM engine (Python bindings)

Project description

myelin — Python bindings

First-class PyO3 bindings for the Myelin engine: a bio-mimetic, dynamic layer-masking local LLM runtime. import myelin loads a native extension module — no ctypes, no manual signatures, no server process.

  • Local: the model runs on your GPU; nothing leaves your machine.
  • Lean: weights live in VRAM int8-quantized; host RAM stays near the embedding table (~1.6 GB for Llama 3.2 1B).
  • Bio-mimetic masking: per-layer importance is calibrated from the model itself at load; under hardware pressure (or an explicit quality budget) unimportant layers are skipped for speed.

Install

pip install myel

The PyPI distribution name is myel; the importable module is myelin (import myelin) — the two differ because myelin was already taken.

Quick start

import myelin

eng = myelin.Engine()                      # returns immediately; the default
                                           # model loads in the background
eng.wait_ready()                           # optional — generate() also waits

print(eng.generate("The capital of France is", max_tokens=32))
print(eng.chat("Explain transformers in one sentence."))

for piece in eng.stream_iter("Write a haiku about GPUs."):
    print(piece, end="", flush=True)

First run with no model on disk:

eng = myelin.Engine("llama-3.2-1b-instruct", download=True)   # ~2.5 GB, once

API

Engine

Engine(model=None, *, download=False, models_dir=None, profile=None)
  • model — catalog id to activate; blocks until loaded. Without it the default model auto-loads in the background.
  • download — with model, fetch it first if missing.
  • models_dir — model library root (default MYELIN_MODELS_DIR or ./models).
  • profile"quality" (uniform int8, default) or "speed" (calibrated mixed int8/int4, ~25% faster at a small perplexity cost).

Generation

eng.generate(prompt, max_tokens=128, *, temperature, top_k, top_p,
             repeat_penalty, seed, quality=1.0) -> str

Raw completion (no chat template). Sampling defaults are the Llama-family chat settings (temperature 0.7, top-k 40, top-p 0.95, repeat penalty 1.1); pass temperature=0.0 for greedy decoding, seed= for reproducibility.

quality is the decision engine's quality floor: 1.0 runs every layer; lower values let the bio-mimetic mask skip calibrated-unimportant layers.

eng.chat(messages, max_tokens=256, *, system=None, ...) -> str

Chat completion through the Llama 3 instruct template. messages is a plain string (single user turn) or a full conversation:

history = [
    {"role": "user", "content": "My name is Ada."},
    {"role": "assistant", "content": "Nice to meet you, Ada!"},
    {"role": "user", "content": "What's my name?"},
]
eng.chat(history, system="Answer briefly.")

Streaming

eng.stream(messages, callback, max_tokens=256, ...) -> str   # callback per fragment
for piece in eng.stream_iter(messages, ...):                 # or iterate
    ...

stream(..., inspect=True, on_activity=fn) additionally calls fn(layer_norms, depth) per token with the real per-layer activation — the "neuron liveness" signal (slower; deliberate).

Introspection

text, info = eng.generate_detailed(prompt, ...)
info["active_layers"]   # per-layer bool mask this generation ran with
info["depth"]           # how many layers were active
info["policy"]          # layer-selection policy (e.g. BIOMIMETIC)

eng.hardware()          # {'vram_used_mb', 'temperature_c', 'utilization_pct', ...}

Model library

eng.list_models()       # curated catalog + download/active/loading status
eng.download_model("llama-3.2-3b-instruct", lambda p: print(p["downloaded_bytes"]))
eng.load_model("llama-3.2-3b-instruct")     # hot-swap; frees old model's VRAM
eng.active_model()      # -> str | None
eng.is_ready()          # -> bool
eng.wait_ready(timeout=None)

Errors

Engine-level failures raise myelin.MyelinError (a RuntimeError subclass); argument mistakes raise TypeError/ValueError.

Notes

  • The GIL is released during Rust-side compute, so generations never block other Python threads; callbacks re-acquire it per fragment — keep them light.
  • One Engine per process is the intended pattern (it owns the GPU state). It is thread-safe; generations serialize on the single GPU.
  • The catalog is curated (Llama 3.2 1B/3B Instruct) — the runtime implements the Llama 3.x architecture only.

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

myel-0.2.5.tar.gz (147.5 kB view details)

Uploaded Source

Built Distributions

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

myel-0.2.5-cp39-abi3-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

myel-0.2.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

File details

Details for the file myel-0.2.5.tar.gz.

File metadata

  • Download URL: myel-0.2.5.tar.gz
  • Upload date:
  • Size: 147.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for myel-0.2.5.tar.gz
Algorithm Hash digest
SHA256 207b7ec6fa55faec22ac1be92aa0fdb0ccd6093eebf1c8859de63e759b324508
MD5 c3c19f200b0556df9312b99d87422632
BLAKE2b-256 46b2922f9e0577d2878fb93b4e05d5ea9c7a2eeaa408af353350b1dbd1b1099b

See more details on using hashes here.

File details

Details for the file myel-0.2.5-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: myel-0.2.5-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for myel-0.2.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0282461fe19a4d3f6ff69671088355e7624b775cf74935556de66244434b8676
MD5 c9cb1fd26f9dd61f352f5add40636018
BLAKE2b-256 91a8884e1e82cf2b7ff8c4a87c3044508ae2b28a89a249b6f9bb87e6fa55837a

See more details on using hashes here.

File details

Details for the file myel-0.2.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for myel-0.2.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 287563fd7bc7d6bbbcb3cba9b04cb0ba81d5dc9bcdd31f0da8d3710c0f038314
MD5 7e32d20c6f36f1650979e031b4dfd734
BLAKE2b-256 bc8cd23d2b005b5c89c40df87ed3356ee6038d5ec9c37818972247f962b56d11

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