xTuring

stochasticaiApache-2.0活跃维护

xTuring 提供从数据预处理到微调的完整流程,让开发者用 LoRA、Adapter 等轻量方法快速个性化开源大模型,降低训练门槛和显存开销。

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 discord community: https://discord.gg/TgHXuSJEk6

v0.1.8发布于 2023-09-07 12:08 UTC2,679star209fork同步于 2026-11-10 11:43 UTC

怎么上手

由 README 提炼,执行前请确认
pip install xturing
硬件要求按 README 说明

README 未给出通用最低显存要求;性能测试使用 4 张 A100 40GB 与 335GB 内存。支持 CPU 与笔记本推理(基于 Intel Extension for Transformers,面向 Intel 平台),也可从单机扩展到多 GPU。

纯 CPU 可运行支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在本地或私有云上微调、评估并运行开源大模型的一站式 Python 工具库

xTuring 提供从数据预处理到微调的完整流程,让开发者用 LoRA、Adapter 等轻量方法快速个性化开源大模型,降低训练门槛和显存开销。

核心能力

  • 用统一 API 完成数据准备、微调与推理
  • 支持 LoRA 与 INT8/INT4 低精度微调以降低成本
  • 内置 perplexity 指标评估任意因果语言模型
  • 通过 Intel 扩展支持 CPU 推理与权重量化
  • 提供 CLI 与本地 UI Playground 交互试用模型

容易踩的坑

