Skip to main content

A module for balanced loading of large language models

Project description

NiuLoad

niuload is a Python module for balanced loading large language models across multiple GPUs(pipeline parallel). This package can be used during training and inference.

Report (Chinese)

More details can be found at: https://zhuanlan.zhihu.com/p/792303768

Usage

niuload offers the following advanced features:

  1. Customizable load distribution across each GPU. If not specified, the model will be evenly distributed across all GPUs by default.
from niuload import balanced_load
model = balanced_load("openai-community/gpt2", ratio=["0.5,1,1"], num_devices=4)

This example allows you to split the model across four GPUs, with GPU 0 only having half the load compared to the others.

  1. Specify which GPUs to use for model splitting.
from niuload import balanced_load
model = balanced_load("openai-community/gpt2", device_idx=[1,2,5,7], num_devices=4)
  1. Support for training. Models automatically split by Hugging Face's device_map='auto' do not always support training due to a current bug in accelerate. Specifically, when model.device is not on device 0, certain models can encounter errors. We currently force embeddings to be on GPU 0 to avoid this issue.

  2. Support for splitting models that are not supported by Hugging Face, but this requires some additional adaptation. We are working on reorganizing the code structure soon and welcome community contributions to the project.

Benchmark

For reproducing our results in report, you can checkout scripts under /benchmark.

FQA

  1. Q: Why do I see the model being loaded twice?

    A: To better analyze the model's parameter structure, we first load the model onto a meta device. This process is very fast because the initialized tensors are random and meaningless. After obtaining the device_map, we then actually load the model.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niuload-0.2.4.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niuload-0.2.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file niuload-0.2.4.tar.gz.

File metadata

  • Download URL: niuload-0.2.4.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for niuload-0.2.4.tar.gz
Algorithm Hash digest
SHA256 6e65db4fb59ed5650c90287b01985bce4615fec4b2a62578c79069113432700d
MD5 45ca9e2240d31a22619f884361e2a8f4
BLAKE2b-256 64d09e50c9488efdd5e799171dcc810e645437cdb872da6fdbcc9378f641420c

See more details on using hashes here.

File details

Details for the file niuload-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: niuload-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for niuload-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 64fa425e6c134281420f25159ec327c9c33a8e1b748b770a1f3061fbad74fba1
MD5 6add84ce89e9eb697fc3b0e02fd63548
BLAKE2b-256 57fb5de3bdf1932421478ff213fc7683c79d4187fa52005024aed69f41dc0a2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page