Metadata-Version: 2.4
Name: amberlib
Version: 0.1.0
Summary: Model-agnostic GPU daemon (amberd) and continual compiler CLI (amber) for coding agents optimizing custom LLM inference engines
Author: Anibal Angulo
License-Expression: MIT
Project-URL: Homepage, https://github.com/ajac-zero/amber
Project-URL: Repository, https://github.com/ajac-zero/amber
Project-URL: Issues, https://github.com/ajac-zero/amber/issues
Keywords: llm,inference,gpu,triton,cuda,compiler,coding-agents
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: torch
Requires-Dist: torch; extra == "torch"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/ajac-zero/amber/main/assets/amber-logo.png" alt="Amber logo" width="160" />
</p>

<p align="center">
  <a href="https://github.com/ajac-zero/amber/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ajac-zero/amber/ci.yml?branch=main&style=flat-square&label=CI" alt="CI" /></a>
  <a href="https://pypi.org/project/amberlib/"><img src="https://img.shields.io/pypi/v/amberlib?style=flat-square&color=D97706" alt="PyPI" /></a>
  <img src="https://img.shields.io/badge/python-3.11%2B-3776AB?style=flat-square" alt="Python 3.11+" />
  <img src="https://img.shields.io/badge/license-MIT-F59E0B?style=flat-square" alt="MIT License" />
</p>

# Amber
On-demand, continuously hardening custom LLM inference engines.

## What this project is about

Amber is a framework for agents to build custom inference engines that perfectly fit *YOUR* hardware and *YOUR* workload.

