Instructions to use eivintobias/heartly-qwen-code with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eivintobias/heartly-qwen-code with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="eivintobias/heartly-qwen-code") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("eivintobias/heartly-qwen-code") model = AutoModelForCausalLM.from_pretrained("eivintobias/heartly-qwen-code", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use eivintobias/heartly-qwen-code with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "eivintobias/heartly-qwen-code" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eivintobias/heartly-qwen-code", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/eivintobias/heartly-qwen-code
- SGLang
How to use eivintobias/heartly-qwen-code 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 "eivintobias/heartly-qwen-code" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eivintobias/heartly-qwen-code", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "eivintobias/heartly-qwen-code" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eivintobias/heartly-qwen-code", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use eivintobias/heartly-qwen-code with Docker Model Runner:
docker model run hf.co/eivintobias/heartly-qwen-code
Heartly Qwen-Code v3
A 1.5B coding LLM with the Heartly hallucination-reduction architecture,
fine-tuned from Qwen2.5-Coder-1.5B with the conversational Stage-5 SFT recipe
(Fix1–4: natural phrasing, single refusal, persona — 5,200 samples in
heartly-qwen-code/sft_dataset_code_v3.jsonl).
v3 builds on the same v1/v2 Stage 1–4 numbers (grammar adoption 100%, boundary-head
AUROC 1.000, critic AUROC 1.000) — same Qwen2.5-Coder-1.5B base, now trained for
multi-turn conversational code chat. See HF_MODEL_CARD.md for
the Stage 1–2 probe/critic results carried over from the identical architecture.
Output grammar
thinking [reasoning] response<decide>speak|stop</decide><verify>known|unknown</verify> [answer] <stop>
Only [answer] should reach the user.
Usage
0. Recommended — chat via the GitHub server (strips the grammar for you)
This model emits the Heartly grammar as ordinary multi-token text (the tags are
not tokenizer special tokens), so some front-ends (e.g. LM Studio) may decode
them mangled. The server.py FastAPI loader on GitHub loads this model and
runs every reply through reply_formatter.py, which canonicalises the tags
and returns only the clean answer.
pip install -r requirements.txt # fastapi + uvicorn + transformers + torch
python server.py --model eivintobias/heartly-qwen-code --port 8000
curl -X POST http://127.0.0.1:8000/chat \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a function that reverses a string"}'
Response: {"model":"eivintobias/heartly-qwen-code","raw":"...<decide>...","reply":"<clean answer>"}.
Quick browser test (no curl): open http://127.0.0.1:8000/ — server.py serves an
HTML chat UI at GET /. The first message lazy-loads the model; code answers render
with real line breaks, and the Heartly grammar is stripped by the reply formatter.
Quick offline test (no server): python chat_smoke.py "Write a function that sorts a list".
📦 Model card source: this file (HF_MODEL_CARD_v3.md). When uploaded to
HuggingFace, copy it to README.md on the hub repo.
1. Transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tok = AutoTokenizer.from_pretrained("eivintobias/heartly-qwen-code")
model = AutoModelForCausalLM.from_pretrained(
"eivintobias/heartly-qwen-code", torch_dtype=torch.float32, device_map="cpu"
)
model.eval()
ids = tok.encode("User: Write a function that reverses a string\nAssistant: ", return_tensors="pt")
out = model.generate(**ids, max_new_tokens=256, pad_token_id=tok.eos_token_id, do_sample=False)
raw = tok.decode(out[0][ids.shape[1]:], skip_special_tokens=False)
# Strip the grammar -> clean answer:
from reply_formatter import format_reply
print(format_reply(raw))
reply_formatter.py(grammar strip) andserver.pyare bundled in this repo (HF clone = flat layout; GitHub =heartly-qwen-code/). Clone it sofrom reply_formatter import format_replyresolves before the offline example.
Files in this repo
| File | Description |
|---|---|
config.json |
Qwen2ForCausalLM (28 layers, d=1536) + heartly_stop_token_id=9495 |
generation_config.json |
default generate params |
chat_template.jinja |
standard Qwen chat template |
tokenizer.json / tokenizer_config.json |
Qwen BPE tokenizer |
model.safetensors |
v3 fine-tuned weights (full fine-tune, not a LoRA adapter) |
server.py |
FastAPI server: lazy-loads the model; serves /, /health, /chat; strips Heartly grammar via reply_formatter |
reply_formatter.py |
strips thinking / <decide> / <verify> / <stop> -> clean answer; unescapes code newlines |
chat_smoke.py |
offline load + chat smoke test (no server) |
requirements.txt |
torch, transformers, fastapi, uvicorn, sentencepiece, datasets, scikit-learn, numpy, accelerate, huggingface_hub |
Training
- Base: Qwen/Qwen2.5-Coder-1.5B
- Method: full fine-tune (fp16), max-length 512, 2 epochs, freeze bottom 12 layers
- Dataset:
sft_dataset_code_v3.jsonl(5,200 conversational Heartly samples) - GPU: 1× RTX 3090 (24GB)
License
MIT — built on Qwen2.5-Coder (Apache 2.0).
Links
- Downloads last month
- 445