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.dev1.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.dev1-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: programasweights-0.1.0.dev1.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.dev1.tar.gz
Algorithm Hash digest
SHA256 7f9758132d22c101d6cafebedf2f249d567d85336c5ab4e0f676d85460f01fb3
MD5 cccef49baa65761566f426c47031237e
BLAKE2b-256 0f017b88204c229fdee71334ab1e45e0184a9f85b71b0f8b57b13a878303183e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for programasweights-0.1.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 64bf82e498f660b47c5e17a4f23aa750d39f1e64b54682150be3666cab5fcc85
MD5 269bc437f4dc09d43f0837cb60b4a7bd
BLAKE2b-256 1c5dc31e0f55bf7d7c6f9386daa3014eb0b8b048c560d174bd4549bc8ea82c20

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