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

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

Usages

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.3.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.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: niuload-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d4840d15fce568f8193923604b5bb97bec4820c1b7e7f34fec93a005dbd7abb0
MD5 a84287a9f70bf0dacb361ae9310ad3c6
BLAKE2b-256 a2ff219a981b035713b40fce17757ea09d805c4955a7f1edd167a38aec344973

See more details on using hashes here.

File details

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

File metadata

  • Download URL: niuload-0.2.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4b154b8b47fc693d989a492d0568b8402fd3723df40ef09ffe07eef064a505df
MD5 5c62dd3c79c30fde5cf9ee5ae8edabe7
BLAKE2b-256 7cac42074d63abd5f70aff6ea35bf1ec5c5bef05ce1fa67c277e77c16d137680

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