Metadata-Version: 2.5
Name: wspx
Version: 0.1.0.dev0
Summary: Grep, edit, check, test and version-control model weights. A sandboxed harness for AI agents.
Project-URL: Homepage, https://github.com/RITIK-12/wspx
Project-URL: Source, https://github.com/RITIK-12/wspx
Project-URL: Issues, https://github.com/RITIK-12/wspx/issues
Author: Ritik Bompilwar
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,interpretability,llm,mcp,model-editing,pytorch,transformers,version-control
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.28
Requires-Dist: mcp>=2.3
Requires-Dist: modal>=1.6.4
Requires-Dist: pydantic>=2.14
Requires-Dist: typer>=0.29
Provides-Extra: all
Requires-Dist: accelerate>=1.16; extra == 'all'
Requires-Dist: anthropic>=2.11; extra == 'all'
Requires-Dist: fastapi>=0.165; extra == 'all'
Requires-Dist: gguf>=0.19; extra == 'all'
Requires-Dist: google-genai>=3.6; extra == 'all'
Requires-Dist: huggingface-hub>=2.4; extra == 'all'
Requires-Dist: numpy>=2.0; extra == 'all'
Requires-Dist: openai>=3.56; extra == 'all'
Requires-Dist: peft>=0.22; extra == 'all'
Requires-Dist: pyarrow>=26; extra == 'all'
Requires-Dist: safetensors>=0.8; extra == 'all'
Requires-Dist: sse-starlette>=3.7; extra == 'all'
Requires-Dist: starlette>=1.10; extra == 'all'
Requires-Dist: torch>=2.15; extra == 'all'
Requires-Dist: transformers>=5.23; extra == 'all'
Requires-Dist: uvicorn>=0.54; extra == 'all'
Provides-Extra: control
Requires-Dist: fastapi>=0.165; extra == 'control'
Requires-Dist: pyarrow>=26; extra == 'control'
Requires-Dist: sse-starlette>=3.7; extra == 'control'
Requires-Dist: uvicorn>=0.54; extra == 'control'
Provides-Extra: driver
Requires-Dist: anthropic>=2.11; extra == 'driver'
Requires-Dist: google-genai>=3.6; extra == 'driver'
Requires-Dist: openai>=3.56; extra == 'driver'
Provides-Extra: gateway
Requires-Dist: starlette>=1.10; extra == 'gateway'
Requires-Dist: uvicorn>=0.54; extra == 'gateway'
Provides-Extra: lab
Requires-Dist: accelerate>=1.16; extra == 'lab'
Requires-Dist: gguf>=0.19; extra == 'lab'
Requires-Dist: huggingface-hub>=2.4; extra == 'lab'
Requires-Dist: numpy>=2.0; extra == 'lab'
Requires-Dist: pyarrow>=26; extra == 'lab'
Requires-Dist: safetensors>=0.8; extra == 'lab'
Requires-Dist: starlette>=1.10; extra == 'lab'
Requires-Dist: torch>=2.15; extra == 'lab'
Requires-Dist: transformers>=5.23; extra == 'lab'
Requires-Dist: uvicorn>=0.54; extra == 'lab'
Provides-Extra: peft
Requires-Dist: peft>=0.22; extra == 'peft'
Description-Content-Type: text/markdown

# wspx

Grep, edit, check, test and version-control model weights.

