Shard Large Language Models
Project description
🧠 Shard LLMs: Unleashing the Power of Large Language Models
🌟 Introduction
Welcome to the Shard LLMs project! This repository provides tools and techniques for efficiently managing and deploying Large Language Models (LLMs) through sharding. By breaking down these massive models, we can overcome resource constraints and unlock their full potential.
🚀 Why Shard LLMs?
Sharding is a game-changer for working with LLMs. Here's why:
- 💾 Memory Optimization: Fit billion-parameter models across multiple GPUs.
- ⚡ Speed Boost: Parallel processing for faster training and inference.
- 📈 Scalability: Effortlessly scale to larger models and datasets.
- 💰 Cost-Effective: Maximize hardware efficiency and reduce training costs.
- 🔄 Enhanced Throughput: Process more requests simultaneously.
- 🛡️ Fault Tolerance: Improve system resilience with distributed processing.
- 🔧 Flexibility: Train large models on limited hardware or scale to massive clusters.
- 🌐 Optimized Communication: Reduce overhead between model components.
🛠️ Getting Started
Prerequisites
Ensure you have all the necessary dependencies:
pip install -r requirements.txt
This will install:
- python-dotenv==1.0.1
- transformers==4.44.2
- torch==2.4.1
Installation
-
Clone the repository:
# SSH git clone git@github.com:yzm1205/Shard-Any-LLMs.git # HTTPS git clone https://github.com/yzm1205/Shard-Any-LLMs.git
-
Navigate to the project directory:
cd Shard-Any-LLMs
🔬 Sharding a Model
To shard a HuggingFace model, use the following command:
python sharding_model.py \
--model_name MODEL-ID \
--save_dir SAVE_DIRECTORY \
--max_shard_size SHARD_SIZE \
--token YOUR_HUGGINGFACE_TOKEN
Example:
Let's shard the LLaMA-3.1-8B-Instruct model as an example:
python sharding_model.py \
--model_name meta-llama/Meta-Llama-3.1-8B-Instruct \
--save_dir ~/sharded_model \
--max_shard_size 2GB \
--token YOUR_HUGGINGFACE_TOKEN
Replace YOUR_HUGGINGFACE_TOKEN with your actual HuggingFace token.
🔧 Loading a Sharded Model
To use your sharded model, you can load it using HuggingFace's AutoModelForCausalLM and AutoTokenizer:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_dir = "./sharded_model/Meta-Llama-3.1-8B-Instruct/"
hf_token = "YOUR_HUGGINGFACE_TOKEN"
model = AutoModelForCausalLM.from_pretrained(
model_dir,
trust_remote_code=True,
torch_dtype=torch.float16,
token=hf_token
)
tokenizer = AutoTokenizer.from_pretrained(
model_dir,
trust_remote_code=True,
token=hf_token
)
💡 Pro Tip: You can also use other methods to load sharded models, such as the
pipelineAPI from Transformers.
🤝 Contributing
We welcome contributions! If you have ideas for improvements or new features, feel free to open an issue or submit a pull request.
🙏 Acknowledgments
- HuggingFace for their amazing Transformers library
- The open-source AI community for continuous inspiration and support
Happy sharding! 🎉
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters