Top Related Projects
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
PyTorch extensions for high performance and large scale training.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Distributed training framework for TensorFlow, Keras, PyTorch, and Apache MXNet.
Ongoing research training transformer models at scale
An open-source NLP research library, built on PyTorch.
Quick Overview
ColossalAI is an open-source deep learning system for large-scale model training and inference. It aims to make distributed AI more accessible and efficient, offering a comprehensive suite of parallel components for training large models across multiple GPUs and machines.
Pros
- Supports various parallelism paradigms (data, pipeline, tensor, and sequence parallelism)
- Provides memory optimization techniques to reduce GPU memory usage
- Offers seamless integration with popular deep learning frameworks like PyTorch
- Includes tools for both training and inference of large language models
Cons
- Steep learning curve for users new to distributed computing
- Documentation may be lacking in some areas, especially for advanced features
- Requires significant computational resources for optimal performance
- May have compatibility issues with certain hardware configurations
Code Examples
- Initializing ColossalAI:
import colossalai
import torch
colossalai.launch_from_torch(config={})
- Defining a model with ColossalAI:
import colossalai
import colossalai.nn as col_nn
from colossalai.core import global_context as gpc
class MyModel(col_nn.Module):
def __init__(self):
super().__init__()
self.linear = col_nn.Linear(10, 10)
def forward(self, x):
return self.linear(x)
model = MyModel()
- Training loop with ColossalAI:
import torch
from colossalai.core import global_context as gpc
from colossalai.utils import get_dataloader
# Assume dataset and model are defined
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
criterion = torch.nn.CrossEntropyLoss()
for epoch in range(num_epochs):
for data, label in get_dataloader(dataset, batch_size=32):
optimizer.zero_grad()
output = model(data)
loss = criterion(output, label)
loss.backward()
optimizer.step()
Getting Started
To get started with ColossalAI:
- Install ColossalAI:
pip install colossalai
- Create a configuration file (e.g.,
config.py
):
from colossalai.amp import AMP_TYPE
BATCH_SIZE = 128
NUM_EPOCHS = 10
CONFIG = dict(
parallel=dict(
pipeline=2,
tensor=dict(size=2, mode='1d'),
),
optimizer=dict(
type='Adam',
lr=0.001
),
fp16=dict(
mode=AMP_TYPE.TORCH
)
)
- Launch your training script:
import colossalai
colossalai.launch_from_torch(config='./config.py')
# Your model definition and training loop here
Competitor Comparisons
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Pros of DeepSpeed
- More mature and widely adopted in industry and research
- Extensive documentation and community support
- Seamless integration with popular frameworks like PyTorch
Cons of DeepSpeed
- Steeper learning curve for beginners
- Less flexible for customization compared to ColossalAI
Code Comparison
DeepSpeed:
import deepspeed
model_engine, optimizer, _, _ = deepspeed.initialize(args=args, model=model, model_parameters=params)
ColossalAI:
import colossalai
colossalai.launch(config={}, rank=rank, world_size=world_size, host=host, port=port)
Both libraries aim to optimize large-scale model training, but ColossalAI offers a more unified approach with its all-in-one solution. DeepSpeed provides more granular control over optimization techniques, while ColossalAI emphasizes ease of use and automatic optimization.
DeepSpeed's strength lies in its proven track record and extensive ecosystem, making it a go-to choice for many researchers and practitioners. ColossalAI, on the other hand, offers a more streamlined experience with its automatic parallelism and memory management features.
Ultimately, the choice between the two depends on specific project requirements, team expertise, and desired level of control over the training process.
PyTorch extensions for high performance and large scale training.
Pros of FairScale
- More mature and battle-tested in production environments
- Extensive documentation and examples for various use cases
- Stronger integration with PyTorch ecosystem
Cons of FairScale
- Less focus on automatic parallelism and optimization
- Limited support for heterogeneous computing environments
- Narrower scope, primarily focused on scaling deep learning models
Code Comparison
FairScale:
from fairscale.nn import ShardedDataParallel, FullyShardedDataParallel
model = FullyShardedDataParallel(model, sharding_strategy=ShardingStrategy.FULL_SHARD)
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
ColossalAI:
import colossalai
from colossalai.nn.optimizer import HybridAdam
colossalai.launch_from_torch(config={})
model = colossalai.nn.ZeroDDP(model, optimizer_config=dict(cpu_offload=True))
optimizer = HybridAdam(model.parameters(), lr=0.001)
Both libraries aim to simplify distributed training, but ColossalAI offers more automated optimization and a broader range of parallelism strategies. FairScale provides a more straightforward integration with existing PyTorch workflows, while ColossalAI focuses on comprehensive solutions for large-scale AI training. The code examples demonstrate the different approaches to model wrapping and optimization, with ColossalAI offering more built-in features for memory efficiency and scalability.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Pros of PyTorch
- Mature ecosystem with extensive documentation and community support
- Wide range of pre-built models and tools for various AI tasks
- Seamless integration with other popular data science libraries
Cons of PyTorch
- Limited built-in support for distributed training and large-scale models
- Higher memory consumption for large models compared to specialized frameworks
- Steeper learning curve for advanced optimizations and custom operations
Code Comparison
PyTorch:
import torch
model = torch.nn.Linear(10, 5)
optimizer = torch.optim.Adam(model.parameters())
loss = torch.nn.functional.mse_loss(output, target)
loss.backward()
optimizer.step()
ColossalAI:
import colossalai
from colossalai.nn import Linear
from colossalai.optimizer import HybridAdam
model = Linear(10, 5)
optimizer = HybridAdam(model.parameters())
loss = colossalai.nn.loss.MSELoss()(output, target)
engine.backward(loss)
engine.step()
ColossalAI builds upon PyTorch, focusing on distributed training and large-scale models. It offers optimizations for memory efficiency and parallelism, making it suitable for training massive AI models. However, PyTorch remains more versatile and widely adopted for general AI development tasks.
Distributed training framework for TensorFlow, Keras, PyTorch, and Apache MXNet.
Pros of Horovod
- Mature and widely adopted in industry, with strong support for TensorFlow and PyTorch
- Efficient distributed training across multiple GPUs and nodes
- Seamless integration with existing deep learning frameworks
Cons of Horovod
- Limited support for advanced parallelism techniques like pipeline parallelism
- Less flexible for customizing training strategies compared to ColossalAI
- Primarily focused on data parallelism, while ColossalAI offers more diverse parallelism options
Code Comparison
Horovod:
import horovod.torch as hvd
hvd.init()
torch.cuda.set_device(hvd.local_rank())
optimizer = hvd.DistributedOptimizer(optimizer, named_parameters=model.named_parameters())
hvd.broadcast_parameters(model.state_dict(), root_rank=0)
ColossalAI:
import colossalai
colossalai.launch(config={}, rank=rank, world_size=world_size, host=host, port=port)
model = colossalai.nn.DataParallel(model)
optimizer = colossalai.nn.Optimizer(optimizer)
engine, _, _, _ = colossalai.initialize(model, optimizer)
Both libraries aim to simplify distributed training, but ColossalAI offers more advanced features and flexibility in parallelism strategies, while Horovod focuses on efficient data parallelism across multiple devices and frameworks.
Ongoing research training transformer models at scale
Pros of Megatron-LM
- Developed by NVIDIA, optimized for their hardware
- Extensive documentation and research papers
- Strong focus on model parallelism and distributed training
Cons of Megatron-LM
- Less flexible compared to ColossalAI
- Primarily designed for language models, limiting its versatility
- Steeper learning curve for users not familiar with NVIDIA ecosystems
Code Comparison
Megatron-LM:
args = get_args()
model = get_model(args)
optimizer = get_optimizer(model, args)
train(model, optimizer, args)
ColossalAI:
import colossalai
colossalai.launch_from_torch(config={})
model = gpt2_medium()
optimizer = colossalai.nn.Lamb(model.parameters(), lr=0.001)
engine, _, _, _ = colossalai.initialize(model, optimizer)
ColossalAI offers a more streamlined API for distributed training, while Megatron-LM provides more granular control over the training process. ColossalAI's approach is more user-friendly and requires less boilerplate code, making it easier for newcomers to get started with distributed training. However, Megatron-LM's approach may offer more flexibility for advanced users who need fine-grained control over the training pipeline.
An open-source NLP research library, built on PyTorch.
Pros of AllenNLP
- Extensive documentation and tutorials for easy onboarding
- Strong focus on natural language processing tasks
- Well-established and widely used in the research community
Cons of AllenNLP
- Less emphasis on distributed training and large-scale models
- More specialized for NLP, potentially limiting its use in other domains
Code Comparison
AllenNLP:
from allennlp.data import DatasetReader, Instance
from allennlp.data.fields import TextField
from allennlp.data.token_indexers import SingleIdTokenIndexer
class MyDatasetReader(DatasetReader):
def _read(self, file_path: str) -> Iterable[Instance]:
with open(file_path, "r") as file:
for line in file:
yield self.text_to_instance(line.strip())
ColossalAI:
import torch
import colossalai
from colossalai.core import global_context as gpc
from colossalai.utils import get_dataloader
colossalai.launch_from_torch(config={})
model = MyModel()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
dataloader = get_dataloader(dataset, batch_size=gpc.config.BATCH_SIZE)
The code snippets highlight AllenNLP's focus on NLP tasks with its dataset reader implementation, while ColossalAI emphasizes distributed training setup and integration with PyTorch.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Colossal-AI
Colossal-AI: Making large AI models cheaper, faster, and more accessible
Paper | Documentation | Examples | Forum | GPU Cloud Playground | Blog
Latest News
- [2024/06] Open-Sora Continues Open Source: Generate Any 16-Second 720p HD Video with One Click, Model Weights Ready to Use
- [2024/05] Large AI Models Inference Speed Doubled, Colossal-Inference Open Source Release
- [2024/04] Open-Sora Unveils Major Upgrade: Embracing Open Source with Single-Shot 16-Second Video Generation and 720p Resolution
- [2024/04] Most cost-effective solutions for inference, fine-tuning and pretraining, tailored to LLaMA3 series
- [2024/03] 314 Billion Parameter Grok-1 Inference Accelerated by 3.8x, Efficient and Easy-to-Use PyTorch+HuggingFace version is Here
- [2024/03] Open-Sora: Revealing Complete Model Parameters, Training Details, and Everything for Sora-like Video Generation Models
- [2024/03] Open-Soraï¼Sora Replication Solution with 46% Cost Reduction, Sequence Expansion to Nearly a Million
- [2024/01] Inference Performance Improved by 46%, Open Source Solution Breaks the Length Limit of LLM for Multi-Round Conversations
- [2023/07] HPC-AI Tech Raises 22 Million USD in Series A Funding
Table of Contents
- Why Colossal-AI
- Features
-
Colossal-AI for Real World Applications
- Open-Sora: Revealing Complete Model Parameters, Training Details, and Everything for Sora-like Video Generation Models
- Colossal-LLaMA-2: One Half-Day of Training Using a Few Hundred Dollars Yields Similar Results to Mainstream Large Models, Open-Source and Commercial-Free Domain-Specific Llm Solution
- ColossalChat: An Open-Source Solution for Cloning ChatGPT With a Complete RLHF Pipeline
- AIGC: Acceleration of Stable Diffusion
- Biomedicine: Acceleration of AlphaFold Protein Structure
- Parallel Training Demo
- Single GPU Training Demo
- Inference
- Installation
- Use Docker
- Community
- Contributing
- Cite Us
Why Colossal-AI
Prof. James Demmel (UC Berkeley): Colossal-AI makes training AI models efficient, easy, and scalable.
Features
Colossal-AI provides a collection of parallel components for you. We aim to support you to write your distributed deep learning models just like how you write your model on your laptop. We provide user-friendly tools to kickstart distributed training and inference in a few lines.
-
Parallelism strategies
- Data Parallelism
- Pipeline Parallelism
- 1D, 2D, 2.5D, 3D Tensor Parallelism
- Sequence Parallelism
- Zero Redundancy Optimizer (ZeRO)
- Auto-Parallelism
-
Heterogeneous Memory Management
-
Friendly Usage
- Parallelism based on the configuration file
Colossal-AI in the Real World
Open-Sora
Open-Soraï¼Revealing Complete Model Parameters, Training Details, and Everything for Sora-like Video Generation Models [code] [blog] [Model weights] [Demo] [GPU Cloud Playground] [OpenSora Image]
Colossal-LLaMA-2
[GPU Cloud Playground] [LLaMA3 Image]
-
7B: One half-day of training using a few hundred dollars yields similar results to mainstream large models, open-source and commercial-free domain-specific LLM solution. [code] [blog] [HuggingFace model weights] [Modelscope model weights]
-
13B: Construct refined 13B private model with just $5000 USD. [code] [blog] [HuggingFace model weights] [Modelscope model weights]
Model | Backbone | Tokens Consumed | MMLU (5-shot) | CMMLU (5-shot) | AGIEval (5-shot) | GAOKAO (0-shot) | CEval (5-shot) |
---|---|---|---|---|---|---|---|
Baichuan-7B | - | 1.2T | 42.32 (42.30) | 44.53 (44.02) | 38.72 | 36.74 | 42.80 |
Baichuan-13B-Base | - | 1.4T | 50.51 (51.60) | 55.73 (55.30) | 47.20 | 51.41 | 53.60 |
Baichuan2-7B-Base | - | 2.6T | 46.97 (54.16) | 57.67 (57.07) | 45.76 | 52.60 | 54.00 |
Baichuan2-13B-Base | - | 2.6T | 54.84 (59.17) | 62.62 (61.97) | 52.08 | 58.25 | 58.10 |
ChatGLM-6B | - | 1.0T | 39.67 (40.63) | 41.17 (-) | 40.10 | 36.53 | 38.90 |
ChatGLM2-6B | - | 1.4T | 44.74 (45.46) | 49.40 (-) | 46.36 | 45.49 | 51.70 |
InternLM-7B | - | 1.6T | 46.70 (51.00) | 52.00 (-) | 44.77 | 61.64 | 52.80 |
Qwen-7B | - | 2.2T | 54.29 (56.70) | 56.03 (58.80) | 52.47 | 56.42 | 59.60 |
Llama-2-7B | - | 2.0T | 44.47 (45.30) | 32.97 (-) | 32.60 | 25.46 | - |
Linly-AI/Chinese-LLaMA-2-7B-hf | Llama-2-7B | 1.0T | 37.43 | 29.92 | 32.00 | 27.57 | - |
wenge-research/yayi-7b-llama2 | Llama-2-7B | - | 38.56 | 31.52 | 30.99 | 25.95 | - |
ziqingyang/chinese-llama-2-7b | Llama-2-7B | - | 33.86 | 34.69 | 34.52 | 25.18 | 34.2 |
TigerResearch/tigerbot-7b-base | Llama-2-7B | 0.3T | 43.73 | 42.04 | 37.64 | 30.61 | - |
LinkSoul/Chinese-Llama-2-7b | Llama-2-7B | - | 48.41 | 38.31 | 38.45 | 27.72 | - |
FlagAlpha/Atom-7B | Llama-2-7B | 0.1T | 49.96 | 41.10 | 39.83 | 33.00 | - |
IDEA-CCNL/Ziya-LLaMA-13B-v1.1 | Llama-13B | 0.11T | 50.25 | 40.99 | 40.04 | 30.54 | - |
Colossal-LLaMA-2-7b-base | Llama-2-7B | 0.0085T | 53.06 | 49.89 | 51.48 | 58.82 | 50.2 |
Colossal-LLaMA-2-13b-base | Llama-2-13B | 0.025T | 56.42 | 61.80 | 54.69 | 69.53 | 60.3 |
ColossalChat
ColossalChat: An open-source solution for cloning ChatGPT with a complete RLHF pipeline. [code] [blog] [demo] [tutorial]
- Up to 10 times faster for RLHF PPO Stage3 Training
- Up to 7.73 times faster for single server training and 1.42 times faster for single-GPU inference
- Up to 10.3x growth in model capacity on one GPU
- A mini demo training process requires only 1.62GB of GPU memory (any consumer-grade GPU)
- Increase the capacity of the fine-tuning model by up to 3.7 times on a single GPU
- Keep at a sufficiently high running speed
AIGC
Acceleration of AIGC (AI-Generated Content) models such as Stable Diffusion v1 and Stable Diffusion v2.
- Training: Reduce Stable Diffusion memory consumption by up to 5.6x and hardware cost by up to 46x (from A100 to RTX3060).
- DreamBooth Fine-tuning: Personalize your model using just 3-5 images of the desired subject.
- Inference: Reduce inference GPU memory consumption by 2.5x.
Biomedicine
Acceleration of AlphaFold Protein Structure
- FastFold: Accelerating training and inference on GPU Clusters, faster data processing, inference sequence containing more than 10000 residues.
- FastFold with Intel: 3x inference acceleration and 39% cost reduce.
- xTrimoMultimer: accelerating structure prediction of protein monomers and multimer by 11x.
Parallel Training Demo
LLaMA3
- 70 billion parameter LLaMA3 model training accelerated by 18% [code] [GPU Cloud Playground] [LLaMA3 Image]
LLaMA2
LLaMA1
MoE
- Enhanced MoE parallelism, Open-source MoE model training can be 9 times more efficient [code] [blog]
GPT-3
- Save 50% GPU resources and 10.7% acceleration
GPT-2
- 11x lower GPU memory consumption, and superlinear scaling efficiency with Tensor Parallelism
- 24x larger model size on the same hardware
- over 3x acceleration
BERT
- 2x faster training, or 50% longer sequence length
PaLM
- PaLM-colossalai: Scalable implementation of Google's Pathways Language Model (PaLM).
OPT
- Open Pretrained Transformer (OPT), a 175-Billion parameter AI language model released by Meta, which stimulates AI programmers to perform various downstream tasks and application deployments because of public pre-trained model weights.
- 45% speedup fine-tuning OPT at low cost in lines. [Example] [Online Serving]
Please visit our documentation and examples for more details.
ViT
- 14x larger batch size, and 5x faster training for Tensor Parallelism = 64
Recommendation System Models
- Cached Embedding, utilize software cache to train larger embedding tables with a smaller GPU memory budget.
Single GPU Training Demo
GPT-2
- 20x larger model size on the same hardware
- 120x larger model size on the same hardware (RTX 3080)
PaLM
- 34x larger model size on the same hardware
Inference
Colossal-Inference
- Large AI models inference speed doubled, compared to the offline inference performance of vLLM in some cases. [code] [blog] [GPU Cloud Playground] [LLaMA3 Image]
Grok-1
- 314 Billion Parameter Grok-1 Inference Accelerated by 3.8x, an easy-to-use Python + PyTorch + HuggingFace version for Inference.
[code] [blog] [HuggingFace Grok-1 PyTorch model weights] [ModelScope Grok-1 PyTorch model weights]
SwiftInfer
- SwiftInfer: Inference performance improved by 46%, open source solution breaks the length limit of LLM for multi-round conversations
Installation
Requirements:
- PyTorch >= 2.2
- Python >= 3.7
- CUDA >= 11.0
- NVIDIA GPU Compute Capability >= 7.0 (V100/RTX20 and higher)
- Linux OS
If you encounter any problem with installation, you may want to raise an issue in this repository.
Install from PyPI
You can easily install Colossal-AI with the following command. By default, we do not build PyTorch extensions during installation.
pip install colossalai
Note: only Linux is supported for now.
However, if you want to build the PyTorch extensions during installation, you can set BUILD_EXT=1
.
BUILD_EXT=1 pip install colossalai
Otherwise, CUDA kernels will be built during runtime when you actually need them.
We also keep releasing the nightly version to PyPI every week. This allows you to access the unreleased features and bug fixes in the main branch. Installation can be made via
pip install colossalai-nightly
Download From Source
The version of Colossal-AI will be in line with the main branch of the repository. Feel free to raise an issue if you encounter any problems. :)
git clone https://github.com/hpcaitech/ColossalAI.git
cd ColossalAI
# install colossalai
pip install .
By default, we do not compile CUDA/C++ kernels. ColossalAI will build them during runtime. If you want to install and enable CUDA kernel fusion (compulsory installation when using fused optimizer):
BUILD_EXT=1 pip install .
For Users with CUDA 10.2, you can still build ColossalAI from source. However, you need to manually download the cub library and copy it to the corresponding directory.
# clone the repository
git clone https://github.com/hpcaitech/ColossalAI.git
cd ColossalAI
# download the cub library
wget https://github.com/NVIDIA/cub/archive/refs/tags/1.8.0.zip
unzip 1.8.0.zip
cp -r cub-1.8.0/cub/ colossalai/kernel/cuda_native/csrc/kernels/include/
# install
BUILD_EXT=1 pip install .
Use Docker
Pull from DockerHub
You can directly pull the docker image from our DockerHub page. The image is automatically uploaded upon release.
Build On Your Own
Run the following command to build a docker image from Dockerfile provided.
Building Colossal-AI from scratch requires GPU support, you need to use Nvidia Docker Runtime as the default when doing
docker build
. More details can be found here. We recommend you install Colossal-AI from our project page directly.
cd ColossalAI
docker build -t colossalai ./docker
Run the following command to start the docker container in interactive mode.
docker run -ti --gpus all --rm --ipc=host colossalai bash
Community
Join the Colossal-AI community on Forum, Slack, and WeChat(微信) to share your suggestions, feedback, and questions with our engineering team.
Contributing
Referring to the successful attempts of BLOOM and Stable Diffusion, any and all developers and partners with computing powers, datasets, models are welcome to join and build the Colossal-AI community, making efforts towards the era of big AI models!
You may contact us or participate in the following ways:
- Leaving a Star â to show your like and support. Thanks!
- Posting an issue, or submitting a PR on GitHub follow the guideline in Contributing
- Send your official proposal to email contact@hpcaitech.com
Thanks so much to all of our amazing contributors!
CI/CD
We leverage the power of GitHub Actions to automate our development, release and deployment workflows. Please check out this documentation on how the automated workflows are operated.
Cite Us
This project is inspired by some related projects (some by our team and some by other organizations). We would like to credit these amazing projects as listed in the Reference List.
To cite this project, you can use the following BibTeX citation.
@inproceedings{10.1145/3605573.3605613,
author = {Li, Shenggui and Liu, Hongxin and Bian, Zhengda and Fang, Jiarui and Huang, Haichen and Liu, Yuliang and Wang, Boxiang and You, Yang},
title = {Colossal-AI: A Unified Deep Learning System For Large-Scale Parallel Training},
year = {2023},
isbn = {9798400708435},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3605573.3605613},
doi = {10.1145/3605573.3605613},
abstract = {The success of Transformer models has pushed the deep learning model scale to billions of parameters, but the memory limitation of a single GPU has led to an urgent need for training on multi-GPU clusters. However, the best practice for choosing the optimal parallel strategy is still lacking, as it requires domain expertise in both deep learning and parallel computing. The Colossal-AI system addressed the above challenge by introducing a unified interface to scale your sequential code of model training to distributed environments. It supports parallel training methods such as data, pipeline, tensor, and sequence parallelism and is integrated with heterogeneous training and zero redundancy optimizer. Compared to the baseline system, Colossal-AI can achieve up to 2.76 times training speedup on large-scale models.},
booktitle = {Proceedings of the 52nd International Conference on Parallel Processing},
pages = {766â775},
numpages = {10},
keywords = {datasets, gaze detection, text tagging, neural networks},
location = {Salt Lake City, UT, USA},
series = {ICPP '23}
}
Colossal-AI has been accepted as official tutorial by top conferences NeurIPS, SC, AAAI, PPoPP, CVPR, ISC, NVIDIA GTC ,etc.
Top Related Projects
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
PyTorch extensions for high performance and large scale training.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Distributed training framework for TensorFlow, Keras, PyTorch, and Apache MXNet.
Ongoing research training transformer models at scale
An open-source NLP research library, built on PyTorch.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot