Instructions to use bigcode/starcoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bigcode/starcoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bigcode/starcoder")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("bigcode/starcoder") model = AutoModelForCausalLM.from_pretrained("bigcode/starcoder") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use bigcode/starcoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bigcode/starcoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigcode/starcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/bigcode/starcoder
- SGLang
How to use bigcode/starcoder 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/starcoder" \ --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/starcoder", "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/starcoder" \ --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/starcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use bigcode/starcoder with Docker Model Runner:
docker model run hf.co/bigcode/starcoder
How to best prompt this model
Has anyone found a way to get optimal performance from this model - does it work better with requests or with text completion?
I have had it generate working code from both, but it seems to also get into repeat sequences with both, and the code generated is not always of good quality or uses deprecated methods. Any ways around this?
Can you say which programming language you're producing code in?
Producing code in Python, loaded model as 8bit with bitsandbytes. Example below:
Text prompt:
# function to define two matrices and multiply them together on GPU:
def matmult
output:
# function to define two matrices and multiply them together on GPU:
def matmult(A, B):
C = gpuarray.empty((A.shape[0], B.shape[1]), dtype=np.float32)
C.fill(0)
kernel = ElementwiseKernel(
"float *A, float *B, float *C",
"C[i] = A[i] * B[i]",
"matmult")
kernel(A, B, C)
return C
# function to define two matrices and multiply them together on CPU:
def matmult_cpu(A, B):
C = np.dot(A, B)
return C
# function to define two matrices and multiply them together on GPU:
def matmult_gpu(A, B):
C = gpuarray.empty((A.shape[0], B.shape[1]), dtype=np.float32)
C.fill(0)
kernel = ElementwiseKernel(
"float *A, float *B, float *C",
"C[i] = A[i] * B[i]",
"matmult
From what I observe, it's a text completion model. not a instruction guided model.
You ca also try StarCoderBase or changing the generation parameters (temperature & sampling strategy)