> For the complete documentation index, see [llms.txt](https://klaralabs.gitbook.io/klara-labs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://klaralabs.gitbook.io/klara-labs-docs/klarity/integrations/vllm.md).

# vLLM

### About vLLM

vLLM is an open-source high-performance LLM serving platform that optimizes large language model inference through efficient execution and scalability. It empowers teams to deploy and manage state-of-the-art models in production, ensuring fast and reliable responses.

### Using Klarity with vLLM

Integrate Klarity with vLLM to enhance your LLM applications with automated uncertainty and reasoning analysis. Evaluate your model’s predictions, debug reasoning flows, and gain actionable insights to continuously improve performance in real-world scenarios.

<pre class="language-python"><code class="lang-python"><strong>from vllm import LLM, SamplingParams
</strong>from transformers import AutoTokenizer
from klarity import UncertaintyEstimator
from klarity.core.analyzer import EntropyAnalyzer

model_name = "Qwen/Qwen2.5-0.5B-Instruct"
llm = LLM(model=model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

estimator = UncertaintyEstimator(
    top_k=5,
    analyzer=EntropyAnalyzer(
        min_token_prob=0.01,
        insight_model="together:meta-llama/Llama-3.3-70B-Instruct-Turbo",
        insight_api_key="your_api_key",
    ),
)

prompt = "What is the capital of France?"
sampling_params = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=20, logprobs=5, prompt_logprobs=5)

outputs = llm.generate([prompt], sampling_params)
output = outputs[0]  # Get first output since we only sent one prompt

# Access the completion output which contains the generated text and logprobs
completion = output.outputs[0]
generated_text = completion.text

result = estimator.analyze_generation(output, tokenizer=tokenizer, prompt=prompt)

print(f"Prompt: {prompt}")
print(f"Generated text: {generated_text}")

for idx, metrics in enumerate(result.token_metrics):
    print(f"\nStep {idx}:")
    print(f"Raw entropy: {metrics.raw_entropy:.4f}")
    print(f"Semantic entropy: {metrics.semantic_entropy:.4f}")
    for pred in metrics.token_predictions[:3]:
        print(f"  {pred.token} (prob: {pred.probability:.4f})")

if result.overall_insight:
    print("\nAnalysis:")
    print(result.overall_insight)
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://klaralabs.gitbook.io/klara-labs-docs/klarity/integrations/vllm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
