# xTuring

> A short Python API for fine-tuning, evaluating and chatting with open-source LLMs on your own data, locally or in your private cloud

- Category: Training & Fine-Tuning / Fine-Tuning Frameworks
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/stochasticai/xTuring
- Website: https://xturing.stochastic.ai
- Canonical page: https://ai-tldr.dev/tools/xturing/

## In short

xTuring is an open-source Python library from Stochastic for personalising open-source large language models on your own data. Its pitch is a small, uniform API: load an instruction dataset, create a model by key with BaseModel.create(), then call finetune(), generate(), evaluate(), save() and load(). It sits in the Fine-Tuning Frameworks category of the Training & Fine-Tuning tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

xTuring is an open-source Python library from Stochastic for personalising open-source large language models on your own data. Its pitch is a small, uniform API: load an instruction dataset, create a model by key with BaseModel.create(), then call finetune(), generate(), evaluate(), save() and load(). It targets models such as GPT-OSS (20B and 120B), LLaMA and LLaMA 2, Qwen3 0.6B, MiniMax M2, Mistral-7B, GPT-J, GPT-2, DistilGPT-2, OPT-1.3B and Mamba, and it is designed to run locally or inside your own VPC rather than through a hosted service.

Every supported model comes in variants that follow a naming template — the base key, <key>_lora, <key>_int8 and <key>_lora_int8 — so switching from full fine-tuning to LoRA or to low-precision training is a change of string rather than of code. INT4 + LoRA fine-tuning of other Hugging Face checkpoints goes through the GenericLoraKbitModel class. Under the hood, per-model YAML files hold training and generation parameters, engines handle weight loading, tokenisation and DeepSpeed integration, and training runs on a Lightning-based trainer.

Around the training loop the library adds dataset tooling (instruction and text datasets, plus self-instruct dataset generation using OpenAI, Cohere, Claude or a locally run Qwen3-Omni checkpoint), perplexity evaluation of any causal LM, batched generation, CPU inference on Intel platforms via Intel Extension for Transformers, and two ways to try a fine-tuned model by hand: an xturing chat command in the terminal and a Gradio playground in the browser. The README notes it requires transformers>=4.36.0 and should not be moved to transformers 5.x yet, because 5.x drops the load_in_8bit/load_in_4bit kwargs its INT8/INT4 engines rely on.

## What it does

- One API across model families — BaseModel.create("<key>") and then finetune(), generate(), evaluate(), save() and load()
- LoRA, INT8 and INT4 fine-tuning selected by variant key (<key>_lora, <key>_int8, <key>_lora_int8) or via GenericLoraKbitModel for any Hugging Face checkpoint
- Built-in evaluation of any causal LM on any dataset, with perplexity as the supported metric and batch_size for faster runs
- Self-instruct dataset generation using OpenAI, Cohere or Claude model APIs, or a local Qwen3-Omni checkpoint
- CPU inference on Intel hardware through Intel Extension for Transformers' weight-only quantization kernels
- An xturing CLI with a terminal chat, plus a Gradio UI playground for loading a saved model and chatting with it

## Getting started

xTuring installs from PyPI. The README's quickstart fine-tunes the lightweight Qwen3 0.6B LoRA checkpoint on a toy Alpaca-format dataset, which is small enough to try on a CPU.

1. Install the package

   xTuring requires transformers>=4.36.0; the project advises staying off transformers 5.x for now.

```bash
pip install xturing
```

2. Fine-tune a small model and generate

   The Alpaca-format example data lives in the repo under examples/models/llama/alpaca_data.

```python
from xturing.datasets import InstructionDataset
from xturing.models import BaseModel

# Load a toy instruction dataset (Alpaca format)
dataset = InstructionDataset("./examples/models/llama/alpaca_data")

# Start with the lightweight Qwen 0.6B LoRA checkpoint
model = BaseModel.create("qwen3_0_6b_lora")

# Fine-tune and then generate
model.finetune(dataset=dataset)
output = model.generate(texts=["Explain quantum computing for beginners."])
print(f"Model output: {output}")
```

3. Go low-precision with INT4 + LoRA

   GenericLoraKbitModel takes a local directory or a Hugging Face model id and fine-tunes it in INT4 with LoRA.

```python
from xturing.datasets import InstructionDataset
from xturing.models import GenericLoraKbitModel

dataset = InstructionDataset('../llama/alpaca_data')
model = GenericLoraKbitModel('mistralai/Mistral-7B-Instruct-v0.2')
model.finetune(dataset)
```

4. Save the model and try it in the playground

   Save the fine-tuned weights, then chat with them from the terminal or launch the local Gradio UI.

```python
model.save("llama_lora_finetuned")

# then, from a shell:
# xturing chat -m "<path-to-model-folder>"
# xturing ui
```

5. Measure the result

   Evaluate any causal LM on a dataset; perplexity is the supported metric.

```python
from xturing.datasets import InstructionDataset
from xturing.models import BaseModel

dataset = InstructionDataset('../llama/alpaca_data')
model = BaseModel.create('gpt_oss_20b')
result = model.evaluate(dataset)
print(f"Perplexity of the evalution: {result}")
```

## When to use it

- Reach for it when you want to LoRA-tune an open model on your own instruction data in a dozen lines of Python, without wiring up a training loop yourself
- Reach for it when the data cannot leave your laptop or VPC and you need fine-tuning and inference to stay fully private
- Reach for it when you are GPU-constrained and want to compare full, LoRA, INT8 and INT4 variants of the same model by swapping a key
- Reach for it when you need a quick instruction dataset bootstrapped with self-instruct before your first fine-tuning run