wspx gives an AI agent (or you) the tools to change a model's weights the way it
changes code: search them, make targeted edits, check each edit, run tests
against the base, and commit or revert. It runs in your own
[Modal](https://modal.com) account with your own provider keys.

## Install

```bash
pip install wspx
```

## Set up

Once per machine and account:

```bash
wspx login                  # link your Modal account
wspx keys set anthropic     # or openai, google, hf
wspx deploy
```

Keys are stored as secrets in your Modal account and shared by every project
and session. `wspx keys list` shows which are set and checks that each works;
`wspx keys rm <provider>` removes one.

## Projects

A project is a directory with a `wspx.toml`. Sessions started inside it take
their defaults from it, and its files (test suites, prompt sets, scripts) are
uploaded to the session's lab.

```bash
mkdir loops && cd loops
wspx init --model Qwen/Qwen3-0.6B --driver anthropic:claude-opus-5-5 --gpu L4
wspx new "The model loops on 'Wait'. Find the direction responsible and remove it without hurting math."
wspx open                   # watch the session in the browser
```

`wspx sessions` lists the project's sessions (`--all` for every project). Each
project has its own current session, which the commands below act on; pass
`--session` to pick another.

## Commands

Every tool the agent has is also a command:

```bash
wspx info
wspx grep 'writes(" Wait") > 0.3' --in 'L*.mlp.down' --top 5
wspx contrast data/loops.jsonl data/clean.jsonl --name loop
wspx edit project_out direction=dir:loop 'targets=["L15.mlp.down","L19.mlp.down"]' cols=@r1
wspx check
wspx test --vs base
wspx vcs commit -m "Project out the loop direction in L15/L19 down_proj"
```

| Tool | Does |
|---|---|
| `info` | Outline of the model: blocks, layer types, residual stream |
| `ls` | Addresses matching a scope |
| `grep` | Ranks weight units by an expression, or by what fires on prompts |
| `show` | Stats, histogram, spectrum and vocabulary of a slice |
| `contrast` | A direction from two prompt sets, and its top writers |
| `generate` | Samples from the current weights |
| `trace` | Logit lens and top writers; diff (`--vs`) and attribution traces |
| `edit` | Stages `ablate`, `set`, `scale`, `project_out`, `bake_steer`, `rank_one_write`, `transplant` or `orthogonalize` |
| `check` | Static, numeric and smoke diagnostics, each with suggested fixes |
| `test` | Test suites, paired against another revision |
| `vcs` | `status`, `diff`, `commit`, `log`, `checkout`, `branch`, `revert`, `bisect`, `blame`, `merge` |
| `export` | Merged safetensors, PEFT adapter, GGUF or a portable bundle |
| `run` | A Python script in the lab, with the SDK loaded |
| `jobs` | Status and results of long-running jobs |

Weights are addressed by role, derived from the model's actual computation:
`L19.mlp.down[:, 8812]`, `L7.attn.q.h3`, `L12.moe.e5.up`, `embed[" Wait"]`.
Raw parameter names work too. Results come back as handles (`@r1`, `dir:loop`,
`p_8f2a91c0`) that later commands accept.

## Claude Code and Codex

```bash
wspx connect claude         # or: wspx connect codex
```

Adds the wspx MCP server, the wspx skill, and hooks that record the agent's
steps in the session trace.

## Python

With a GPU (or a small model on CPU) the lab can run in your own process:

```bash
pip install "wspx[lab]"
```

```python
import wspx

m = wspx.session("Qwen/Qwen3-0.6B", store="./wspx-store")
hits = m.grep('writes(" Wait") > 0.3', scope="L*.mlp.down", top=50)
d = m.contrast("data/loops.jsonl", "data/clean.jsonl", name="loop")
p = m.edit.project_out(d, ["L15.mlp.down", "L19.mlp.down"], cols=hits)
print(m.check(p).summary())
print(m.commit("Project out the loop direction"))
```

## Tests

Suites live in `wtests/`, as Python or YAML:

```python
from wspx.testing import expect, load_jsonl, suite


@suite(split="dev")
def math_finishes(model):
    for item in load_jsonl("data/math_dev.jsonl"):
        out = model.generate(item["prompt"], max_tokens=4096)
        yield expect.regex(out, item["answer_regex"])
```

`wspx test --vs <revision>` runs them item by item against another revision and
reports confidence intervals. Suites with `split="heldout"` show the agent only
aggregate scores. The built-in `canary` and `regression` suites need no data.

## Configuration

`wspx.toml`, all sections optional:

```toml
[project]
name = "loops"
exclude = ["data/raw"]      # kept out of the upload, on top of .git, venvs, caches and weights

[model]
id = "Qwen/Qwen3-0.6B"
dtype = "bfloat16"

[driver]
model = "anthropic:claude-opus-5-5"

[lab]
gpu = "L4"
grace = "15m"               # keep the lab warm this long after the session goes idle

[check]
max_rel_norm = 0.05
max_canary_kl = 0.10

[tests]
paths = ["wtests/"]

[policy]
protected_branches = ["main"]
```

## Spend and safety

wspx sets no spend limits unless you ask for them. Every model call goes
through a gateway in your deployment, which meters it and enforces the limits
you set:

```bash
wspx limits set day dollars 50
wspx limits set session calls 400
wspx usage
```

Sessions that repeat themselves are nudged, then paused. Idle labs are shut
down. To stop everything:

```bash
wspx kill --all             # stop all sessions and halt model calls
wspx kill --hard            # with only your Modal token, even if the deployment is down
wspx resume
```

Labs run in Modal sandboxes with no network access and no secrets.

## Supported models

Any PyTorch model whose forward pass runs. Tested against Llama, Mistral,
Qwen3, Qwen3-MoE, Qwen3.5, Gemma 3, Gemma 4, Phi-3/Phi-4, OLMo 2, GPT-2,
Falcon, Mixtral, gpt-oss, DeepSeek-V3, Jamba, Bamba, Mamba, ViT and ResNet, and
plain MLPs, CNNs, LSTMs and GRUs.

## Development

```bash
uv sync --extra all --group dev
uv run pytest
uv run ruff check && uv run ruff format --check
uv run mypy
cd ui && npm install && npm run build
```

`wspx deploy` run from a source checkout deploys that checkout.

## License

Apache-2.0
