Build, personalize and control your own LLMs. From data pre-processing to fine-tuning, xTuring provides an easy way to personalize open-source LLMs. Join our di
Build, personalize and control your own LLMs. From data pre-processing to fine-tuning, xTuring provides an easy way to personalize open-source LLMs. Join our di
xTuring makes it simple, fast, and cost‑efficient to fine‑tune open‑source LLMs (e.g., GPT‑OSS, LLaMA/LLaMA 2, Qwen3, MiniMax M2, GPT‑J, GPT‑2, DistilGPT‑2, Mamba) on your own data — locally or in your private cloud.
Why xTuring:
pip install xturingNote: xTuring requires transformers>=4.36.0. Do not upgrade to transformers 5.x yet — 5.x drops the load_in_8bit/load_in_4bit loading kwargs that the INT8/INT4 engines rely on, and nothing currently shipped needs 5.x.
Qwen3-Omni support (which requires transformers>=5.0.0) is not released yet — see #318.
If you want to contribute to xTuring or run from source:
# Clone the repository
git clone https://github.com/stochasticai/xturing.git
cd xturing
# Install in editable mode with development dependencies
pip install -e .
pip install -r requirements-dev.txt
# Set up pre-commit hooks (required before contributing)
pre-commit install
pre-commit install --hook-type commit-msgRun a small, CPU‑friendly example first:
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}")Want bigger models and reasoning controls? Try GPT‑OSS variants (requires significant resources):
from xturing.models import BaseModel
# 120B or 20B variants; also support LoRA/INT8/INT4 configs
model = BaseModel.create("gpt_oss_20b_lora")You can find the data folder here.
Highlights from recent updates:
gpt_oss_120b and gpt_oss_20b with off‑the‑shelf, INT8, LoRA, LoRA+INT8, and LoRA+INT4 options. Includes configurable reasoning levels and harmony response format support.from xturing.models import BaseModel
# Use the production-ready 120B model
model = BaseModel.create('gpt_oss_120b_lora')
# Or use the efficient 20B model for faster inference
model = BaseModel.create('gpt_oss_20b_lora')
# Both models support reasoning levels via system promptsGenericModel or Llama2.from xturing.models import Llama2
model = Llama2()
## or
from xturing.models import BaseModel
model = BaseModel.create('llama2')
perplexity.# Make the necessary imports
from xturing.datasets import InstructionDataset
from xturing.models import BaseModel
# Load the desired dataset
dataset = InstructionDataset('../llama/alpaca_data')
# Load the desired model (try GPT-OSS for advanced reasoning)
model = BaseModel.create('gpt_oss_20b')
# Run the Evaluation of the model on the dataset
result = model.evaluate(dataset)
# Print the result
print(f"Perplexity of the evalution: {result}")
GenericLoraKbitModel.# Make the necessary imports
from xturing.datasets import InstructionDataset
from xturing.models import GenericLoraKbitModel
# Load the desired dataset
dataset = InstructionDataset('../llama/alpaca_data')
# Load the desired model for INT4 bit fine-tuning
model = GenericLoraKbitModel('mistralai/Mistral-7B-Instruct-v0.2')
# Run the fine-tuning
model.finetune(dataset)# Make the necessary imports
from xturing.models import BaseModel
# Initializes the model: quantize the model with weight-only algorithms
# and replace the linear with Itrex's qbits_linear kernel
model = BaseModel.create("llama2_int8")
# Once the model has been quantized, do inferences directly
output = model.generate(texts=["Why LLM models are becoming so important?"])
print(output)batch_size in .generate() and .evaluate() to speed up processing.# Make the necessary imports
from xturing.datasets import InstructionDataset
from xturing.models import GenericLoraKbitModel
# Load the desired dataset
dataset = InstructionDataset('../llama/alpaca_data')
# Load the desired model for INT4 bit fine-tuning
model = GenericLoraKbitModel('mistralai/Mistral-7B-Instruct-v0.2')
# Generate outputs on desired prompts
outputs = model.generate(dataset = dataset, batch_size=10)
from xturing.datasets import InstructionDataset
from xturing.models import BaseModel
dataset = InstructionDataset("./examples/models/llama/alpaca_data")
model = BaseModel.create("qwen3_0_6b_lora")
model.finetune(dataset=dataset)See
examples/models/qwen3/qwen3_lora_finetune.pyfor a runnable script.
from xturing.datasets import InstructionDataset
from xturing.model_apis.qwen import Qwen3OmniTextGenerationAPI
# Download `Qwen/Qwen3-Omni-30B-A3B-Instruct` (or another HF variant) ahead of time
engine = Qwen3OmniTextGenerationAPI(model_name_or_path="Qwen/Qwen3-Omni-30B-A3B-Instruct")
dataset = InstructionDataset.generate_dataset("./tasks.jsonl", engine=engine)An exploration of the Llama LoRA INT4 working example is recommended for an understanding of its application.
For an extended insight, consider examining the GenericModel working example available in the repository.
The xturing CLI provides interactive tools for working with fine-tuned models:
# Chat with a fine-tuned model
xturing chat -m "<path-to-model-folder>"
# Launch the UI playground (alternative to programmatic Playground)
xturing ui
# Get help and see all available commands
xturing --helpfrom xturing.datasets import InstructionDataset
from xturing.models import BaseModel
from xturing.ui import Playground
dataset = InstructionDataset("./alpaca_data")
model = BaseModel.create("<model_name>")
model.finetune(dataset=dataset)
model.save("llama_lora_finetuned")
Playground().launch() ## launches localhost UI
Here is a comparison for the performance of different fine-tuning techniques on the LLaMA 7B model. We use the Alpaca dataset for fine-tuning. The dataset contains 52K instructions.
Hardware:
4xA100 40GB GPU, 335GB CPU RAM
Fine-tuning parameters:
{
'maximum sequence length': 512,
'batch size': 1,
}| LLaMA-7B | DeepSpeed + CPU Offloading | LoRA + DeepSpeed | LoRA + DeepSpeed + CPU Offloading |
|---|---|---|---|
| GPU | 33.5 GB | 23.7 GB | 21.9 GB |
| CPU | 190 GB | 10.2 GB | 14.9 GB |
| Time/epoch | 21 hours | 20 mins | 20 mins |
Contribute to this by submitting your performance results on other GPUs by creating an issue with your hardware specifications, memory consumption and time per epoch.
We have already fine-tuned some models that you can use as your base or start playing with.
Load from xTuring hub:
from xturing.models import BaseModel
model = BaseModel.load("x/distilgpt2_lora_finetuned_alpaca")Load from local directory:
model = BaseModel.load("/path/to/saved/model")Create a new model for fine-tuning:
model = BaseModel.create("llama_lora")| model | dataset | Path |
|---|---|---|
| DistilGPT-2 LoRA | alpaca | x/distilgpt2_lora_finetuned_alpaca |
| LLaMA LoRA | alpaca | x/llama_lora_finetuned_alpaca |
Below is a list of all the supported models via BaseModel class of xTuring and their corresponding keys to load them.
| Model | Key |
|---|---|
| DistilGPT-2 | distilgpt2 |
| GPT-OSS (20B/120B) | gpt_oss_20b, gpt_oss_120b |
| GPT-J | gptj |
| GPT-2 | gpt2 |
| LLaMA | llama |
| LLaMA2 | llama2 |
| Mistral-7B | mistral_7b |
| Ministral 3.14B | ministral_3_14b |
| MiniMaxM2 | minimax_m2 |
| OPT-1.3B | opt |
| Qwen3 0.6B | qwen3_0_6b |
| Mamba | mamba |
The above are the base variants. Use these templates for LoRA, INT8, and INT8 + LoRA versions:
| Version | Template |
|---|---|
| LoRA | <model_key>_lora |
| INT8 | <model_key>_int8 |
| INT8 + LoRA | <model_key>_lora_int8 |
To load a model’s INT4 + LoRA version, use the GenericLoraKbitModel class:
model = GenericLoraKbitModel('<model_path>')Replace <model_path> with a local directory or a Hugging Face model like mistralai/Mistral-7B-Instruct-v0.2.
LLaMA, LLaMA 2, GPT-J, GPT-2, and GPT-OSS modelsGeneric model wrapperMiniMax M2, Qwen3 0.6B, and Mamba modelsThe project uses pytest for testing. Test files are located in the tests/ directory.
Run all tests:
pytestRun a specific test file:
pytest tests/xturing/models/test_qwen_model.pySkip slow tests:
pytest -m "not slow"Skip GPU tests (for CPU-only environments):
pytest -No open issues yet, or sync has not completed.