需 transformers>=4.36.0,且不要升级到 5.x,否则 INT8/INT4 依赖的 load_in_8bit/load_in_4bit 参数会失效;Qwen3-Omni 支持尚未发布,需自行从 Hugging Face 提前下载模型;大模型(如 GPT-OSS 20B/120B)需要大量资源,建议先用 Qwen3 0.6B 的 CPU 示例验证流程。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.1.8
  1. v0.1.80.1.8最新正式版2023-09-07 · 2023-09-07 12:08 UTC

    Stability and documentation

    • New version of Documentation is live, thanks to @tushar2407.
    • Updated contribution guide.
    • Stability improvements and bugfixing.
    • int8 generation now works even better.
  2. v0.1.70.1.72023-07-26 · 2023-07-26 13:45 UTC
    查看更新说明

    Evaluation and documentation, CPU support

    • Evaluation of finetuned models, thanks to @tushar2407.
    • Llama2 model support and enchantments of Generic models.
    • Batch size support for both evaluation and generation.
    • CPU inference and finetuning.
    • Documentation and examples, thanks to @tushar2407.
  3. v0.1.60.1.62023-07-12 · 2023-07-12 11:21 UTC
    查看更新说明

    INT4 models

    • INT4 Generic model now supports large variety of open source models finetuning in INT4, thanks to @tushar2407.
    • All INT4 finetunings are now much stable and work on large variety of GPUs.
    • Support of flags for models loading, thanks to @msinha251.
    • Documentation enchantment and bug fix, thanks to @tushar2407.
  4. v0.1.5BaseModel bug fix2023-06-14 · 2023-06-14 11:04 UTC
    查看更新说明
    • Changing BaseModel to work with LoRA after previous release, thanks to @tushar2407
  5. v0.1.40.1.42023-06-13 · 2023-06-13 13:18 UTC
    查看更新说明

    New models and logging

    • Generic model to support large variety of open source models, thanks to @tushar2407
    • Falcon model support as a latest open source model release, thanks to @tushar2407
    • Documentation enchantment, again, big thanks to @tushar2407
    • Logger integration and refactoring, thanks to @Georgehe4

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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:

    • Simple API for data prep, training, and inference
    • Private by default: run locally or in your VPC
    • Efficient: LoRA and low‑precision (INT8/INT4) to cut costs
    • Scales from CPU/laptop to multi‑GPU easily
    • Evaluate models with built‑in metrics (e.g., perplexity)

    ⚙️ Installation

    pip install xturing
    

    Note: 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.

    Development Installation

    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-msg
    

    🚀 Quickstart

    Run 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.

    🌟 What's new?

    Highlights from recent updates:

    1. GPT‑OSS integration – Use and fine‑tune 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 prompts
    
    1. LLaMA 2 integration – Off‑the‑shelf, INT8, LoRA, LoRA+INT8, and LoRA+INT4 via GenericModel or Llama2.
    from xturing.models import Llama2
    model = Llama2()
    
    ## or
    from xturing.models import BaseModel
    model = BaseModel.create('llama2')
    
    
    1. Evaluation – Evaluate any causal LM on any dataset. Currently supports 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}")
    
    
    1. INT4 precision – Fine‑tune many LLMs with INT4 using 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)
    
    1. CPU inference – Run inference on CPUs (including laptops) via Intel® Extension for Transformers, using weight‑only quantization and optimized kernels on Intel platforms.
    # 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)
    
    1. Batching – Set 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)
    
    
    1. Qwen3 0.6B supervised fine-tuning – The lightweight Qwen3 0.6B checkpoint now has first-class support (registry, configs, docs, and examples) so you can launch SFT/LoRA jobs immediately.
    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.py for a runnable script.

    1. Qwen3-Omni dataset generation – Run the multimodal checkpoint locally (download from Hugging Face) to bootstrap instruction corpora without leaving your machine.
    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.

    CLI playground

    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 --help
    

    UI playground

    from 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
    
    

    📚 Tutorials

    📊 Performance

    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-7BDeepSpeed + CPU OffloadingLoRA + DeepSpeedLoRA + DeepSpeed + CPU Offloading
    GPU33.5 GB23.7 GB21.9 GB
    CPU190 GB10.2 GB14.9 GB
    Time/epoch21 hours20 mins20 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.

    📎 Fine‑tuned model checkpoints

    We have already fine-tuned some models that you can use as your base or start playing with.

    Loading Models

    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")
    

    Available Pre-trained Models

    modeldatasetPath
    DistilGPT-2 LoRAalpacax/distilgpt2_lora_finetuned_alpaca
    LLaMA LoRAalpacax/llama_lora_finetuned_alpaca

    Supported Models

    Below is a list of all the supported models via BaseModel class of xTuring and their corresponding keys to load them.

    ModelKey
    DistilGPT-2distilgpt2
    GPT-OSS (20B/120B)gpt_oss_20b, gpt_oss_120b
    GPT-Jgptj
    GPT-2gpt2
    LLaMAllama
    LLaMA2llama2
    Mistral-7Bmistral_7b
    Ministral 3.14Bministral_3_14b
    MiniMaxM2minimax_m2
    OPT-1.3Bopt
    Qwen3 0.6Bqwen3_0_6b
    Mambamamba

    The above are the base variants. Use these templates for LoRA, INT8, and INT8 + LoRA versions:

    VersionTemplate
    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.

    📈 Roadmap

    • Support for LLaMA, LLaMA 2, GPT-J, GPT-2, and GPT-OSS models
    • Dataset generation using self-instruction
    • Low-precision LoRA fine-tuning and unsupervised fine-tuning
    • INT8 low-precision fine-tuning support
    • OpenAI, Cohere, and Claude model APIs for dataset generation
    • Added fine-tuned checkpoints for some models to the hub
    • INT4 LLaMA LoRA fine-tuning demo
    • INT4 LLaMA LoRA fine-tuning with INT4 generation
    • Support for a Generic model wrapper
    • Support for MiniMax M2, Qwen3 0.6B, and Mamba models
    • INT4 low-precision fine-tuning support
    • Evaluation of LLM models
    • INT3, INT2, INT1 low-precision fine-tuning support
    • Support for Stable Diffusion

    🧪 Running Tests

    The project uses pytest for testing. Test files are located in the tests/ directory.

    Run all tests:

    pytest
    

    Run a specific test file:

    pytest tests/xturing/models/test_qwen_model.py
    

    Skip slow tests:

    pytest -m "not slow"
    

    Skip GPU tests (for CPU-only environments):

    pytest -m "not gpu"
    

    Test markers used in this project:

    • @pytest.mark.slow - Tests that take significant time to run
    • @pytest.mark.gpu - Tests requiring GPU hardware

    🤝 Help and Support

    If you have any questions, you can create an issue on this repository.

    You can also join our Discord server and start a discussion in the #xturing channel.

    🏗️ Project Structure

    Understanding the codebase organization:

    src/xturing/
    ├── models/          # Model classes and registry (BaseModel, LLaMA, GPT-2, etc.)
    ├── engines/         # Low-level model loading, tokenization, and operations
    ├── datasets/        # Dataset loaders (InstructionDataset, TextDataset)
    ├── trainers/        # Training loops (LightningTrainer with DeepSpeed support)
    ├── preprocessors/   # Data preprocessing and tokenization
    ├── config/          # YAML configurations for finetuning and generation
    ├── cli/             # CLI commands (chat, ui, api)
    ├── ui/              # Gradio UI playground
    ├── self_instruct/   # Dataset generation utilities
    └── utils/           # Shared utilities
    
    tests/xturing/       # Test suite mirroring src structure
    examples/            # Example scripts organized by model and feature
    

    Key architectural patterns:

    • Registry Pattern: Models and engines use a registry-based factory pattern via BaseModel.create() and BaseEngine.create()
    • Model Variants: Each model family has multiple variants following the naming template <base>_[lora]_[int8|kbit]
      • Example: llama, llama_lora, llama_int8, llama_lora_int8
    • Configuration: Training and generation parameters are defined in YAML files per model in src/xturing/config/
    • Engines: Handle the low-level operations (loading weights, tokenization, DeepSpeed integration)
    • Models: Provide high-level API (finetune(), generate(), evaluate(), save(), load())

    📝 License

    This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

    🌎 Contributing

    As an open source project in a rapidly evolving field, we welcome contributions of all kinds, including new features and better documentation. Please read our contributing guide to learn how you can get involved.

    Quick Contribution Guidelines

    Important: All pull requests should target the dev branch, not main.

    The project uses pre-commit hooks to enforce code quality:

    • black - Code formatting
    • isort - Import sorting (black profile)
    • autoflake - Remove unused imports
    • absolufy-imports - Convert relative to absolute imports
    • gitlint - Commit message linting

    You can manually format code:

    black src/ tests/
    isort src/ tests/
    

    Pre-commit hooks will automatically run these checks when you commit. Make sure to install them:

    pre-commit install
    pre-commit install --hook-type commit-msg