Registry / ai-ml / ms-swift

ms-swift

JSON →
library4.3.1pypypiunverified

A scalable lightweight infrastructure for fine-tuning large language models (LLMs), vision-language models (VLMs), and embedding models. Supports LoRA, QLoRA, full fine-tuning, and reinforcement learning methods like DPO, GRPO, and PPO. Version 4.1.3 is the latest, with releases every few weeks.

pip install ms-swift
INSTALL
IMPORT
SIG · MS-SWIFT
M
ms-swift
ai-mlpythonv4.3.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
build_error
glibc
py 3.103.915 runs
timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SwiftTrainer
from swift import SwiftTrainer
from swift.trainers import SwiftTrainer

Basic LoRA fine-tuning with Qwen2.5. Demonstrates correct imports and usage.

from swift import Swift, SwiftModel, LoRAConfig import os # Load a pre-trained model and apply LoRA model = SwiftModel.from_pretrained("Qwen/Qwen2.5-1.5B") lora_config = LoRAConfig(r=8, lora_alpha=32, target_modules=["q_proj", "v_proj"]) model = Swift.prepare_model(model, lora_config) # Quick training snippet (simplified) from swift.trainers import Seq2SeqTrainer from swift.utils import get_dataset train_dataset = get_dataset("json", data_files="train.jsonl") trainer = Seq2SeqTrainer(model=model, train_dataset=train_dataset) trainer.train()
swift --version
Debug
Known issues
breakingIn v4.0.0, the package structure was refactored. SwiftTrainer moved from `swift` to `swift.trainers`, and many utility functions moved to `swift.utils`. Code written for v3.x will break on v4.x without import adjustments.
fix
Update imports: `from swift.trainers import SwiftTrainer`, `from swift.utils import get_dataset`. Use `from swift import LoRAConfig` instead of `from swift.tuners`.
affects: >=4.0.0
deprecatedThe `Megatron` integration (Megatron-SWIFT) has been extracted to a separate repository `mcore-bridge` in v4.1.0. Future updates for Megatron training will be there.
fix
If you rely on Megatron, use the new repo: https://github.com/modelscope/mcore-bridge
affects: >=4.1.0
gotchaWhen using `Swift.prepare_model`, the `target_modules` parameter in LoRAConfig must match actual module names in the model. Common mistake: using default target_modules that may not exist, leading to no LoRA applied silently.
fix
Check model module names via `model.named_modules()` and set `target_modules` accordingly. For most models, `["q_proj", "v_proj", "k_proj", "o_proj"]` works.
affects: all
gotchams-swift requires Python >=3.8. However, some features (like GRPO) may need Python >=3.10 due to newer dependency versions. Using Python 3.8 may cause silent failures or missing optimizations.
fix
Use Python 3.10 or higher for full functionality.
affects: >=4.0
Upgrade
Version history
4.3.1latest on PyPI · released Jun 17, 2026
Audit
Dependencies
torchrequiredCore dependency for model training and inference
transformersrequiredHugging Face Transformers integration
acceleraterequiredDistributed training acceleration
datasetsrequiredDataset loading and processing
peftrequiredParameter-efficient fine-tuning (LoRA, etc.)
wandboptionalExperiment tracking (optional)
Agent activity
78 hits · last 30 days
node
74
OpenAI (training)
1
Resources
ms-swift — pip install ms-swift · libregistry