Instructions to use bigcode/starcoderbase with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bigcode/starcoderbase with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bigcode/starcoderbase")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("bigcode/starcoderbase") model = AutoModelForCausalLM.from_pretrained("bigcode/starcoderbase") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use bigcode/starcoderbase with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bigcode/starcoderbase" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigcode/starcoderbase", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/bigcode/starcoderbase
- SGLang
How to use bigcode/starcoderbase 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 "bigcode/starcoderbase" \ --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": "bigcode/starcoderbase", "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 "bigcode/starcoderbase" \ --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": "bigcode/starcoderbase", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use bigcode/starcoderbase with Docker Model Runner:
docker model run hf.co/bigcode/starcoderbase
can not generate with mode: Fill-in-the-middle
my code as below:
pip install -q transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
import os
checkpoint = "bigcode/starcoder"
device = "cuda" # for GPU usage or "cpu" for CPU usage
tokenizer = AutoTokenizer.from_pretrained(checkpoint,use_auth_token=True)
model = AutoModelForCausalLM.from_pretrained(checkpoint, trust_remote_code=True,load_in_8bit=True,device_map={"": 0})
input_text = "def print_hello_world():\n \n print('Hello world!')"
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
Does anyone know what is the reason for this?
Can you leave the code you want to fill in blank? It seems the code has been completed and no further action is required in your snippet.
The warning can be eliminated by passing an additional argument to model.generate:
outputs = model.generate(inputs, pad_token_id=tokenizer.eos_token_id)
Also, I strongly suspect that the example has <fim_suffix> and <fim_middle> swapped. When I do this:
input_text = "<fim_prefix>def print_hello_world():\n <fim_middle>\n print('Hello world!')<fim_suffix>"
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
outputs = model.generate(inputs, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(outputs[0]))
I get this output:
<fim_prefix>def print_hello_world():
<fim_middle>
print('Hello world!')<fim_suffix>
if
That trailing if is a bit weird, but it seems not unusual for these models to throw in a stray token at the end; I think I've seen another model do it. Except for that, I gather this output is as intended.
