> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Working with vLLM

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-vllm.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-vllm.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/providers/working-with-vllm.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

This tutorial demonstrates how to use Pixeltable’s built-in `vLLM`
integration to run local LLMs with high-throughput inference.

### Important notes

* vLLM provides high-throughput inference with techniques like
  PagedAttention and continuous batching
* Models are loaded from HuggingFace and cached in memory for reuse
* vLLM currently requires a Linux environment with GPU support for best
  performance
* Consider GPU memory when choosing model sizes

## Set up environment

First, let’s install Pixeltable with vLLM support:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable vllm
```

## Create a table for chat completions

Now let’s create a table that will contain our inputs and responses.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
from pixeltable.functions import vllm

pxt.drop_dir('vllm_demo', force=True)
pxt.create_dir('vllm_demo')

t = pxt.create_table('vllm_demo/chat', {'input': pxt.String})
```

<pre>
  Created directory 'vllm\_demo'.
  Created table 'chat'.
</pre>

Next, we add a computed column that calls the Pixeltable
`chat_completions` UDF, which uses vLLM’s high-throughput inference
engine under the hood. We specify a HuggingFace model identifier, and
vLLM will download and cache the model automatically.

(If this is your first time using Pixeltable, the
[Pixeltable
Fundamentals](https://docs.pixeltable.com/tutorials/tables-and-data-operations.md) tutorial contains more details about table creation,
computed columns, and UDFs.)

For this demo we’ll use `Qwen2.5-0.5B-Instruct`, a very small
(0.5-billion parameter) model that still produces decent results.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add a computed column that uses vLLM for chat completion
# against the input.

messages = [
    {'role': 'system', 'content': 'You are a helpful assistant.'},
    {'role': 'user', 'content': t.input},
]

t.add_computed_column(
    result=vllm.chat_completions(
        messages, model='Qwen/Qwen2.5-0.5B-Instruct'
    )
)

# Extract the output content from the native vLLM response.

t.add_computed_column(output=t.result.outputs[0].text)
```

<pre>
  Added 0 column values with 0 errors in 0.01 s
  Added 0 column values with 0 errors in 0.00 s
  No rows affected.
</pre>

## Test chat completion

Let’s try a few queries:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Test with a few questions
t.insert(
    [
        {'input': 'What is the capital of France?'},
        {'input': 'What are some edible species of fish?'},
        {'input': 'Who are the most prominent classical composers?'},
    ]
)
```

<pre>
  Inserted 3 rows with 0 errors in 1.74 s (1.72 rows/s)
  3 rows inserted.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
t.select(t.input, t.output).collect()
```

## Comparing models

vLLM makes it easy to compare the output of different models. Let’s try
comparing the output from `Qwen2.5-0.5B` against a somewhat larger
model, `Qwen2.5-1.5B-Instruct`. As always, when we add a new computed
column to our table, it’s automatically evaluated against the existing
table rows.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
t.add_computed_column(
    result_qwen15=vllm.chat_completions(
        messages, model='Qwen/Qwen2.5-1.5B-Instruct'
    )
)

t.add_computed_column(output_qwen15=t.result_qwen15.outputs[0].text)

t.select(t.input, t.output, t.output_qwen15).collect()
```

<pre>
  Added 3 column values with 0 errors in 3.45 s (0.87 rows/s)
  Added 3 column values with 0 errors in 0.01 s (225.06 rows/s)
</pre>

## Using sampling parameters

vLLM supports fine-grained control over generation through
`sampling_params`. Parameters like `max_tokens`, `temperature`, `top_p`,
and `top_k` control the decoding behavior. Engine-level settings (such
as `max_model_len`) can be passed separately via `engine_args`. Let’s
try running with a different system prompt and custom sampling settings.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
messages_teacher = [
    {
        'role': 'system',
        'content': 'You are a patient school teacher. Explain concepts simply and clearly.',
    },
    {'role': 'user', 'content': t.input},
]

t.add_computed_column(
    result_teacher=vllm.chat_completions(
        messages_teacher,
        model='Qwen/Qwen2.5-0.5B-Instruct',
        sampling_params={
            'max_tokens': 256,
            'temperature': 0.7,
            'top_p': 0.9,
        },
    )
)

t.add_computed_column(output_teacher=t.result_teacher.outputs[0].text)

t.select(t.input, t.output_teacher).collect()
```

<pre>
  Added 3 column values with 0 errors in 14.16 s (0.21 rows/s)
  Added 3 column values with 0 errors in 0.01 s (271.08 rows/s)
</pre>

## Text generation

In addition to chat completions, vLLM also supports direct text
generation with the `generate` UDF.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
gen_t = pxt.create_table('vllm_demo/generation', {'prompt': pxt.String})

gen_t.add_computed_column(
    result=vllm.generate(
        gen_t.prompt,
        model='Qwen/Qwen2.5-0.5B-Instruct',
        sampling_params={'max_tokens': 100},
    )
)

gen_t.add_computed_column(output=gen_t.result.outputs[0].text)

gen_t.insert(
    [
        {'prompt': 'The capital of France is'},
        {'prompt': 'Once upon a time, there was a'},
    ]
)

gen_t.select(gen_t.prompt, gen_t.output).collect()
```

<pre>
  Created table 'generation'.
  Added 0 column values with 0 errors in 0.00 s
  Added 0 column values with 0 errors in 0.00 s
  Inserted 2 rows with 0 errors in 5.88 s (0.34 rows/s)
</pre>

## Additional Resources

* [Pixeltable Documentation](https://docs.pixeltable.com/)
* [vLLM Documentation](https://docs.vllm.ai/)
* [vLLM GitHub](https://github.com/vllm-project/vllm)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.