Metadata-Version: 2.4
Name: nenya-vllm
Version: 1.0.0
Summary: vLLM plugin for the Nenya models: fused Triton kernels, OpenAI-compatible serving with tool calls
Author: ArsalanZ
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/contrastivelabs/nenya-vllm
Project-URL: Issues, https://github.com/contrastivelabs/nenya-vllm/issues
Project-URL: Nenya 1, https://huggingface.co/contrastivelabs/Nenya-1
Project-URL: Base model, https://huggingface.co/contrastivelabs/Nenya-2.5B-A0.5B-Base
Project-URL: Website, https://contrastivelabs.ai
Keywords: vllm,nenya,llm,inference,function-calling,tool-use,mixture-of-experts
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: <3.15,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: vllm==0.33.0
Requires-Dist: flash-linear-attention==0.5.2
Dynamic: license-file

<p align="center"><a href="https://contrastivelabs.ai" target="_blank"><img src="https://huggingface.co/contrastivelabs/Nenya-1/resolve/main/assets/banner.png" alt="Contrastive Labs" width="100%"/></a></p>

<div align="center" style="line-height: 1;">
  <a href="https://contrastivelabs.ai" target="_blank"><img alt="Website" src="https://img.shields.io/badge/%F0%9F%8C%90%20Website-Contrastive%20Labs-6b8f3a"/></a>
  <a href="https://contrastivelabs.ai/docs" target="_blank"><img alt="API" src="https://img.shields.io/badge/%E2%9A%A1%20API-Docs-2ea44f"/></a>
  <a href="https://contrastivelabs.ai/playground" target="_blank"><img alt="Playground" src="https://img.shields.io/badge/%F0%9F%8E%AE%20Playground-Try%20Nenya%201-8250df"/></a>
  <a href="https://contrastivelabs.ai/research/nenya-technical-report" target="_blank"><img alt="Technical report" src="https://img.shields.io/badge/%F0%9F%93%84%20Technical%20Report-Nenya-1783ff"/></a>
  <a href="https://huggingface.co/contrastivelabs/Nenya-1" target="_blank"><img alt="Hugging Face: Nenya 1" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Nenya%201-ffc107"/></a>
  <a href="https://github.com/contrastivelabs/nenya-vllm/blob/main/LICENSE" target="_blank"><img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-f5de53"/></a>
</div>

Nenya 1 is a 500m active parameter model built on top of our Nenya base. It excels at tool calling, extraction and classification at a fraction of the cost and latency.

**nenya-vllm** runs the Nenya models natively on [vLLM](https://github.com/vllm-project/vllm) 0.33.0: Nenya 1 (chat,
tool calls) and the Nenya base model. It's a vLLM plugin with fused Triton kernels for the decode path, plus vLLM's
OpenAI compatible server w/ Nenya's chat format & tool parser. No vLLM fork. No `--trust-remote-code`.

## Quickstart

