Skip to main content

Compile natural language specifications into neural programs that run locally via llama.cpp.

Project description

ProgramAsWeights

Compile natural language specifications into neural programs (.paw files) that run locally.

Programs are stored as weight blobs (KV cache prefix + optional LoRA adapters) interpreted by a small fixed model. No API calls needed at runtime — fully deterministic, local execution.

Installation

pip install programasweights

Quick Start

Run a Program

import programasweights as paw

# Load and run a compiled program
fn = paw.function("program_id_or_path.paw")
result = fn("Contact alice@company.com or bob@example.org")
print(result)  # ["alice@company.com", "bob@example.org"]

Compile a Program

import programasweights as paw

# Compile from natural language specification
paw.compile(
    "output.paw",
    spec="Extract all email addresses from text and return as JSON list",
    checkpoint_dir="path/to/trained/compiler",
)

LoRA Support (PEFT Compatible)

Already using PEFT for LoRA training? Convert to .paw in one line:

import programasweights as paw

# Standard PEFT workflow:
# model = get_peft_model(base_model, LoraConfig(r=16, target_modules=["q_proj", "v_proj"]))
# trainer.train()
# model.save_pretrained("my_adapter/")

# Convert to .paw:
paw.from_peft(
    "my_adapter/",       # Your PEFT checkpoint
    "sentiment.paw",     # Output .paw file
    spec="Classify sentiment as positive or negative",
    tags=["sentiment", "classification"],
    examples=[
        {"input": "Great movie!", "output": "positive"},
        {"input": "Terrible film.", "output": "negative"},
    ],
)

# Use it:
fn = paw.function("sentiment.paw")
print(fn("This is amazing!"))  # → "positive"

Load LoRA from a .paw file:

lora_weights, lora_config = paw.load_paw_lora("sentiment.paw")
print(lora_config)  # {"rank": 16, "alpha": 32, ...}

Or use save_lora_to_paw() directly if you have raw tensors instead of a PEFT checkpoint.

.paw File Format v2

A .paw file is a self-contained neural program that includes:

Component Description Required
KV cache prefix Continuous program (prefix weights) Optional
Pseudo-program Discrete text instructions Optional
LoRA adapter Fine-tuned adapter weights Optional
Generation config Temperature, top_p, max_tokens Optional
Metadata Interpreter model, spec, author, tags Required

Program Hub

Browse and share programs at hub.programasweights.com

Links

License

MIT

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

programasweights-0.1.0.dev3.tar.gz (7.4 MB view details)

Uploaded Source

Built Distribution

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

programasweights-0.1.0.dev3-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file programasweights-0.1.0.dev3.tar.gz.

File metadata

  • Download URL: programasweights-0.1.0.dev3.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for programasweights-0.1.0.dev3.tar.gz
Algorithm Hash digest
SHA256 700f53555354bcfd346c3baf06f0332df02324e7b8219e0f03906bfc52a42678
MD5 682df8aa04eadd6e88dac496336a149b
BLAKE2b-256 6d62de71d69a82cb25c4292b7f7d5c2976e7cb4ed79725d798c7baf6279a5d71

See more details on using hashes here.

File details

Details for the file programasweights-0.1.0.dev3-py3-none-any.whl.

File metadata

File hashes

Hashes for programasweights-0.1.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 1f177eb8dfa7369eaba05e306489ef32c4704e92e3b283b076a6bac7f32591ad
MD5 ee22e0acdb9c08fad82a6768e2479672
BLAKE2b-256 2439810d0691b2d030281e1e28712d7eb551e275bbf36f15ad088b1d494b4c16

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