programasweights 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- programasweights-0.1.1/.gitignore +34 -0
- programasweights-0.1.1/.readthedocs.yaml +13 -0
- programasweights-0.1.1/PKG-INFO +88 -0
- programasweights-0.1.1/PYPI_README.md +53 -0
- {programasweights-0.1.0 → programasweights-0.1.1}/README.md +68 -8
- programasweights-0.1.1/docs/Makefile +20 -0
- programasweights-0.1.1/docs/api-reference.rst +194 -0
- programasweights-0.1.1/docs/conf.py +27 -0
- programasweights-0.1.1/docs/index.rst +84 -0
- programasweights-0.1.1/docs/installation.rst +95 -0
- programasweights-0.1.1/docs/quickstart.rst +165 -0
- programasweights-0.1.1/docs/requirements.txt +3 -0
- programasweights-0.1.1/docs/using-pretrained.rst +223 -0
- programasweights-0.1.1/eval.py +142 -0
- programasweights-0.1.1/outputs_1spec/prefix_kv/LATEST +1 -0
- programasweights-0.1.1/outputs_1spec/prefix_kv/eval_program/kv_prefix.pt +0 -0
- programasweights-0.1.1/outputs_1spec/prefix_kv/eval_program/program.json +5 -0
- programasweights-0.1.1/programasweights/__init__.py +6 -0
- programasweights-0.1.1/programasweights/artifacts.py +51 -0
- programasweights-0.1.1/programasweights/compiler/__init__.py +67 -0
- programasweights-0.1.1/programasweights/compiler/dummy.py +20 -0
- programasweights-0.1.1/programasweights/runtime/__init__.py +1 -0
- programasweights-0.1.1/programasweights/runtime/interpreter.py +181 -0
- programasweights-0.1.1/pyproject.toml +61 -0
- programasweights-0.1.1/test_1spec.py +18 -0
- programasweights-0.1.1/test_api.py +53 -0
- programasweights-0.1.1/test_compile.py +10 -0
- programasweights-0.1.1/test_execute.py +6 -0
- programasweights-0.1.1/tests/test_programasweights.py +239 -0
- programasweights-0.1.1/train.py +105 -0
- programasweights-0.1.1/training/README.md +45 -0
- programasweights-0.1.1/training/__init__.py +42 -0
- programasweights-0.1.1/training/data_generation/README.md +74 -0
- programasweights-0.1.1/training/data_generation/generate_specs.py +460 -0
- programasweights-0.1.1/training/data_generation/synthesize_data.py +485 -0
- programasweights-0.1.1/training/data_generation/templates/pairs_system.txt +3 -0
- programasweights-0.1.1/training/data_generation/templates/pairs_user.txt +10 -0
- programasweights-0.1.1/training/data_generation/templates/specs_system.txt +1 -0
- programasweights-0.1.1/training/data_generation/templates/specs_user.txt +9 -0
- programasweights-0.1.1/training/datasets/__init__.py +1 -0
- programasweights-0.1.1/training/datasets/jsonl_text_pairs.py +29 -0
- programasweights-0.1.1/training/loops/__init__.py +1 -0
- programasweights-0.1.1/training/loops/prefix_tuning_sft.py +580 -0
- programasweights-0.1.1/upload_model.py +95 -0
- programasweights-0.1.1/web-app/README.md +175 -0
- programasweights-0.1.1/web-app/backend/app/__init__.py +1 -0
- programasweights-0.1.1/web-app/backend/app/config.py +59 -0
- programasweights-0.1.1/web-app/backend/app/main.py +344 -0
- programasweights-0.1.1/web-app/backend/app/models.py +104 -0
- programasweights-0.1.1/web-app/backend/app/services/__init__.py +1 -0
- programasweights-0.1.1/web-app/backend/app/services/compiler_service.py +137 -0
- programasweights-0.1.1/web-app/backend/app/services/gpt_service.py +129 -0
- programasweights-0.1.1/web-app/backend/app/services/interpreter_service.py +133 -0
- programasweights-0.1.1/web-app/backend/app/services/program_service.py +268 -0
- programasweights-0.1.1/web-app/backend/data/programs.db +0 -0
- programasweights-0.1.1/web-app/backend/env_example.txt +11 -0
- programasweights-0.1.1/web-app/backend/requirements.txt +7 -0
- programasweights-0.1.1/web-app/backend/run_server.py +27 -0
- programasweights-0.1.1/web-app/frontend/README.md +73 -0
- programasweights-0.1.1/web-app/frontend/eslint.config.js +23 -0
- programasweights-0.1.1/web-app/frontend/index.html +13 -0
- programasweights-0.1.1/web-app/frontend/package-lock.json +5145 -0
- programasweights-0.1.1/web-app/frontend/package.json +38 -0
- programasweights-0.1.1/web-app/frontend/postcss.config.js +6 -0
- programasweights-0.1.1/web-app/frontend/public/react-test.html +112 -0
- programasweights-0.1.1/web-app/frontend/public/test.html +40 -0
- programasweights-0.1.1/web-app/frontend/public/vite.svg +1 -0
- programasweights-0.1.1/web-app/frontend/src/App.css +42 -0
- programasweights-0.1.1/web-app/frontend/src/App.tsx +39 -0
- programasweights-0.1.1/web-app/frontend/src/assets/react.svg +1 -0
- programasweights-0.1.1/web-app/frontend/src/components/AboutPage.tsx +203 -0
- programasweights-0.1.1/web-app/frontend/src/components/CompileSection.tsx +74 -0
- programasweights-0.1.1/web-app/frontend/src/components/ExamplesInput.tsx +74 -0
- programasweights-0.1.1/web-app/frontend/src/components/Header.tsx +64 -0
- programasweights-0.1.1/web-app/frontend/src/components/LeaderboardPage.tsx +354 -0
- programasweights-0.1.1/web-app/frontend/src/components/MainInterface.tsx +251 -0
- programasweights-0.1.1/web-app/frontend/src/components/ModelSelector.tsx +55 -0
- programasweights-0.1.1/web-app/frontend/src/components/ProgramDetailPage.tsx +449 -0
- programasweights-0.1.1/web-app/frontend/src/components/PublishProgramPage.tsx +495 -0
- programasweights-0.1.1/web-app/frontend/src/components/SpecInput.tsx +41 -0
- programasweights-0.1.1/web-app/frontend/src/components/TestSection.tsx +122 -0
- programasweights-0.1.1/web-app/frontend/src/index.css +43 -0
- programasweights-0.1.1/web-app/frontend/src/main.tsx +10 -0
- programasweights-0.1.1/web-app/frontend/src/types/index.ts +113 -0
- programasweights-0.1.1/web-app/frontend/src/utils/api.ts +87 -0
- programasweights-0.1.1/web-app/frontend/tailwind.config.js +50 -0
- programasweights-0.1.1/web-app/frontend/tsconfig.app.json +28 -0
- programasweights-0.1.1/web-app/frontend/tsconfig.json +7 -0
- programasweights-0.1.1/web-app/frontend/tsconfig.node.json +26 -0
- programasweights-0.1.1/web-app/frontend/vite.config.ts +14 -0
- programasweights-0.1.1/web-app/start.sh +102 -0
- programasweights-0.1.1/web-app/test_setup.py +160 -0
- programasweights-0.1.0/.gitignore +0 -5
- programasweights-0.1.0/PKG-INFO +0 -19
- programasweights-0.1.0/PYPI_README.md +0 -7
- programasweights-0.1.0/programasweights/__init__.py +0 -13
- programasweights-0.1.0/pyproject.toml +0 -38
- {programasweights-0.1.0 → programasweights-0.1.1}/MANIFEST.in +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
npm-debug.log*
|
|
4
|
+
yarn-debug.log*
|
|
5
|
+
yarn-error.log*
|
|
6
|
+
|
|
7
|
+
# Build outputs
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
|
|
11
|
+
# Cache directories
|
|
12
|
+
.vite/
|
|
13
|
+
.cache/
|
|
14
|
+
|
|
15
|
+
# Python
|
|
16
|
+
__pycache__/
|
|
17
|
+
*.pyc
|
|
18
|
+
*.pyo
|
|
19
|
+
.venv
|
|
20
|
+
.env
|
|
21
|
+
|
|
22
|
+
# System files
|
|
23
|
+
.DS_Store
|
|
24
|
+
Thumbs.db
|
|
25
|
+
|
|
26
|
+
# IDE
|
|
27
|
+
.vscode/
|
|
28
|
+
.idea/
|
|
29
|
+
*.swp
|
|
30
|
+
*.swo
|
|
31
|
+
|
|
32
|
+
# Compiled models (optional - comment out if you want to track them)
|
|
33
|
+
web-app/backend/compiled_models/
|
|
34
|
+
web-app/backend/temp/
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: programasweights
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: ProgramAsWeights: a minimal runtime where programs are weight blobs run by a fixed interpreter.
|
|
5
|
+
Author-email: ProgramAsWeights <support@programasweights.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: neural-programs,nlp,prefix-tuning,runtime,transformers
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Requires-Dist: torch
|
|
22
|
+
Requires-Dist: transformers
|
|
23
|
+
Provides-Extra: data
|
|
24
|
+
Requires-Dist: openai>=1.0.0; extra == 'data'
|
|
25
|
+
Requires-Dist: tqdm>=4.66.0; extra == 'data'
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == 'test'
|
|
28
|
+
Provides-Extra: train
|
|
29
|
+
Requires-Dist: accelerate>=0.33.0; extra == 'train'
|
|
30
|
+
Requires-Dist: datasets>=2.19.0; extra == 'train'
|
|
31
|
+
Requires-Dist: evaluate>=0.4.2; extra == 'train'
|
|
32
|
+
Requires-Dist: rich>=13.7.0; extra == 'train'
|
|
33
|
+
Requires-Dist: safetensors>=0.4.0; extra == 'train'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# ProgramAsWeights
|
|
37
|
+
|
|
38
|
+
A minimal runtime where programs are weight blobs run by a fixed interpreter.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install programasweights
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import programasweights as paw
|
|
50
|
+
|
|
51
|
+
# Load a compiled program
|
|
52
|
+
f = paw.function("path/to/program", interpreter_name="yuntian-deng/paw-interpreter")
|
|
53
|
+
|
|
54
|
+
# Use the program function
|
|
55
|
+
result = f("Your input string here")
|
|
56
|
+
print(result)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Example Usage
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import programasweights as paw
|
|
63
|
+
|
|
64
|
+
# Load a program that processes key-value mappings
|
|
65
|
+
f = paw.function("outputs_1spec/prefix_kv/eval_program", interpreter_name="yuntian-deng/paw-interpreter")
|
|
66
|
+
|
|
67
|
+
# Process input
|
|
68
|
+
string = "A: b b:a, d:a"
|
|
69
|
+
result = f(string)
|
|
70
|
+
print(result) # Output: {"A":"b":"a","D":"d":"a"}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
- **Simple API**: Load and run neural programs with just a few lines of code
|
|
76
|
+
- **Flexible Interpreters**: Support for different transformer models as interpreters
|
|
77
|
+
- **Efficient Execution**: Optimized runtime for prefix-tuned neural programs
|
|
78
|
+
- **Easy Integration**: Seamlessly integrate neural programs into your Python applications
|
|
79
|
+
|
|
80
|
+
## Requirements
|
|
81
|
+
|
|
82
|
+
- Python >= 3.8
|
|
83
|
+
- PyTorch
|
|
84
|
+
- Transformers
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT License
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# ProgramAsWeights
|
|
2
|
+
|
|
3
|
+
A minimal runtime where programs are weight blobs run by a fixed interpreter.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install programasweights
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import programasweights as paw
|
|
15
|
+
|
|
16
|
+
# Load a compiled program
|
|
17
|
+
f = paw.function("path/to/program", interpreter_name="yuntian-deng/paw-interpreter")
|
|
18
|
+
|
|
19
|
+
# Use the program function
|
|
20
|
+
result = f("Your input string here")
|
|
21
|
+
print(result)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Example Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import programasweights as paw
|
|
28
|
+
|
|
29
|
+
# Load a program that processes key-value mappings
|
|
30
|
+
f = paw.function("outputs_1spec/prefix_kv/eval_program", interpreter_name="yuntian-deng/paw-interpreter")
|
|
31
|
+
|
|
32
|
+
# Process input
|
|
33
|
+
string = "A: b b:a, d:a"
|
|
34
|
+
result = f(string)
|
|
35
|
+
print(result) # Output: {"A":"b":"a","D":"d":"a"}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Simple API**: Load and run neural programs with just a few lines of code
|
|
41
|
+
- **Flexible Interpreters**: Support for different transformer models as interpreters
|
|
42
|
+
- **Efficient Execution**: Optimized runtime for prefix-tuned neural programs
|
|
43
|
+
- **Easy Integration**: Seamlessly integrate neural programs into your Python applications
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- Python >= 3.8
|
|
48
|
+
- PyTorch
|
|
49
|
+
- Transformers
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
# ProgramAsWeights
|
|
2
2
|
|
|
3
|
-
**⚠️ PLACEHOLDER PACKAGE - NOT YET FUNCTIONAL ⚠️**
|
|
4
|
-
|
|
5
|
-
This package is currently a placeholder to reserve the name "programasweights" on PyPI.
|
|
6
|
-
|
|
7
|
-
The functionality is not yet available for public use. Please check back later for updates.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
3
|
Programs as small weight blobs; a fixed interpreter runs them.
|
|
12
4
|
|
|
13
5
|
## Development
|
|
@@ -40,6 +32,74 @@ print(f("Hello"))
|
|
|
40
32
|
- weights = programs; base model = interpreter.
|
|
41
33
|
- Deterministic by default (greedy generation).
|
|
42
34
|
|
|
35
|
+
## 🌐 Web Interface
|
|
36
|
+
|
|
37
|
+
ProgramAsWeights includes a modern web interface for easy interaction with the system. The web app provides a user-friendly way to compile specifications, test neural programs, and manage models without writing code.
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
- **Interactive Model Selection**: Choose from available compiler and interpreter models
|
|
42
|
+
- **Natural Language Specifications**: Describe your program in plain English
|
|
43
|
+
- **GPT-Powered Examples**: Auto-generate test data using OpenAI's API
|
|
44
|
+
- **Real-time Compilation**: Compile specs into neural programs instantly
|
|
45
|
+
- **Interactive Testing**: Test compiled programs with custom inputs
|
|
46
|
+
- **Model Downloads**: Download compiled models as `.tgz` files
|
|
47
|
+
- **Community Sharing**: Publish and discover programs on the leaderboard
|
|
48
|
+
|
|
49
|
+
### Quick Start
|
|
50
|
+
|
|
51
|
+
1. **Prerequisites**: Ensure you have Python 3.8+, Node.js 16+, and npm installed
|
|
52
|
+
|
|
53
|
+
2. **Start the application**:
|
|
54
|
+
```bash
|
|
55
|
+
cd web-app
|
|
56
|
+
./start.sh
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
3. **Access the interface**:
|
|
60
|
+
- **Web App**: http://localhost:5173
|
|
61
|
+
- **API Docs**: http://localhost:8000/docs
|
|
62
|
+
|
|
63
|
+
The startup script automatically:
|
|
64
|
+
- Installs Python and Node.js dependencies
|
|
65
|
+
- Starts the FastAPI backend server
|
|
66
|
+
- Starts the React frontend development server
|
|
67
|
+
|
|
68
|
+
### Manual Setup (Alternative)
|
|
69
|
+
|
|
70
|
+
If you prefer manual setup:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Backend
|
|
74
|
+
cd web-app/backend
|
|
75
|
+
pip install -r requirements.txt
|
|
76
|
+
python run_server.py
|
|
77
|
+
|
|
78
|
+
# Frontend (in another terminal)
|
|
79
|
+
cd web-app/frontend
|
|
80
|
+
npm install
|
|
81
|
+
npm run dev
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Configuration
|
|
85
|
+
|
|
86
|
+
Create `web-app/backend/.env` with:
|
|
87
|
+
```bash
|
|
88
|
+
OPENAI_API_KEY=your_openai_api_key_here # Optional: for GPT test generation
|
|
89
|
+
CHECKPOINT_DIR=../../outputs_1spec/prefix_kv # Path to trained models
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Example Workflow
|
|
93
|
+
|
|
94
|
+
1. Select "Qwen 2.5 Coder 0.5B" as compiler and "PAW Interpreter" as interpreter
|
|
95
|
+
2. Enter specification: *"Parse a string like '(A) cat (B) dog' into a JSON list"*
|
|
96
|
+
3. Generate examples with GPT or add manually
|
|
97
|
+
4. Click "Compile" to create your neural program
|
|
98
|
+
5. Test with input: *"(A) red apple (B) green banana"*
|
|
99
|
+
6. Download or publish your compiled model
|
|
100
|
+
|
|
101
|
+
For detailed documentation, see [`web-app/README.md`](web-app/README.md).
|
|
102
|
+
|
|
43
103
|
## Train a compiler→KV prefix→interpreter (defaults)
|
|
44
104
|
|
|
45
105
|
```bash
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = _build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
API Reference
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
This page documents the main ProgramAsWeights API for end users.
|
|
5
|
+
|
|
6
|
+
Core Functions
|
|
7
|
+
--------------
|
|
8
|
+
|
|
9
|
+
paw.function()
|
|
10
|
+
~~~~~~~~~~~~~~
|
|
11
|
+
|
|
12
|
+
Load and execute a neural program.
|
|
13
|
+
|
|
14
|
+
.. code-block:: python
|
|
15
|
+
|
|
16
|
+
paw.function(path, *, name=None, interpreter_name="google/flan-t5-small",
|
|
17
|
+
tokenizer_name=None, max_new_tokens=128)
|
|
18
|
+
|
|
19
|
+
**Parameters:**
|
|
20
|
+
|
|
21
|
+
- **path** (*str*) - HuggingFace model ID (e.g., "yuntian-deng/paw-parser") or local directory path
|
|
22
|
+
- **name** (*str, optional*) - Custom name for the program (defaults to basename of path)
|
|
23
|
+
- **interpreter_name** (*str*) - Interpreter model to use (defaults to "google/flan-t5-small")
|
|
24
|
+
- **tokenizer_name** (*str, optional*) - Custom tokenizer path (defaults to interpreter's tokenizer)
|
|
25
|
+
- **max_new_tokens** (*int*) - Maximum tokens to generate (default: 128)
|
|
26
|
+
|
|
27
|
+
**Returns:**
|
|
28
|
+
``Callable[[Union[str, List[str]]], Union[str, List[str]]]`` - Function that accepts string or list of strings
|
|
29
|
+
|
|
30
|
+
**Examples:**
|
|
31
|
+
|
|
32
|
+
.. code-block:: python
|
|
33
|
+
|
|
34
|
+
# Basic usage
|
|
35
|
+
fn = paw.function("yuntian-deng/paw-sentiment")
|
|
36
|
+
result = fn("This is great!")
|
|
37
|
+
|
|
38
|
+
# Batch processing
|
|
39
|
+
results = fn(["Good product", "Bad service", "Okay experience"])
|
|
40
|
+
|
|
41
|
+
# Custom interpreter
|
|
42
|
+
fn = paw.function("yuntian-deng/paw-parser",
|
|
43
|
+
interpreter_name="yuntian-deng/paw-interpreter")
|
|
44
|
+
|
|
45
|
+
paw.compile()
|
|
46
|
+
~~~~~~~~~~~~~
|
|
47
|
+
|
|
48
|
+
Compile a natural language spec into a neural program (requires trained models).
|
|
49
|
+
|
|
50
|
+
.. code-block:: python
|
|
51
|
+
|
|
52
|
+
paw.compile(out_dir, *, spec, checkpoint_dir="outputs/prefix_kv/checkpoint",
|
|
53
|
+
prefix_steps=None)
|
|
54
|
+
|
|
55
|
+
**Parameters:**
|
|
56
|
+
|
|
57
|
+
- **out_dir** (*str*) - Directory to save the compiled program
|
|
58
|
+
- **spec** (*str*) - Natural language description of the desired function
|
|
59
|
+
- **checkpoint_dir** (*str*) - Path to trained compiler/interpreter checkpoints
|
|
60
|
+
- **prefix_steps** (*int, optional*) - Override prefix length (defaults to trained value)
|
|
61
|
+
|
|
62
|
+
**Returns:**
|
|
63
|
+
*str* - Path to the compiled program directory
|
|
64
|
+
|
|
65
|
+
**Example:**
|
|
66
|
+
|
|
67
|
+
.. code-block:: python
|
|
68
|
+
|
|
69
|
+
# Compile a custom program
|
|
70
|
+
program_dir = paw.compile(
|
|
71
|
+
out_dir="my_custom_parser",
|
|
72
|
+
spec="Extract email addresses from text and return as JSON array"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Use the compiled program
|
|
76
|
+
fn = paw.function(program_dir)
|
|
77
|
+
emails = fn("Contact: alice@example.com or bob@test.org")
|
|
78
|
+
|
|
79
|
+
Utility Functions
|
|
80
|
+
-----------------
|
|
81
|
+
|
|
82
|
+
paw.compile_dummy()
|
|
83
|
+
~~~~~~~~~~~~~~~~~~~
|
|
84
|
+
|
|
85
|
+
Create a dummy program for testing (legacy).
|
|
86
|
+
|
|
87
|
+
.. code-block:: python
|
|
88
|
+
|
|
89
|
+
paw.compile_dummy(out_path, spec=None, *, seed=None, num_tokens=32)
|
|
90
|
+
|
|
91
|
+
**Parameters:**
|
|
92
|
+
|
|
93
|
+
- **out_path** (*str*) - Output file path
|
|
94
|
+
- **spec** (*str, optional*) - Ignored (for API compatibility)
|
|
95
|
+
- **seed** (*int, optional*) - Random seed for deterministic output
|
|
96
|
+
- **num_tokens** (*int*) - Number of dummy tokens to generate
|
|
97
|
+
|
|
98
|
+
**Returns:**
|
|
99
|
+
*str* - Path to the created dummy program
|
|
100
|
+
|
|
101
|
+
**Example:**
|
|
102
|
+
|
|
103
|
+
.. code-block:: python
|
|
104
|
+
|
|
105
|
+
# Create deterministic dummy for testing
|
|
106
|
+
paw.compile_dummy("test.weights", seed=42)
|
|
107
|
+
fn = paw.function("test.weights")
|
|
108
|
+
print(fn("test input"))
|
|
109
|
+
|
|
110
|
+
Configuration
|
|
111
|
+
-------------
|
|
112
|
+
|
|
113
|
+
Environment Variables
|
|
114
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
115
|
+
|
|
116
|
+
**PROGRAMASWEIGHTS_DEVICE**
|
|
117
|
+
Force device selection:
|
|
118
|
+
|
|
119
|
+
- ``"cpu"`` - Use CPU only
|
|
120
|
+
- ``"cuda"`` - Use GPU if available, fallback to CPU
|
|
121
|
+
- Not set - Auto-detect (GPU if available)
|
|
122
|
+
|
|
123
|
+
.. code-block:: bash
|
|
124
|
+
|
|
125
|
+
export PROGRAMASWEIGHTS_DEVICE=cpu
|
|
126
|
+
python my_script.py
|
|
127
|
+
|
|
128
|
+
**HF_TOKEN**
|
|
129
|
+
HuggingFace authentication token for accessing private models:
|
|
130
|
+
|
|
131
|
+
.. code-block:: bash
|
|
132
|
+
|
|
133
|
+
export HF_TOKEN=your_token_here
|
|
134
|
+
|
|
135
|
+
Error Handling
|
|
136
|
+
--------------
|
|
137
|
+
|
|
138
|
+
Common Exceptions
|
|
139
|
+
~~~~~~~~~~~~~~~~~
|
|
140
|
+
|
|
141
|
+
**ValueError**
|
|
142
|
+
- Invalid program artifact type
|
|
143
|
+
- Missing KV prefix in program
|
|
144
|
+
- Malformed program directory
|
|
145
|
+
|
|
146
|
+
**FileNotFoundError**
|
|
147
|
+
- Program path doesn't exist
|
|
148
|
+
- Missing program.json manifest
|
|
149
|
+
- Missing kv_prefix.pt file
|
|
150
|
+
|
|
151
|
+
**RuntimeError**
|
|
152
|
+
- Model loading failures
|
|
153
|
+
- GPU out of memory
|
|
154
|
+
- Generation errors
|
|
155
|
+
|
|
156
|
+
**Example error handling:**
|
|
157
|
+
|
|
158
|
+
.. code-block:: python
|
|
159
|
+
|
|
160
|
+
import programasweights as paw
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
fn = paw.function("yuntian-deng/paw-nonexistent")
|
|
164
|
+
except FileNotFoundError:
|
|
165
|
+
print("Program not found - check the model ID")
|
|
166
|
+
except ValueError as e:
|
|
167
|
+
print(f"Invalid program: {e}")
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
result = fn("input text")
|
|
171
|
+
except RuntimeError as e:
|
|
172
|
+
print(f"Execution failed: {e}")
|
|
173
|
+
|
|
174
|
+
Type Hints
|
|
175
|
+
----------
|
|
176
|
+
|
|
177
|
+
For better IDE support:
|
|
178
|
+
|
|
179
|
+
.. code-block:: python
|
|
180
|
+
|
|
181
|
+
from typing import Union, List, Callable
|
|
182
|
+
import programasweights as paw
|
|
183
|
+
|
|
184
|
+
# Type hints for program functions
|
|
185
|
+
ProgramFunction = Callable[[Union[str, List[str]]], Union[str, List[str]]]
|
|
186
|
+
|
|
187
|
+
def load_parser() -> ProgramFunction:
|
|
188
|
+
return paw.function("yuntian-deng/paw-parser")
|
|
189
|
+
|
|
190
|
+
def process_texts(texts: List[str]) -> List[str]:
|
|
191
|
+
parser = load_parser()
|
|
192
|
+
return parser(texts)
|
|
193
|
+
|
|
194
|
+
Next: :doc:`examples/text-parsing`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
# -- Project information -----------------------------------------------------
|
|
7
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
8
|
+
|
|
9
|
+
project = 'programasweights'
|
|
10
|
+
copyright = '2025, PAW'
|
|
11
|
+
author = 'PAW'
|
|
12
|
+
|
|
13
|
+
# -- General configuration ---------------------------------------------------
|
|
14
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
15
|
+
|
|
16
|
+
extensions = ['myst_parser']
|
|
17
|
+
|
|
18
|
+
templates_path = ['_templates']
|
|
19
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# -- Options for HTML output -------------------------------------------------
|
|
24
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
25
|
+
|
|
26
|
+
html_theme = 'sphinx_rtd_theme'
|
|
27
|
+
html_static_path = ['_static']
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
ProgramAsWeights Documentation
|
|
2
|
+
==============================
|
|
3
|
+
|
|
4
|
+
**Programs as small weight blobs; a fixed interpreter runs them.**
|
|
5
|
+
|
|
6
|
+
ProgramAsWeights (PAW) is a new programming paradigm where fuzzy functions—like "determine if a review is positive" or "extract the final answer from reasoning text"—are represented as compact neural weight blobs that execute locally without external API calls.
|
|
7
|
+
|
|
8
|
+
Quick Start
|
|
9
|
+
-----------
|
|
10
|
+
|
|
11
|
+
Install and use a pre-trained program in 3 lines:
|
|
12
|
+
|
|
13
|
+
.. code-block:: python
|
|
14
|
+
|
|
15
|
+
import programasweights as paw
|
|
16
|
+
|
|
17
|
+
# Load a pre-trained program for parsing options
|
|
18
|
+
fn = paw.function("yuntian-deng/paw-option-parser")
|
|
19
|
+
|
|
20
|
+
# Use it like any Python function
|
|
21
|
+
result = fn("(A) cat (B) dog (C) both (A) and (B)")
|
|
22
|
+
print(result) # → ["(A) cat", "(B) dog", "(C) both (A) and (B)"]
|
|
23
|
+
|
|
24
|
+
No internet connection required after download. No API keys. No external dependencies.
|
|
25
|
+
|
|
26
|
+
Why ProgramAsWeights?
|
|
27
|
+
--------------------
|
|
28
|
+
|
|
29
|
+
**Replace expensive LLM API calls** with lightweight local execution:
|
|
30
|
+
|
|
31
|
+
- ❌ **Before:** ``openai.chat.completions.create(...)`` - $$$, internet-dependent, fragile
|
|
32
|
+
- ✅ **After:** ``paw.function("task")("input")`` - local, fast, reproducible
|
|
33
|
+
|
|
34
|
+
**Perfect for fuzzy functions** that are conceptually simple but hard to code precisely:
|
|
35
|
+
|
|
36
|
+
- Sentiment analysis, bias detection, answer extraction
|
|
37
|
+
- HTML cleaning, format conversion, typo-tolerant parsing
|
|
38
|
+
- Evaluation tasks like checking answer equivalence
|
|
39
|
+
- Linguistic analysis (counting nouns/verbs, readability scoring)
|
|
40
|
+
|
|
41
|
+
Documentation Sections
|
|
42
|
+
======================
|
|
43
|
+
|
|
44
|
+
.. toctree::
|
|
45
|
+
:maxdepth: 2
|
|
46
|
+
:caption: User Guide:
|
|
47
|
+
|
|
48
|
+
installation
|
|
49
|
+
quickstart
|
|
50
|
+
using-pretrained
|
|
51
|
+
api-reference
|
|
52
|
+
|
|
53
|
+
.. toctree::
|
|
54
|
+
:maxdepth: 2
|
|
55
|
+
:caption: Examples:
|
|
56
|
+
|
|
57
|
+
examples/text-parsing
|
|
58
|
+
examples/evaluation-tasks
|
|
59
|
+
examples/bias-analysis
|
|
60
|
+
examples/html-processing
|
|
61
|
+
|
|
62
|
+
.. toctree::
|
|
63
|
+
:maxdepth: 1
|
|
64
|
+
:caption: Advanced (Researchers):
|
|
65
|
+
|
|
66
|
+
training/overview
|
|
67
|
+
training/custom-datasets
|
|
68
|
+
training/model-architecture
|
|
69
|
+
|
|
70
|
+
.. toctree::
|
|
71
|
+
:maxdepth: 1
|
|
72
|
+
:caption: Reference:
|
|
73
|
+
|
|
74
|
+
api
|
|
75
|
+
troubleshooting
|
|
76
|
+
contributing
|
|
77
|
+
|
|
78
|
+
Indices and tables
|
|
79
|
+
==================
|
|
80
|
+
|
|
81
|
+
* :ref:`genindex`
|
|
82
|
+
* :ref:`modindex`
|
|
83
|
+
* :ref:`search`
|
|
84
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Installation
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
ProgramAsWeights requires Python 3.8+ and PyTorch.
|
|
5
|
+
|
|
6
|
+
Quick Install
|
|
7
|
+
-------------
|
|
8
|
+
|
|
9
|
+
.. code-block:: bash
|
|
10
|
+
|
|
11
|
+
pip install programasweights
|
|
12
|
+
|
|
13
|
+
That's it! The package automatically handles model downloads when you first use a program.
|
|
14
|
+
|
|
15
|
+
Requirements
|
|
16
|
+
------------
|
|
17
|
+
|
|
18
|
+
**Minimal requirements** (automatically installed):
|
|
19
|
+
|
|
20
|
+
- ``torch`` - Neural network runtime
|
|
21
|
+
- ``transformers`` - Model loading and inference
|
|
22
|
+
- ``safetensors`` - Efficient tensor storage
|
|
23
|
+
|
|
24
|
+
**Optional dependencies** for advanced users:
|
|
25
|
+
|
|
26
|
+
.. code-block:: bash
|
|
27
|
+
|
|
28
|
+
# For training your own models (researchers only)
|
|
29
|
+
pip install programasweights[train]
|
|
30
|
+
|
|
31
|
+
# For generating new datasets
|
|
32
|
+
pip install programasweights[data]
|
|
33
|
+
|
|
34
|
+
System Requirements
|
|
35
|
+
-------------------
|
|
36
|
+
|
|
37
|
+
**Memory:**
|
|
38
|
+
- **CPU:** 4GB+ RAM recommended
|
|
39
|
+
- **GPU:** 8GB+ VRAM for larger models (optional, falls back to CPU)
|
|
40
|
+
|
|
41
|
+
**Storage:**
|
|
42
|
+
- ~2-4GB per interpreter model (downloaded once, cached locally)
|
|
43
|
+
- ~100MB per compiled program
|
|
44
|
+
|
|
45
|
+
**Network:**
|
|
46
|
+
- Internet connection for initial model download
|
|
47
|
+
- Offline execution after download
|
|
48
|
+
|
|
49
|
+
Verify Installation
|
|
50
|
+
-------------------
|
|
51
|
+
|
|
52
|
+
.. code-block:: python
|
|
53
|
+
|
|
54
|
+
import programasweights as paw
|
|
55
|
+
print(paw.__version__) # Should print version number
|
|
56
|
+
|
|
57
|
+
**Test with a dummy program:**
|
|
58
|
+
|
|
59
|
+
.. code-block:: python
|
|
60
|
+
|
|
61
|
+
# Create a test program (uses dummy compiler for demo)
|
|
62
|
+
paw.compile_dummy("test.weights", seed=42)
|
|
63
|
+
|
|
64
|
+
# Load and run it
|
|
65
|
+
fn = paw.function("test.weights")
|
|
66
|
+
print(fn("hello world"))
|
|
67
|
+
|
|
68
|
+
GPU Setup (Optional)
|
|
69
|
+
--------------------
|
|
70
|
+
|
|
71
|
+
ProgramAsWeights automatically uses GPU if available. To force CPU-only:
|
|
72
|
+
|
|
73
|
+
.. code-block:: bash
|
|
74
|
+
|
|
75
|
+
export PROGRAMASWEIGHTS_DEVICE=cpu
|
|
76
|
+
|
|
77
|
+
To verify GPU usage:
|
|
78
|
+
|
|
79
|
+
.. code-block:: python
|
|
80
|
+
|
|
81
|
+
import torch
|
|
82
|
+
print(f"CUDA available: {torch.cuda.is_available()}")
|
|
83
|
+
print(f"Device: {torch.cuda.get_device_name() if torch.cuda.is_available() else 'CPU'}")
|
|
84
|
+
|
|
85
|
+
Troubleshooting
|
|
86
|
+
---------------
|
|
87
|
+
|
|
88
|
+
**Common issues:**
|
|
89
|
+
|
|
90
|
+
- **"No module named 'programasweights'"** → Run ``pip install programasweights``
|
|
91
|
+
- **Model download fails** → Check internet connection and disk space
|
|
92
|
+
- **Out of memory** → Set ``PROGRAMASWEIGHTS_DEVICE=cpu`` or use smaller models
|
|
93
|
+
- **Slow execution** → Enable GPU or use smaller input batches
|
|
94
|
+
|
|
95
|
+
See :doc:`troubleshooting` for detailed solutions.
|