File size: 6,254 Bytes
ef6eb55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | # PAX-Coder Demo
Verified GPU kernel generation demonstration with realistic Lean 4 proofs, PTX kernels, and Futhark specs.
## Quick Start
```bash
# Mock mode (no model download required)
python3 demo.py
# Non-interactive mode (useful for CI/scripting)
python3 demo.py --no-pause
# Use actual Ollama model (if running locally)
python3 demo.py --live
# Target H100 (Hopper, sm_90) instead of RTX 3080 (Ampere, sm_86)
python3 demo.py --arch sm_90
```
## What It Shows
The demo demonstrates PAX-Coder end-to-end with 5 kernel categories:
| Category | What's Proven | Example Output |
|----------|---------------|-----------------|
| **FP16** | IEEE-754 binary16 rounding error bound | Lean 4 proof + PTX `cvt.rn.f16.f32` |
| **GEMM** | 128Γ128 matrix multiply correctness | `mma.sync` kernel + index partition proof |
| **Pipeline** | 3-stage async GEMM throughput bound | `cp.async` + happens-before proof |
| **Epilogue** | Bias+GeLU fusion numerical stability | In-register computation proof |
| **Warp** | Tree-reduction warp shuffle correctness | `shfl.sync.xor` + divergence-free guarantee |
For each category, you see:
- **Prompt**: What was asked
- **Lean 4 Proof**: Machine-checked correctness (zero sorry)
- **PTX Kernel**: Hand-rolled `mma.sync`, `ldmatrix`, `cp.async` code
- **Futhark Spec**: Functional reference implementation
- **PAX Certificate**: Which proof obligations (PO1βPO8) are satisfied
## Command-Line Options
```
--live Use actual Ollama instance (localhost:11434)
--arch {sm_86,sm_90}
Target GPU (default: sm_86 / RTX 3080)
--no-rich Disable colored terminal output (plain text)
--speed SPEED Streaming animation speed multiplier (default: 1.0)
--no-pause Skip pauses between demos (for CI/automation)
--help Show this help message
```
## Requirements
### Minimal (Mock Mode)
- Python 3.10+
- Standard library only
### Optional (Live Mode + Rich Output)
- Ollama running at `localhost:11434` with `Snapkitty/pax-coder-7b` model
- `rich` library: `pip install rich`
```bash
# Install rich for prettier output
pip install rich
# Run Ollama locally for --live mode
ollama run Snapkitty/pax-coder-7b
```
## Example Output
Running `python3 demo.py --no-pause` will generate ~680 lines showing:
1. **PAX-Coder banner** with legal information
2. **5 kernel demos** (fp16, gemm, pipeline, epilogue, warp)
3. **VRAM usage breakdown** (~8.1 GB on RTX 3080)
4. **Call-to-action** for Sovereign Node Key
5. **Links** to GitHub, HuggingFace, documentation
### Sample Output Structure
```
================================================================================
DEMO 1/5: FP16
================================================================================
π PROMPT:
Prove that IEEE-754 binary16 rounding error is bounded by 0.5 ulp...
π LEAN 4 PROOF:
theorem fp16_rounding_bound (x : Float)...
nlinarith [ulp_nonneg (roundToFP16 x), ...]
βοΈ PTX KERNEL:
// IEEE-754 binary16 RNE conversion
.target sm_86
cvt.rn.f16.f32 h_out, f_in;
π FUTHARK SPEC:
def round_fp16 (x : f32) : f16 = f16.from_f32 x
β PAX CERTIFICATE: [PO4 | PO5 | PO7]
```
## Proof Obligations (PO1βPO8)
| PO | Invariant | Example |
|----|-----------|---------|
| PO1 | Index space partition | Coverage + disjointness proven |
| PO2 | Address space separation | `shared β© global = β
` |
| PO3 | SIMT reconvergence | Before every barrier |
| PO4 | Happens-before SPO | Strict partial order proven |
| PO5 | Permission sum β€ 1 | Fractional permissions at every address |
| PO6 | Barrier permission conservation | Preserved across `__syncthreads` |
| PO7 | Data-race freedom | No concurrent writes to same address |
| PO8 | Termination + correctness | Kernel always terminates correctly |
Each PAX-Coder output lists which POs are satisfied by that kernel.
## Architecture Targets
### Ampere (sm_86) β RTX 3080 β Default
- `mma.sync.aligned.m16n8k8.f32` (FP32 accumulate)
- `mma.sync.aligned.m16n8k16.f32` (FP16 input)
- `ldmatrix.sync.aligned.m8n8.x4.b16`
- `cp.async.ca.shared.global` + `cp.async.wait_group`
- Shared memory: 48 KB (or 100 KB dynamic)
### Hopper (sm_90) β H100 β `--arch sm_90`
- TMA (Tensor Memory Accelerator) multicast
- `cp.async.bulk` (pipelined async copy)
- Cluster sync primitives
- Thread blocks per cluster
## Running on Different GPUs
```bash
# Default: RTX 3080 Ampere (sm_86)
python3 demo.py
# H100 Hopper (sm_90)
python3 demo.py --arch sm_90
# With actual model (requires Ollama)
ollama run Snapkitty/pax-coder-7b "Write verified GEMM for sm_90"
python3 demo.py --live --arch sm_90
```
## For CI/Automation
```bash
# Non-interactive, plain text, full output to file
python3 demo.py --no-pause --no-rich > pax_demo.log 2>&1
# Check all POs are satisfied
python3 demo.py --no-pause 2>&1 | grep "PAX CERTIFICATE"
```
## Troubleshooting
### `ModuleNotFoundError: No module named 'rich'`
Rich is optional. Run `pip install rich` or use `--no-rich` for plain output.
### `ModuleNotFoundError: No module named 'requests'`
Only needed for `--live` mode. Install with `pip install requests`.
### Ollama connection refused
Ensure Ollama is running: `ollama serve`
Then in another terminal: `ollama run Snapkitty/pax-coder-7b`
### Unicode/Encoding errors on Windows
The script handles UTF-8 automatically. If issues persist, try `--no-rich`.
---
## Learn More
- **GitHub**: https://github.com/SNAPKITTYWEST/pax-coder
- **HuggingFace**: https://huggingface.co/Snapkitty/pax-coder-7b
- **Architecture Doc**: https://github.com/SNAPKITTYWEST/pax-coder/tree/main/PAX
- **User Guide**: https://github.com/SNAPKITTYWEST/pax-coder/tree/main/docs
## License
PAX-Coder is tri-licensed:
- **BSL-1.1** (Business Source License 1.1) β restricts until 2028-08-08
- **AGPL-3.0** (GNU Affero General Public License 3.0) β starting 2028-08-08
- **MPL-2.0** (Mozilla Public License 2.0) β alternative terms
Copyright: Ahmad Ali Parr, Bel Esprit D'Accord Irrevocable Trust
---
*Evidence or Silence β 2026*
|