Text Generation
Transformers
Safetensors
code
English
llama
python
code-completion
fill-in-the-middle
fim
text-generation-inference
Instructions to use Bayhakl1/GrimmCoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Bayhakl1/GrimmCoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Bayhakl1/GrimmCoder")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Bayhakl1/GrimmCoder") model = AutoModelForCausalLM.from_pretrained("Bayhakl1/GrimmCoder", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Bayhakl1/GrimmCoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Bayhakl1/GrimmCoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Bayhakl1/GrimmCoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Bayhakl1/GrimmCoder
- SGLang
How to use Bayhakl1/GrimmCoder 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 "Bayhakl1/GrimmCoder" \ --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": "Bayhakl1/GrimmCoder", "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 "Bayhakl1/GrimmCoder" \ --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": "Bayhakl1/GrimmCoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Bayhakl1/GrimmCoder with Docker Model Runner:
docker model run hf.co/Bayhakl1/GrimmCoder
File size: 4,862 Bytes
3e5299f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | ---
language:
- code
- en
license: apache-2.0
datasets:
- bigcode/starcoderdata
library_name: transformers
pipeline_tag: text-generation
tags:
- code
- python
- code-completion
- fill-in-the-middle
- fim
- llama
---
# GrimmCoder
**GrimmCoder** is a ~107M-parameter LLaMA-style decoder-only transformer trained from scratch exclusively on Python source code for both **left-to-right completion** and **Fill-in-the-Middle (FIM)** code completion.
## Model Summary
| Property | Value |
|---|---|
| Architecture | LLaMA (`LlamaForCausalLM`, pre-norm, RoPE, SwiGLU, GQA, tied embeddings) |
| Parameters | ~106.98M total (~100.69M non-embedding) |
| Context Length | 2048 tokens |
| Hidden Size (`d_model`) | 768 |
| Layers | 16 |
| Attention Heads | 12 query heads / 4 KV heads (GQA) |
| FFN Intermediate Size | 2048 (SwiGLU) |
| Vocabulary | 8192 (byte-level BPE trained on Python) |
| Training Data | `bigcode/starcoderdata` (Python subset) |
| Tokens / Checkpoint | 7.93B tokens (step 61,500, validation loss 1.2321) |
## Special Tokens
| Token | ID | Purpose |
|---|---|---|
| `<|endoftext|>` | `0` | BOS / EOS / document delimiter |
| `<|fim_prefix|>` | `1` | FIM prefix marker |
| `<|fim_middle|>` | `2` | FIM middle marker (model generates from here) |
| `<|fim_suffix|>` | `3` | FIM suffix marker |
| `<|pad|>` | `4` | Padding token |
## Usage (`transformers`)
### 1. Left-to-Right Code Completion
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "Bayhakl1/GrimmCoder"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
dtype=torch.bfloat16,
device_map="auto",
)
prompt = """def binary_search(arr, target):
lo, hi = 0, len(arr) - 1
"""
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=128,
do_sample=True,
temperature=0.2,
top_p=0.95,
eos_token_id=[0, 1, 2, 3, 4],
pad_token_id=4,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
### 2. Fill-in-the-Middle (FIM)
The model was trained 50/50 on PSM and SPM Fill-in-the-Middle formatting. Note `add_special_tokens=False` when tokenizing raw prefix/suffix segments:
```python
prefix = "def add(a: int, b: int) -> int:\n "
suffix = "\n\nprint(add(2, 3))\n"
# PSM format: <|fim_prefix|> prefix <|fim_suffix|> suffix <|fim_middle|>
fim_prompt = f"<|fim_prefix|>{prefix}<|fim_suffix|>{suffix}<|fim_middle|>"
inputs = tokenizer(fim_prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=64,
do_sample=True,
temperature=0.2,
top_p=0.95,
eos_token_id=[0, 1, 2, 3, 4],
pad_token_id=4,
)
middle_ids = outputs[0][inputs["input_ids"].shape[1]:]
middle = tokenizer.decode(middle_ids, skip_special_tokens=True)
print(prefix + middle + suffix)
```
## Evaluation (HumanEval)
Evaluated on [`openai/openai_humaneval`](https://huggingface.co/datasets/openai/openai_humaneval) (164 Python problems) using `transformers` (`bfloat16`):
| Prompt Mode | Decoding | `pass@1` | Solved |
|---|---|---|---|
| Left-to-Right (`prompt.rstrip("\n")`, ending on `"""`) | greedy (`do_sample=False`, `max_new_tokens=128`) | **5.49%** | 9 / 164 |
| Left-to-Right (`prompt.rstrip("\n")`, ending on `"""`) | `temperature=0.2`, `top_k=50`, `top_p=0.95`, `repetition_penalty=1.1` | **4.88%** | 8 / 164 |
| Fill-in-the-Middle (PSM: `<\|fim_prefix\|>{prompt}<\|fim_suffix\|>\n<\|fim_middle\|>`) | greedy (`do_sample=False`, `max_new_tokens=384`) | **4.27%** | 7 / 164 |
| Left-to-Right (raw `prompt` ending on `"""\n`) | greedy (`do_sample=False`, `max_new_tokens=384`) | **0.00%** | 0 / 164 |
> **Notes:**
> - As a base completion model pretrained on raw `starcoderdata`, prompts ending directly on `"""\n` often resemble empty stub/interface files (predicting `<|endoftext|>` or starting another `def`). Stripping the trailing newline so the prompt ends on `"""` (or prompting in FIM-PSM mode) cues the model to emit the indented function body instead.
> - In `bfloat16` (`transformers`), minor intermediate precision rounding can affect borderline tokens (for example, `HumanEval/48` passes in `float32` while `bfloat16` scores `9/164` / `5.49%` greedy). Also keep `repetition_penalty=1.0` when using `transformers` `generate()`, as HF applies `repetition_penalty` across the prompt docstring as well.
## Limitations
- Trained exclusively on Python source code; not intended as a general natural-language chat or instruction-following model.
- Base / completion model: responds best to code prompts and FIM markers rather than conversational Q&A.
|