Files
GemCod-Sapphire-270M-XM/README.md
ModelHub XC bfbc6ae7d0 初始化项目,由ModelHub XC社区提供模型
Model: DireDreadlord/GemCod-Sapphire-270M-XM
Source: Original Platform
2026-06-11 05:00:19 +08:00

3.5 KiB

license, datasets, language, base_model, pipeline_tag, tags
license datasets language base_model pipeline_tag tags
gemma
nphearum/Code-Reasoning-4k
en
google/gemma-3-270m-it
text-generation
text-generation-inference
code
gemma
SLM

GemCod270M - Sapphire - XM (gemma-270m-it-code-reasoning v1.1.0 experimental)

GemCod logo

GemCod is a lightweight code generation model finetuned using SFT on the base gemma-270m-it model(https://huggingface.co/google/gemma-3-270m-it). It offers accurate and quick(ish) code snippet and long-form code generation in all major programming languages. It's small size (270M parameters) allows it to run comfortably on laptop grade GPUs.

The Sapphire model represents the next generation of GemCod agents by integrating COT(Chain Of Thought) reasoning capabilities into the standard coding architecture. This almost completely removes the chances of hallucination and allows the model to give highly detailed and specialized explanations and instructions along with its generations.

It serves as an upgrade from the previous GemCod-Jade-270M model found here (https://huggingface.co/DireDreadlord/GemCod-Jade-270M) whilst only having minor bloat to inference time and space requirements. This model also offers rudimentary Q/A and subject matter expert capabilities on code related subjects.

This is the XM(Experimental) variant of the model which is trained on only 2,000 steps on SFT; it may give slightly incorrect outputs on long-form generation.


Estimated parameters: ~270M

Architecture: Gemma3

Intended use: Code snippet and long-form generations from natural language, instruction generation and COT explanations on code snippets


Training data

Usage

Install requirements:

pip install -r requirements.txt
pip install transformers datasets accelerate safetensors

Usage (Hugging Face Hub)

You can load it directly from HuggingFace:

from transformers import AutoTokenizer, AutoModelForCausalLM


tokenizer = AutoTokenizer.from_pretrained("DireDreadlord/GemCod-Sapphire-270M-XM")
model = AutoModelForCausalLM.from_pretrained("DireDreadlord/GemCod-Sapphire-270M-XM")
model.to(device)
model.eval()
model.resize_token_embeddings(len(tokenizer))


user_prompt = (
    "write a bubble sort algorithm in cpp."
    "Please think step by step and show your chain-of-thought before the final code." #<-- comment out this line to disable COT
)

messages = [{"role": "user", "content": user_prompt}]


inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}


with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=1024,
        do_sample=False,
        num_beams=1,
        pad_token_id=tokenizer.eos_token_id,
        eos_token_id=tokenizer.eos_token_id,
        use_cache=False,
    )


prompt_len = inputs["input_ids"].shape[1]
generated_ids = outputs[0, prompt_len:]
print(tokenizer.decode(generated_ids.tolist(), skip_special_tokens=True))

For optimal long-form generation along with COT, set max_new_tokens=2048

Limitations

  • Model for experimental use only; users should employ it as such under license.