prime (previously called ZeroBand) is a framework for efficient, globally distributed training of AI models over the internet.
https://github.com/user-attachments/assets/c034d2a2-400c-4bf8-acd0-c84b6c897d69
ElasticDeviceMesh for Fault Tolerant Training:
ElasticDeviceMesh which encapsulates dynamic global process groups for fault-tolerant communication across the internet and local process groups for communication within a node or datacenter.ElasticDeviceMesh manages the resizing of the global process groups when nodes join or leave, unlike the standard DeviceMesh in torch distributed, which will crash and require a cold restart to resize the process group./dev/shm which is a RAM backed filesystem. This operation is much faster and we can unblock the main training process once the checkpoint has been created in /dev/shm./dev/shm into the checkpoint directory on disk as well as upload it to the remote./dev/shm.quantize_per_tensor, scatter_add, index, etc) was too slow, resulting in underutilisation of our target network bandwidth of 4 Gbps.fully_shard API from PyTorch FSDP2 which wraps the model parameters as DTensors and registers hooks to schedule all-gather and reduce-scatter on the tensors when they are used. FSDP2 also optimizes the collectives by bucketing the parameters into FSDPParamGroups. This allows us to execute the collectives on larger tensors, improving protocol-to-payload ratio and improving the overlap from pipelining. We employ the same trick for our pseudo-gradients, bucketing them by layer.A research paper about the framework and our INTELLECT-1 10B experiment can be found here.
For an easy install that download the data
curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/prime/main/scripts/install/install.sh | bash
step by step :
git clone git@github.com:PrimeIntellect-ai/prime.git
uv:curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
sudo apt install iperf -y
uv venv
source .venv/bin/activate
uv sync --extra all
git submodule update --init --recursive
huggingface-cli login
mkdir -p datasets
uv run python scripts/subset_data.py --dataset_name PrimeIntellect/fineweb-edu --data_world_size 1 --data_rank 0 --max_shards 32
mv fineweb-edu/ datasets/fineweb-edu/
Verify your setup:
GLOO_SOCKET_IFNAME=lo GLOBAL_ADDR=localhost GLOBAL_RANK=0 GLOBAL_UNIQUE_ID=0 GLOBAL_WORLD_SIZE=1 GLOBAL_PORT=8989 uv run torchrun --nproc_per_node=2 src/zeroband/train.py @configs/debug/diloco.toml
To test DiLoCo locally you can use the helper script scripts/simulate_multi_node_diloco.sh
# Using 4 GPUs (2 diloco workers, each across 2 GPUs)
ZERO_BAND_LOG_LEVEL=DEBUG ./scripts/simulate_multi_node_diloco.sh 2 2 src/zeroband/train.py @configs/debug/diloco.toml
# Using 2 GPUs (2 diloco workers, each on a single GPU)
ZERO_BAND_LOG_LEVEL=DEBUG ./scripts/simulate_multi_node_diloco.sh 2 1 src/zeroband/train.py @configs/debug/diloco.toml
Ensure you have at least two GPU to run the full test suite:
uv run pytest
To eval you need first to convert the checkpoint to a huggingface compatible model.
uv run python scripts/export_dcp.py @configs/10B/H100.toml --ckpt.path CONVERTED_MODEL_PATH --ckpt.resume CHECKPOINT_PATH --torch_dtype bfloat16 --ckpt.interval 1
uv run accelerate launch -m lm_eval --model hf --model_args pretrained=CONVERTED_MODEL_PATH,add_bos_token=True --tasks hellaswag --num_fewshot 10
| Environment Variable | Description | Default Value |
|---|---|---|
GLOBAL_UNIQUE_ID | Unique identifier worker in global store. | None |
GLOBAL_ADDR | IP Address of the global store | None |
GLOBAL_PORT | Port number of the global store. | None |
GLOBAL_WORLD_SIZE | The size of the global process group. | 1 |
GLOBAL_RANK | Rank of the process in the global process group. | 0 |
| Environment Variable | Description | Default Value |
|---|---|---|
ZERO_BAND_LOG_LEVEL | Enable debug log lines | False |
ZERO_BAND_GLOBAL_STORE_TIMEOUT_SECONDS | Number of seconds before the global store operations timeout | 300 |
ZERO_BAND_GLOBAL_PG_TIMEOUT_SECONDS | Number of seconds before the global process group operations timeout | 600 |
ZERO_BAND_GLOBAL_STORE_POLLING_INTERVAL_SECONDS | Number of seconds between polls to the store when waiting for values | 0.1 |
ZERO_BAND_EDM_HEARTBEAT_INTERVAL_SECONDS | Interval in seconds between heartbeats | 2 |
ZERO_BAND_EDM_HEARTBEAT_TIMEOUT_SECONDS | Time in seconds after which a node is considered dead if no heartbeat is received | 10 |
ZERO_BAND_LIVE_RECO_PORT | Port number for the live recovery server | random |
ZERO_BAND_LIVE_RECO_ADDR | IP Address for the live recovery server | localhost |
If you encounter any dataset loading errors at the beginning of training, try setting:
export HF_HUB_ETAG_TIMEOUT=500
Streaming datasets from huggingface hub can sometimes result in http 443 errors which will crash the training process. To avoid them, you can pre-download the dataset.
Here is an example that downloads all the files in PrimeIntellect/fineweb-edu which are used by data_rank 5 in a training with data_world_size of 12.
python3 scripts/subset_data.py --dataset_name PrimeIntellect/fineweb-edu --data_world_size 12 --data_rank 5
For info about the arguments to the script, do:
python3 scripts/subset_data.py --help
You can convert the checkpoints saved by the training script to a model that can be run with any huggingface-compatible inference engine (e.g. transformers, vLLM) using our export script.
The export script takes the training config as a positional argument and 2 keyword arguments, ckpt.resume which is the path to the checkpoint, ckpt.path which is the path you wish to save the converted model.
You may also pass the torch_dtype argument to either float32 or bfloat16 to specify the precision of the exported model weights. The default torch_dtype is float32.
Example export command:
python scripts/export_dcp.py @configs/10B/H100.toml --ckpt.path /path/to/save/converted_model --ckpt.resume /path/to/ckpt/step_84000 --torch_dtype bfloat16
You can then upload the model to huggingface using huggingface-cli:
# Usage: huggingface-cli upload [repo_id] [local_path] [path_in_repo]
huggingface-cli upload username/mymodel /path/to/save/converted_model . --private
The repo will be created if repo_id does not exist. The --private will create the repo as a private repo and can be ommited to create a publicly accessible repo.
Python
92.6%
C++
5.3%
Shell
2.1%
prime (previously called ZeroBand) is a framework for efficient, globally distributed training of AI models over the internet.
https://github.com/user-attachments/assets/c034d2a2-400c-4bf8-acd0-c84b6c897d69
ElasticDeviceMesh for Fault Tolerant Training:
ElasticDeviceMesh which encapsulates dynamic global process groups for fault-tolerant communication across the internet and local process groups for communication within a node or datacenter.ElasticDeviceMesh manages the resizing of the global process groups when nodes join or leave, unlike the standard DeviceMesh in torch distributed, which will crash and require a cold restart to resize the process group./dev/shm which is a RAM backed filesystem. This operation is much faster and we can unblock the main training process once the checkpoint has been created in /dev/shm./dev/shm into the checkpoint directory on disk as well as upload it to the remote./dev/shm.quantize_per_tensor, scatter_add, index, etc) was too slow, resulting in underutilisation of our target network bandwidth of 4 Gbps.fully_shard API from PyTorch FSDP2 which wraps the model parameters as DTensors and registers hooks to schedule all-gather and reduce-scatter on the tensors when they are used. FSDP2 also optimizes the collectives by bucketing the parameters into FSDPParamGroups. This allows us to execute the collectives on larger tensors, improving protocol-to-payload ratio and improving the overlap from pipelining. We employ the same trick for our pseudo-gradients, bucketing them by layer.A research paper about the framework and our INTELLECT-1 10B experiment can be found here.
For an easy install that download the data
curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/prime/main/scripts/install/install.sh | bash
step by step :
git clone git@github.com:PrimeIntellect-ai/prime.git
uv:curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
sudo apt install iperf -y
uv venv
source .venv/bin/activate
uv sync --extra all
git submodule update --init --recursive
huggingface-cli login
mkdir -p datasets
uv run python scripts/subset_data.py --dataset_name PrimeIntellect/fineweb-edu --data_world_size 1 --data_rank 0 --max_shards 32
mv fineweb-edu/ datasets/fineweb-edu/
Verify your setup:
GLOO_SOCKET_IFNAME=lo GLOBAL_ADDR=localhost GLOBAL_RANK=0 GLOBAL_UNIQUE_ID=0 GLOBAL_WORLD_SIZE=1 GLOBAL_PORT=8989 uv run torchrun --nproc_per_node=2 src/zeroband/train.py @configs/debug/diloco.toml
To test DiLoCo locally you can use the helper script scripts/simulate_multi_node_diloco.sh
# Using 4 GPUs (2 diloco workers, each across 2 GPUs)
ZERO_BAND_LOG_LEVEL=DEBUG ./scripts/simulate_multi_node_diloco.sh 2 2 src/zeroband/train.py @configs/debug/diloco.toml
# Using 2 GPUs (2 diloco workers, each on a single GPU)
ZERO_BAND_LOG_LEVEL=DEBUG ./scripts/simulate_multi_node_diloco.sh 2 1 src/zeroband/train.py @configs/debug/diloco.toml
Ensure you have at least two GPU to run the full test suite:
uv run pytest
To eval you need first to convert the checkpoint to a huggingface compatible model.
uv run python scripts/export_dcp.py @configs/10B/H100.toml --ckpt.path CONVERTED_MODEL_PATH --ckpt.resume CHECKPOINT_PATH --torch_dtype bfloat16 --ckpt.interval 1
uv run accelerate launch -m lm_eval --model hf --model_args pretrained=CONVERTED_MODEL_PATH,add_bos_token=True --tasks hellaswag --num_fewshot 10
| Environment Variable | Description | Default Value |
|---|---|---|
GLOBAL_UNIQUE_ID | Unique identifier worker in global store. | None |
GLOBAL_ADDR | IP Address of the global store | None |
GLOBAL_PORT | Port number of the global store. | None |
GLOBAL_WORLD_SIZE | The size of the global process group. | 1 |
GLOBAL_RANK | Rank of the process in the global process group. | 0 |
| Environment Variable | Description | Default Value |
|---|---|---|
ZERO_BAND_LOG_LEVEL | Enable debug log lines | False |
ZERO_BAND_GLOBAL_STORE_TIMEOUT_SECONDS | Number of seconds before the global store operations timeout | 300 |
ZERO_BAND_GLOBAL_PG_TIMEOUT_SECONDS | Number of seconds before the global process group operations timeout | 600 |
ZERO_BAND_GLOBAL_STORE_POLLING_INTERVAL_SECONDS | Number of seconds between polls to the store when waiting for values | 0.1 |
ZERO_BAND_EDM_HEARTBEAT_INTERVAL_SECONDS | Interval in seconds between heartbeats | 2 |
ZERO_BAND_EDM_HEARTBEAT_TIMEOUT_SECONDS | Time in seconds after which a node is considered dead if no heartbeat is received | 10 |
ZERO_BAND_LIVE_RECO_PORT | Port number for the live recovery server | random |
ZERO_BAND_LIVE_RECO_ADDR | IP Address for the live recovery server | localhost |
If you encounter any dataset loading errors at the beginning of training, try setting:
export HF_HUB_ETAG_TIMEOUT=500
Streaming datasets from huggingface hub can sometimes result in http 443 errors which will crash the training process. To avoid them, you can pre-download the dataset.
Here is an example that downloads all the files in PrimeIntellect/fineweb-edu which are used by data_rank 5 in a training with data_world_size of 12.
python3 scripts/subset_data.py --dataset_name PrimeIntellect/fineweb-edu --data_world_size 12 --data_rank 5
For info about the arguments to the script, do:
python3 scripts/subset_data.py --help
You can convert the checkpoints saved by the training script to a model that can be run with any huggingface-compatible inference engine (e.g. transformers, vLLM) using our export script.
The export script takes the training config as a positional argument and 2 keyword arguments, ckpt.resume which is the path to the checkpoint, ckpt.path which is the path you wish to save the converted model.
You may also pass the torch_dtype argument to either float32 or bfloat16 to specify the precision of the exported model weights. The default torch_dtype is float32.
Example export command:
python scripts/export_dcp.py @configs/10B/H100.toml --ckpt.path /path/to/save/converted_model --ckpt.resume /path/to/ckpt/step_84000 --torch_dtype bfloat16
You can then upload the model to huggingface using huggingface-cli:
# Usage: huggingface-cli upload [repo_id] [local_path] [path_in_repo]
huggingface-cli upload username/mymodel /path/to/save/converted_model . --private
The repo will be created if repo_id does not exist. The --private will create the repo as a private repo and can be ommited to create a publicly accessible repo.
Python
92.6%
C++
5.3%
Shell
2.1%