```bash
# brings vLLM 0.33.0 (pinned exactly: the plugin uses vLLM internals) and flash-linear-attention 0.5.2
pip install nenya-vllm          # with uv: uv pip install nenya-vllm --torch-backend=auto

# vLLM's OpenAI-compatible server on port 8000, model name "nenya"
nenya-vllm serve contrastivelabs/Nenya-1
```

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
tools = [{"type": "function", "function": {
    "name": "get_weather", "description": "Get the current weather for a city.",
    "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]
r = client.chat.completions.create(
    model="nenya", tools=tools,
    messages=[{"role": "user", "content": "What is the weather in Paris right now?"}])
print(r.choices[0].message.tool_calls[0].function)
# Function(arguments='{"city": "Paris"}', name='get_weather')
```

- `nenya-vllm serve MODEL` takes a Hub id or a local folder and starts `vllm serve` with Nenya's settings
  (`--dry-run` prints the command). `nenya-vllm serve --help` lists its options; every option also reads an
  environment variable (`PORT`, `SERVED_MODEL_NAME`, ...), and arguments it doesn't know go to `vllm serve`
  unchanged. More in [docs/serving.md](https://github.com/contrastivelabs/nenya-vllm/blob/main/docs/serving.md).
- **Tool calls are greedy by default.** The middleware carries a call guard: a request with tools that sets no
  sampling is decoded greedily, one without `max_tokens` is capped at 2,048 tokens, and a non-streamed reply whose
  call block doesn't parse is generated once more. Chat without tools keeps the model's sampling (temperature 0.9,
  top-k 20). `--no-call-guard` switches it off.
- **The first start is slow.** vLLM compiles FlashInfer's kernels for your GPU on its first forward pass (20 minutes
  or more, once per machine), and the plugin's Triton kernels compile and autotune on their first use (a few
  minutes). Later starts take seconds.
- **The base model** is a continuation model: serve `contrastivelabs/Nenya-2.5B-A0.5B-Base` the same way and use
  `/v1/completions`.

Without vLLM, on any device (transformers, the `nenya` pip package, or the Metal engine on a Mac): see the model
cards of [Nenya 1](https://huggingface.co/contrastivelabs/Nenya-1) and the
[base model](https://huggingface.co/contrastivelabs/Nenya-2.5B-A0.5B-Base).

## Benchmarks

<p align="center"><img src="https://huggingface.co/contrastivelabs/Nenya-1/resolve/main/assets/benchmarks.png" alt="Nenya 1 against eight open models on tool calling (BFCL v4 single-turn), extraction and classification" width="100%"/></p>

<p align="center"><img src="https://huggingface.co/contrastivelabs/Nenya-1/resolve/main/assets/speed.png" alt="Latency per call, cost per 1,000 calls and energy per call, Nenya 1 against eight open models" width="100%"/></p>

Latency, cost and energy are for one request at a time on one RTX 5090, with Nenya 1 served by this plugin. More
benchmarks are on the [model card](https://huggingface.co/contrastivelabs/Nenya-1).

Generation speed with version 1.0, in output tokens per second on one RTX 5090:

| Requests at once | Decoding | Served over HTTP |
|---|---|---|
| 1 | 642 | 500 |
| 16 | 4,945 | 3,844 |
| 64 | 11,442 | 7,393 |
| 256 | 21,147 | 10,001 |

Decoding is the rate of the generation steps (greedy, 512-token prompts, 256 new tokens per request). Served is end
to end through `vllm serve` (1,024-token prompts, 256 output tokens). Measured with the base model, which has Nenya
1's architecture, on a server with two EPYC 7B12 CPUs.

## Examples

Each example uses the `client` from the Quickstart. The comment under a call is what the model returned.

### Extraction: recall notices

Turn a document into a record. Name the fields in the system message and send the document on its own as the user
message.

```python
fields = ('Extract these fields from the document as JSON: "company" (string), '
          '"product" (string), "units" (number), "reason" (string). '
          'Use null for a field the document does not state.')
notice = ("Acme Foods is recalling 12,400 jars of its Crunchy Peanut Butter because "
          "they may contain small pieces of glass.")

r = client.chat.completions.create(model="nenya", temperature=0, messages=[
    {"role": "system", "content": fields}, {"role": "user", "content": notice}])
r.choices[0].message.content
# '{"company": "Acme Foods", "product": "Crunchy Peanut Butter", "units": 12400,
#   "reason": "may contain small pieces of glass"}'
```

### Classification: customer support intent

Route a message before a human sees it. Put the question, the text and your labels in one message, and ask for the
label only.

```python
question = """Which team should handle this message?

Message:
I was charged twice when my subscription renewed on April 15. Please refund one payment.

Options:
- order_status
- refund_request
- cancel_subscription
- login_problem
- shipping_delay

Answer with the label only."""

r = client.chat.completions.create(model="nenya", temperature=0, messages=[
    {"role": "user", "content": question}])
r.choices[0].message.content
# 'refund_request'
```

## Accuracy with Nenya 1

Nenya 1 served by this plugin gives what training recorded for the same weights. Measured on the released files, on
an RTX 5060 Ti (BFCL) and an RTX 5070 (the lm-eval tasks):

| Check | Recorded in training | Through this plugin |
|---|---|---|
| BFCL v4, 13 single-turn categories, 3,641 entries (mean of the categories, %) | 75.43 | 75.26 |
| 11 lm-eval tasks (mean, %) | 57.00 | 57.03 |

More checks, and how each was measured: [docs/benchmarks.md](https://github.com/contrastivelabs/nenya-vllm/blob/main/docs/benchmarks.md#accuracy-with-nenya-1).

## Limitations

- **vLLM 0.33.0 only.** The plugin uses vLLM internals, so it is pinned to one vLLM version; a new vLLM version needs
  a new release of the plugin.
- **NVIDIA GPUs.** Tested on RTX 50-series cards (5060 Ti, 5070, 5090) and the RTX PRO 6000 with CUDA 13 drivers.
- Nenya 1 is a small model tuned for tool calls, extraction and classification. It is weaker than larger models on
  general knowledge and reasoning, and it can produce false, biased or unsafe content. The base model continues
  text and does not follow instructions.
- Trained mostly on English web, educational, academic, code and maths data.
- Quality past 16,384 tokens is untested. With no positional encoding there is no hard limit.

## License

Apache 2.0: see [`LICENSE`](https://github.com/contrastivelabs/nenya-vllm/blob/main/LICENSE). [`NOTICE`](https://github.com/contrastivelabs/nenya-vllm/blob/main/NOTICE) lists the third-party material:
- `nenya_vllm/ops/dilated_conv.py` is copied from [vLLM](https://github.com/vllm-project/vllm) (Apache 2.0);
- `nenya_vllm/model_state.py` is adapted from vLLM;
- `benchmarks/data/origin_of_species.txt` is in the public domain.

The models' weights and tokenizers are licensed in their repositories ([Nenya 1](https://huggingface.co/contrastivelabs/Nenya-1), [base model](https://huggingface.co/contrastivelabs/Nenya-2.5B-A0.5B-Base)).

## Links

- [Nenya 1 on Hugging Face](https://huggingface.co/contrastivelabs/Nenya-1): the model card, with all the benchmarks.
- [API docs](https://contrastivelabs.ai/docs): call Nenya 1 through our hosted, OpenAI-compatible API.
- [Cookbooks](https://contrastivelabs.ai/cookbook): worked examples of extraction, classification and tool calling.
- [Playground](https://contrastivelabs.ai/playground): try Nenya 1 in your browser.
- [`nenya` on PyPI](https://pypi.org/project/nenya/): the pip package that runs Nenya on any device.
- [Metal 8-bit weights](https://huggingface.co/contrastivelabs/Nenya-1-Metal-8bit): the weight file of the Metal engine for Apple silicon.
- [Serving](https://github.com/contrastivelabs/nenya-vllm/blob/main/docs/serving.md): what `nenya-vllm serve` runs, your own fine-tune, how the plugin loads.
- [Benchmarks in full](https://github.com/contrastivelabs/nenya-vllm/blob/main/docs/benchmarks.md): every table, the setup, and how to run them yourself.
- [Changelog](https://github.com/contrastivelabs/nenya-vllm/blob/main/CHANGELOG.md): what changed since version 0.1.
