CoolFace
Modelpublic

Beebey/smallcoder-303m

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
4likes30downloads
Model Card

🧠 SmallCoder (303M)

SmallCoder is a 303M parameter LLaMA-style language model trained from scratch for code generation and algorithmic reasoning.

This checkpoint represents a 6B-token Supervised Fine-Tuning (SFT) run that fixed a critical End-of-Sequence (EOS) token bug from earlier versions.

Despite its compact size, SmallCoder achieves state-of-the-art (SOTA) coding performance for <500M models, rivaling 1B–7B parameter LLMs.

Trained with support from Google’s TPU Research Cloud (TRC) program.

πŸš€ Key Results

ModelSizeHumanEval (pass@1)MBPP (pass@1)
SmallCoder (Stage 4.1)303M27.4 %31.0 %
TinyLlama-1.1B1.1B~26.4 %~27.6 %
MPT-1B-Instruct1.0B~22.0 %~25.0 %
Zephyr-1.3B-SFT1.3B31.0 %34.0 %
Mistral-7B-Base7B30.5 %47.5 %
βš–οΈ SmallCoder nearly matches Mistral 7B on HumanEval while being 23Γ— smaller.

🧬 Model Architecture

A LLaMA-type causal decoder with standard Multi-Head Attention (MHA).

python
LlamaConfig(
  vocab_size=49152,               # StarCoder tokenizer
  hidden_size=768,
  num_hidden_layers=24,
  num_attention_heads=8,
  num_key_value_heads=8,
  intermediate_size=3072,
  max_position_embeddings=1024,
)
ParameterValue
Total parametersβ‰ˆ 303 M
Context length1 024 tokens
Tokenizerbigcode/starcoder
Architecture typeLLaMA (MHA, non-GQA)
Precisionbfloat16
OptimizerAdamW XLA
HardwareTPU v4-32 (TRC)

πŸ“š Training Curriculum (4 Stages, 29.8B tokens)

StageTokens (B)DatasetObjectiveLoss ↓
1. Linguistic Base6.3FineWeb-EduGeneral English grounding10.87 β†’ 2.58
2. Code Specialization7.560 % Nemotron Synthetic Code / 40 % StarCoderDataCode syntax & reasoning5.00 β†’ 1.25
3. Math & Knowledge10.0Nemotron CC-Math / FineWiki / OpenWebMathMathematical reasoning2.77 β†’ 1.55
4.1 SFT (EOS Fixed)6.0Nemotron SFT / OpenCodeInstruct / OpenMathInstruct-2Instruction-tuned code alignment1.73 β†’ ~0.70
🧩 Total β‰ˆ 29.8 B tokens of curated curriculum learning.

πŸ“Š Detailed Benchmarks (Stage 4.1 SFT)

DomainBenchmarkMetricScore
CodeHumanEval (0-shot)pass@127.4 %
CodeMBPP (3-shot)pass@131.0 %
MathGSM8k (0-shot)exact match4.55 %
KnowledgeWikitext-2perplexity ↓167.6
ReasoningARC (Easy/Challenge)acc norm34.6 / 22.8 %
CommonsenseHellaSwagacc norm28.3 %
humaneval/mbpp were computed with manual evaluation (max_new_tokens=512, temp=0.2) due to SFT format truncation issues in lm-eval.

⚠️ Known Limitations

  1. 1.Code-Specialized Model Tuned for Python and algorithmic reasoning. Poor performance on general text, math, and commonsense tasks.
  1. 1.Short Context Trained on 1 024-token sequences only. Performance degrades on longer inputs.
  1. 1.Tokenizer Bias Uses bigcode/starcoder BPE vocabulary β€” optimized for code, not prose.

πŸ’» Usage Example

python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "Beebey/smallcoder-303m"
device = "cuda" if torch.cuda.is_available() else "cpu"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16).to(device)

prompt = """User: Write a Python function to compute Fibonacci numbers.
Assistant:"""
inputs = tokenizer(prompt, return_tensors="pt").to(device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=512,
        eos_token_id=tokenizer.eos_token_id,
        pad_token_id=tokenizer.eos_token_id,
    )

print(tokenizer.decode(outputs[0], skip_special_tokens=True))

πŸ’‘ Trained using the β€œUser:” / β€œAssistant:” dialogue format.


🧾 Citation

If you use SmallCoder (303M) in your research, please cite:

@misc{smallcoder303m,
  title  = {SmallCoder: A 303M-parameter Code LLM trained from scratch},
  author = {Da Silva, Ilan},
  year   = {2025},
  url    = {https://huggingface.co/Beebey/smallcoder-303m},
  note   = {Trained with Google TPU Research Cloud (TRC) support}
}

πŸ™ Acknowledgements

This model was trained with support from the Google TPU Research Cloud (TRC) program. Special thanks to the open datasets that enabled this work: FineWeb, StarCoderData, Nemotron, and OpenWebMath.


🧩 Summary

CategoryDescription
TypeCode LLM (LLaMA-style)
Parameters303 M
Training tokens~29.8 B
SpecialtyCode generation & reasoning
Context window1 024 tokens
Tokenizerbigcode/starcoder
LicenseApache 2.0
HardwareTPU v4 (TRC Program)

πŸ”¬ SmallCoder (303M) demonstrates that a carefully designed <500M model can achieve near-SOTA coding performance, matching 1B-class models on HumanEval β€” proving that efficient, compact, open models still matter.