Convert Figma logo to code with AI

hpcaitech logoColossalAI

Making large AI models cheaper, faster and more accessible

38,735
4,341
38,735
433

Top Related Projects

34,658

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.

82,049

Tensors and Dynamic neural networks in Python with strong GPU acceleration

14,221

Distributed training framework for TensorFlow, Keras, PyTorch, and Apache MXNet.

Ongoing research training transformer models at scale

11,750

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

  1. Initializing ColossalAI:
import colossalai
import torch

colossalai.launch_from_torch(config={})
  1. 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()
  1. 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:

  1. Install ColossalAI:
pip install colossalai
  1. 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
    )
)
  1. Launch your training script:
import colossalai

colossalai.launch_from_torch(config='./config.py')

# Your model definition and training loop here

Competitor Comparisons

34,658

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.

82,049

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.

14,221

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.

11,750

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Colossal-AI

logo

Colossal-AI: Making large AI models cheaper, faster, and more accessible

Paper | Documentation | Examples | Forum | GPU Cloud Playground | Blog

GitHub Repo stars Build Documentation CodeFactor HuggingFace badge slack badge WeChat badge

| English | 中文 |

Latest News

Table of Contents

Why Colossal-AI

Prof. James Demmel (UC Berkeley): Colossal-AI makes training AI models efficient, easy, and scalable.

(back to top)

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.

(back to top)

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]

(back to top)

Colossal-LLaMA-2

[GPU Cloud Playground] [LLaMA3 Image]

ModelBackboneTokens ConsumedMMLU (5-shot)CMMLU (5-shot)AGIEval (5-shot)GAOKAO (0-shot)CEval (5-shot)
Baichuan-7B-1.2T42.32 (42.30)44.53 (44.02)38.7236.7442.80
Baichuan-13B-Base-1.4T50.51 (51.60)55.73 (55.30)47.2051.4153.60
Baichuan2-7B-Base-2.6T46.97 (54.16)57.67 (57.07)45.7652.6054.00
Baichuan2-13B-Base-2.6T54.84 (59.17)62.62 (61.97)52.0858.2558.10
ChatGLM-6B-1.0T39.67 (40.63)41.17 (-)40.1036.5338.90
ChatGLM2-6B-1.4T44.74 (45.46)49.40 (-)46.3645.4951.70
InternLM-7B-1.6T46.70 (51.00)52.00 (-)44.7761.6452.80
Qwen-7B-2.2T54.29 (56.70)56.03 (58.80)52.4756.4259.60
Llama-2-7B-2.0T44.47 (45.30)32.97 (-)32.6025.46-
Linly-AI/Chinese-LLaMA-2-7B-hfLlama-2-7B1.0T37.4329.9232.0027.57-
wenge-research/yayi-7b-llama2Llama-2-7B-38.5631.5230.9925.95-
ziqingyang/chinese-llama-2-7bLlama-2-7B-33.8634.6934.5225.1834.2
TigerResearch/tigerbot-7b-baseLlama-2-7B0.3T43.7342.0437.6430.61-
LinkSoul/Chinese-Llama-2-7bLlama-2-7B-48.4138.3138.4527.72-
FlagAlpha/Atom-7BLlama-2-7B0.1T49.9641.1039.8333.00-
IDEA-CCNL/Ziya-LLaMA-13B-v1.1Llama-13B0.11T50.2540.9940.0430.54-
Colossal-LLaMA-2-7b-baseLlama-2-7B0.0085T53.0649.8951.4858.8250.2
Colossal-LLaMA-2-13b-baseLlama-2-13B0.025T56.4261.8054.6969.5360.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

(back to top)

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

  • Inference: Reduce inference GPU memory consumption by 2.5x.

(back to top)

Biomedicine

Acceleration of AlphaFold Protein Structure

  • FastFold: Accelerating training and inference on GPU Clusters, faster data processing, inference sequence containing more than 10000 residues.

  • xTrimoMultimer: accelerating structure prediction of protein monomers and multimer by 11x.

(back to top)

Parallel Training Demo

LLaMA3

LLaMA2

  • 70 billion parameter LLaMA2 model training accelerated by 195% [code] [blog]

LLaMA1

  • 65-billion-parameter large model pretraining accelerated by 38% [code] [blog]

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

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.

(back to top)

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

(back to top)

Inference

Colossal-Inference

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

(back to top)

Installation

Requirements:

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 .

(back to top)

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

(back to top)

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:

  1. Leaving a Star ⭐ to show your like and support. Thanks!
  2. Posting an issue, or submitting a PR on GitHub follow the guideline in Contributing
  3. Send your official proposal to email contact@hpcaitech.com

Thanks so much to all of our amazing contributors!

(back to top)

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.

(back to top)