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 >`
`< fim_prefix >`
`< fim_middle >`
`< fim_suffix >`
`< pad >`

Usage (transformers)

1. Left-to-Right Code Completion

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:

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 (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.
Downloads last month
26
Safetensors
Model size
0.1B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train Bayhakl1/GrimmCoder