When inference was tied to dozens of engineering hours, the most optimal path was for the community to all work on a shared inference engine that would serve everyone. Although this is a heroic effort, it results in an accumulation of edge cases as user environments grow. The idea behind Amber, inspired by [Resin](https://github.com/ajac-zero/resin) and [Together Compiler](https://arxiv.org/abs/2611.14681), is that agents can now build *AND* continuously adapt an inference engine based on your hardware and your workload characteristics, using any agent you wish.

## How this project works

Amber contains **zero hardcoded model architectures or kernels**. Instead, the engine will be built by your agents via two components: the CLI and the Daemon.

The daemon is the custom inference engine that runs on your GPU host, exposes your model via an OpenAI-compatible API, and accepts 'model packages' from your agents, which change the underlying kernels of your engine. It can then hot-reload these packages in less than a second and promote packages that are verified performance wins atomically. It also holds an internal message board for multiple agents to coordinate improvements.

The CLI is what each agent uses client-side to communicate with the daemon. Through the CLI, they can check baseline latency, target weights, committed stack, CUDA kernel profile of active incumbent, evaluate and submit changes, and access the message board to coordinate with other agents.

```mermaid
flowchart LR
    Agents["Coding Agent(s)<br/>Claude Code · Codex · Amp"]
    Clients["Clients<br/>OpenAI SDK · curl"]

    subgraph Control["amberd Control (:8765)"]
        direction LR
        Reload["Two-Tier Reload<br/>fast · structural"] --> Verify["CorpusNLLVerifier<br/>prefill + decode · parity<br/>immutable S0"] --> Board["Agent Board<br/>notes · base_hash"]
    end

    subgraph Serving["amberd Serving (:8000)"]
        direction LR
        API["OpenAI API<br/>/v1/completions<br/>/v1/chat/completions"] --> Tele["Telemetry<br/>traffic drift"]
    end

    Agents -->|"amber CLI"| Reload
    Board -.->|"promote"| API
    Tele -.->|"retarget"| Control
    Clients -->|"HTTP"| API
```

## Quickstart

Install Amber:

```bash
# Client CLI only (zero dependencies, no PyTorch required)
pip install amberlib

# GPU / model host running amberd
pip install "amberlib[torch]"
```

Start the daemon (listens on `:8765` control / `:8000` serving by default):

```bash
amberd
```

In a second terminal, deploy the included [`examples/tiny_lm`](examples/tiny_lm/) induction-head Transformer, watch `CorpusNLLVerifier` reject a vocab-tail bug and accept a clean vectorized speedup, then promote and emit:

```bash
amber deploy examples/tiny_lm
amber pull /tmp/work_tiny

# Fast-but-buggy candidate (corrupts one tail logit) -> REJECTED_NUMERICS
cp examples/tiny_lm/candidates/buggy_tail/kernels.py /tmp/work_tiny/kernels.py
amber eval --files /tmp/work_tiny/kernels.py --name buggy_tail --summary

# Clean vectorized candidate -> ACCEPTED (~45% faster, 0.0000 delta-NLL)
cp examples/tiny_lm/candidates/fast_fused/kernels.py /tmp/work_tiny/kernels.py
amber eval --files /tmp/work_tiny/kernels.py --name fast_fused --summary

amber board --summary
amber promote
amber emit /tmp/emitted_tiny_lm

# Run the emitted standalone engine with zero Amber dependency
python /tmp/emitted_tiny_lm/run.py --prompt-ids 5,7,9,11,5,7 --max-tokens 6
```

## Agent Skill

Amber ships an open [Agent Skill](https://skills.sh) at [`skills/amber/SKILL.md`](skills/amber/SKILL.md) that teaches Claude Code, Codex, Amp, Cursor, OpenCode, and other coding agents how to deploy, profile, optimize, and collaborate on a live `amberd` instance.

Install it into your coding agent via [`npx skills`](https://github.com/vercel-labs/skills):

```bash
npx skills add ajac-zero/amber
```

Or run it once without installing:

```bash
npx skills use ajac-zero/amber@amber --agent claude-code
```

Once installed, point your agent at `AMBER_URL=http://<gpu-host>:8765` and let it iterate through `amber profile`, `amber pull`, `amber eval`, `amber board`, and `amber promote`.

## CLI Overview

```bash
amber info                                          # GPU, runtime versions, active deployment, drift
amber status                                        # baseline/incumbent latency, target weights, committed stack
amber telemetry                                     # live serving CTXxBATCH histogram + L1/TV drift score
amber target --from-telemetry                       # lock target weights to live serving traffic
amber target --shapes 4096x16:0.8,512x16:0.2        # or lock target to an explicit batch workload
amber profile --key 1024x4 --top 15                 # CUDA kernel profile of active incumbent
amber pull ./work                                   # download winning files + .amber_base (source_hash)
amber eval --files ./work/kernels.py --name my_opt  # evaluate (JSON on stdout, compact summary on stderr)
amber eval --files ./work/kernels.py --name x --summary  # compact verdict summary only
amber board --summary                               # compact history with timings, NLL, parity, failure reasons
amber notes / amber post --kind claim "..."         # multi-agent coordination board
amber promote / amber rollback / amber restart      # live serving lifecycle
amber verify-bench --cmd "python bench.py"          # outer benchmark against AMBER_SERVE_URL
amber emit ./dist/my_engine                         # export standalone runnable package (includes run.py)
```

## Scope & Current Limitations

Amber is intentionally narrow and honest about what it does and does not do *today*:

* **Single-GPU focus:** No multi-GPU tensor/pipeline parallelism orchestration yet.
* **Serving concurrency:** `:8000` serves requests through the deployed package's `generate()` (single-request unless your package wraps a continuous-batching engine).
* **Single-step timing:** Timing measures `ms/step` per `(ctx, batch)` shape, not effective `ms/committed_token` for speculative decoding (MTP/EAGLE).
* **Python package slots:** Editable tracked files are `loader.py`, `model.py`, `kernels.py` (agents can still compile inline CUDA via `torch.utils.cpp_extension.load_inline`, but standalone `.cu` files are not tracked as separate slots yet).

## Development

Amber uses [`uv`](https://docs.astral.sh/uv/), [`ruff`](https://docs.astral.sh/ruff/), [`ty`](https://docs.astral.sh/ty/), and `pytest`.

```bash
# Editable install with PyTorch + dev tools
uv venv && uv pip install -e ".[torch]" pytest ruff ty

# Lint & format check
uvx ruff check src tests examples
uvx ruff format --check src tests examples

# Static type check
uvx ty check --python .venv/bin/python src tests examples

# Zero-dependency stdlib tests (verifies amber CLI/daemon without torch)
python3 -m unittest tests/test_amber_v2.py -v

# Full test suite (CorpusNLLVerifier + daemon + examples/tiny_lm)
pytest tests/ -v

# Build sdist and wheel
uv build
```

All four checks run automatically in [GitHub Actions CI](https://github.com/ajac-zero/amber/actions/workflows/ci.yml) and are required on pull requests.

## Credits

* **[Resin](https://github.com/ajac-zero/resin)** — open-source LLM inference runtime that inspired Amber's printed-engine architecture.
* **[Together Compiler (TKCC)](https://arxiv.org/abs/2611.14681)** — Abhyankar et al. (2026), *Together Compiler: Continual Compilation for AI Inference*, which inspired the tiered persistent engine and continual agent-compilation loop.

## License

MIT — see [`LICENSE`](LICENSE).
