Model guide
StarCoder2 15B
StarCoder2 15B is the larger code-completion checkpoint in this family, with a correspondingly larger local download. Consider it when you already have a completion workflow and want to test whether the additional memory improves useful completions. Use code prefixes or the documented infill format, then compile or run the result.
At a glance
- Parameters
- 15B
- Accepts
- Text
- Returns
- Text, including code
- Published context limit
- 16,384 tokens
- Model format
- safetensors · GGUF
- Software and download hosts
- transformers · Ollama. Follow the exact setup below; this list does not establish support for every format, input type or software version.
- Suggested compression
- Q4_K_M
- Model-weight download
- Q4_K_M weights · 9.86 GBsecond-state (community conversion)starcoder2-15b-Q4_K_M.gguf
- Languages
- 600+ programming languages
- License
- BigCode OpenRAIL-M v1
Will it fit?
StarCoder2 15B · Q4_K_M download. Fit depends on your computer, the app you run it in and the conversation length you need.
Check on your computerBest for
- Code completion — supply the code before and after the gap. Choose an Instruct checkpoint for chat.
- Try the 15B checkpoint when a smaller StarCoder2 completion breaks a nearby test. Compare the actual inserted code at the same cursor.
Choose something else when
- The listed 9.86 GB file is only the weights. Check loaded memory before keeping it as an always-on editor helper.
First setup
For fill-in-the-middle, supply the code before and after the missing section using the publisher’s <fim_prefix>, <fim_suffix> and <fim_middle> format. Prefix: def double(x): followed by an indented return. Suffix: assert double(3) == 6. Submit the prefix and suffix using the displayed infill tokens, then run the assembled function. See the model instructions.
For memory planning, load the linked quantization at 4,096-token context with one request at a time. Record available RAM and VRAM before loading, after loading and while completing a representative code prefix, using Task Manager on Windows, Activity Monitor on macOS or nvidia-smi for an NVIDIA GPU. Increase the context only after the short run leaves adequate memory for other programs. Weight size alone cannot establish fit.
This creates a 4,096-token copy of starcoder2:15b named starcoder2-15b-short-context. Save the following as a file named Modelfile in your working folder:
FROM starcoder2:15b
PARAMETER num_ctx 4096
Then run these commands from that folder:
ollama pull starcoder2:15b
ollama create starcoder2-15b-short-context -f ./Modelfile
ollama run starcoder2-15b-short-context
Run the example in Model-specific setup. While the model is loaded, run ollama ps in another terminal and check CONTEXT and PROCESSOR.
The recorded Ollama package is Q4_0: 9.07 GB of model weights. Use Ollama 0.40.18 or a supporting newer release. A Hugging Face GGUF or MLX checkpoint is a separate representation; choose the matching source and runner in the memory calculator.
See Ollama context settings and the Modelfile instructions.
Open LM Studio’s Discover tab, search for second-state/StarCoder2-15B-GGUF, and download starcoder2-15b-Q4_K_M.gguf (Q4_K_M, 9.86 GB). See the download files. In LM Studio’s Developer tab, select that downloaded model, set context length to 4,096, and load it. Start the local API server and note the displayed port. This is a code-completion model: the following request completes a code prefix without a chat prompt template. If the command fails: Update the llama.cpp runtime if the architecture is unsupported. For memory or loading errors, open the LM Studio loading guide.
Save this as completion.py and run python completion.py (or python3 completion.py if that is your Python command). It uses Python's standard library. Enter the port displayed in LM Studio's Developer tab; the usual default is 1234. Enter an API token only if you enabled authentication. The program lists the server's model IDs; copy the ID for the StarCoder2 model you just loaded, rather than assuming its download filename is the ID.
import json
from getpass import getpass
from urllib.request import Request, urlopen
port = int(input("Port shown in LM Studio Developer: "))
base = f"http://127.0.0.1:{port}/v1"
headers = {"Content-Type": "application/json"}
token = getpass("LM Studio API token (Enter if not required): ")
if token:
headers["Authorization"] = f"Bearer {token}"
with urlopen(Request(base + "/models", headers=headers)) as response:
models = json.load(response)["data"]
for model in models:
print(model["id"])
model_id = input("Copy the loaded StarCoder2 model ID from this list: ").strip()
payload = {
"model": model_id,
"prompt": "def add(a, b):\n return",
"max_tokens": 32,
"temperature": 0,
"stream": False,
}
request = Request(base + "/completions", data=json.dumps(payload).encode("utf-8"),
headers=headers, method="POST")
with urlopen(request) as response:
result = json.load(response)
print(result["choices"][0]["text"])
print("Finish reason:", result["choices"][0]["finish_reason"])
The request uses LM Studio's POST /v1/completions endpoint with max_tokens. The JSON response contains a choices array; choices[0].text is the continuation of the prefix, not a chat message. Check whether the prefix and continuation together form a sensible add function, such as returning a + b; review any generated code before executing it. A length finish reason means the output reached the token cap and may be unfinished. Stop the LM Studio server and unload the model when finished. See the LM Studio completion endpoint and model-list endpoint. The separate llama.cpp recipe below uses its own server on port 8080, /completion, n_predict and content; those are not the LM Studio request or response fields.
Open a terminal in the extracted llama.cpp release folder. On Windows, replace ./llama-server below with .\llama-server.exe:
./llama-server -hf second-state/StarCoder2-15B-GGUF -hff starcoder2-15b-Q4_K_M.gguf -c 4096 --host 127.0.0.1 --port 8080
The server downloads the selected model. Wait for the model to load, then open http://127.0.0.1:8080 in your browser. For completion, send a POST to /completion with JSON {"prompt":"def add(a, b):\n return", "n_predict":32}; inspect the returned content and run any proposed code only after reviewing it. The file list identifies the exact download. If the command fails: Unknown architecture? Update the runner. Allocation failed? Retry with less context or a smaller weight file.
Load the model and time a code completion from a fixed prefix. Use the same prefix, output limit and hardware when comparing another run.
