Instructions to use bigscience/bloom with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bigscience/bloom with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bigscience/bloom")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom") model = AutoModelForCausalLM.from_pretrained("bigscience/bloom") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use bigscience/bloom with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bigscience/bloom" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigscience/bloom", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/bigscience/bloom
- SGLang
How to use bigscience/bloom with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "bigscience/bloom" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigscience/bloom", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "bigscience/bloom" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigscience/bloom", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use bigscience/bloom with Docker Model Runner:
docker model run hf.co/bigscience/bloom
BLOOM models don't run on my GPU
The following code successfully runs on my CPU, maxing out a few cores while 3090's usage remains at 0%:
import torch
from transformers import BloomTokenizerFast, BloomForCausalLM
tokenizer = BloomTokenizerFast.from_pretrained("bigscience/bloom-560m")
model = BloomForCausalLM.from_pretrained("bigscience/bloom-560m")
prompt = "Dave picked up the baseball and"
result_length = 100
inputs = tokenizer(prompt, return_tensors="pt")
raw = model.generate(inputs["input_ids"],max_length=result_length)[0]
print(tokenizer.decode(raw))
However, I want to use my GPU. I have tried using different models like 1b7, but the same result. When using accelerate and device_map="auto", torch_dtype="auto", the models run on my GPU, but when trying to decode, I get an error that says "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!". When I add device = torch.device("cuda:0") and .to(device) to the end of the model line, I get the same runtime error. Same with .cuda(). I made sure to configure accelerate to not use my CPU. What am I doing wrong?
I found the solution. I added these 2 lines before raw, then made raw run on inputs2
device = torch.device(“cuda:0”)
inputs2 = inputs.to(device)
Here is the complete working code:
import torch
from transformers import BloomTokenizerFast, BloomForCausalLM
tokenizer = BloomTokenizerFast.from_pretrained(“bigscience/bloom-560m”)
model = BloomForCausalLM.from_pretrained(“bigscience/bloom-560m”).cuda()
prompt = “Dave picked up the baseball and”
result_length = 100
inputs = tokenizer(prompt, return_tensors=“pt”)
device = torch.device(“cuda:0”)
inputs2 = inputs.to(device)
raw = model.generate(inputs2[“input_ids”],max_length=result_length)[0]
print(tokenizer.decode(raw))