Instructions to use ilogic/NanoFairy23M-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ilogic/NanoFairy23M-Instruct with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf ilogic/NanoFairy23M-Instruct:F16 # Run inference directly in the terminal: llama cli -hf ilogic/NanoFairy23M-Instruct:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf ilogic/NanoFairy23M-Instruct:F16 # Run inference directly in the terminal: llama cli -hf ilogic/NanoFairy23M-Instruct:F16
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf ilogic/NanoFairy23M-Instruct:F16 # Run inference directly in the terminal: ./build/bin/llama cli -hf ilogic/NanoFairy23M-Instruct:F16
Use Docker
docker model run hf.co/ilogic/NanoFairy23M-Instruct:F16
- Llama new
- LM Studio
- Jan
- Ollama
How to use ilogic/NanoFairy23M-Instruct with Ollama:
ollama run hf.co/ilogic/NanoFairy23M-Instruct:F16
- Unsloth Desktop
- Docker Model Runner
How to use ilogic/NanoFairy23M-Instruct with Docker Model Runner:
docker model run hf.co/ilogic/NanoFairy23M-Instruct:F16
- Lemonade
How to use ilogic/NanoFairy23M-Instruct with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ilogic/NanoFairy23M-Instruct:F16
Run and chat with the model
lemonade run user.NanoFairy23M-Instruct-F16
List all available models
lemonade list
- Atomic Chat
NanoFairy23M-Instruct
NanoFairy23M-Instruct is a 23-million-parameter language model trained from scratch and then fine-tuned to hold short, in-character conversations. You give it a persona (a few first-person sentences such as "I love hiking. I have a cat named Pixel.") and it chats as that character.
It is a small hobby and learning project, designed to be cheap to train and to run on a CPU. It is not a general-purpose assistant. See Limitations before using it.
About the name. "Instruct" here means chat-tuned on persona dialogue. The model has not been trained to follow general instructions, answer factual questions, write code, or reason. It is trained to reply in character, in a casual conversational style.
Model details
| Architecture | Decoder-only transformer, GPT-2 design (GPT2LMHeadModel) |
| Parameters | 23,033,856 (about 12.3M of them are the embedding table) |
| Layers / heads / width | 6 / 6 / 384 (head size 64, MLP width 1,536) |
| Context length | 256 tokens (about 200 words, shared by persona, chat history and reply) |
| Vocabulary | 32,000, byte-level BPE, trained on the pretraining text |
| Position encoding | Learned absolute positions |
| Other | Pre-LayerNorm, exact GELU, tied input/output embeddings |
| Language | English |
| Weights | model.safetensors, float32 (about 92 MB) |
Intended use
- Very basic conversations.
- Learning and experimentation: a complete, small, readable example of pretraining and chat fine-tuning.
Not intended for: factual question answering, advice of any kind (medical, legal, financial), safety-critical use, or any setting where wrong or inappropriate output could cause harm.
How to use
The model expects this text format, which the bundled chat template produces for you. The system message becomes the persona:
Persona: My name is Ava. I love hiking and old movies. I have a cat named Pixel.
User: hi! how was your day?
Assistant: It was great, I went hiking with my cat.<|endoftext|>
User: a cat that hikes?
Assistant:
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "ilogic/NanoFairy23M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo)
messages = [
{"role": "system", "content": "My name is Ava. I love hiking and old movies. I have a cat named Pixel."},
{"role": "user", "content": "hi! how was your day?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt")
output = model.generate(
**inputs, max_new_tokens=60, do_sample=True, temperature=0.8, top_k=50,
pad_token_id=tokenizer.pad_token_id, eos_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip())
For a multi-turn chat, append the reply as an {"role": "assistant", ...} message, add the next user message, and repeat.
Tips for better results
- Write the persona as 3 to 5 short sentences in the first person ("I ..."), like the training data. You can include facts about the user ("My boyfriend's name is Sam.") so the character can mention them.
- Use temperature 0.7 to 0.9 and
top_karound 50. Lower is safer and more repetitive; higher is more varied and less coherent. - Keep conversations short. Persona, history and the reply together must fit in 256 tokens, so after a few turns the oldest messages have to be dropped and the model forgets them.
- Prompt it the way the training data looked: greetings, small talk and questions about the character's life, not about the world.
The weights are a standard GPT-2 checkpoint, so they also convert to GGUF for llama.cpp. The custom tokenizer needs a small workaround in llama.cpp's converter (it does not recognise the vocabulary's pre-tokenizer hash, and the GPT-2 setting is the correct one). Serve it with the bundled chat template (--jinja) and --ctx-size 256.
Training
Stage 1: pretraining
- Data: the first ~300M tokens of the
sample-10BTsubset of FineWeb (general web text), tokenized with the model's own 32k tokenizer, with<|endoftext|>between documents. - Run: one pass over the data, 36,758 steps of 32 sequences × 256 tokens (about 301M tokens seen).
- Optimiser: AdamW (β = 0.9, 0.95), weight decay 0.1 on weight matrices only, gradient clipping 1.0, peak learning rate 6e-4 decaying with a cosine schedule to 6e-5, 500 warmup steps, no dropout.
- Hardware: one NVIDIA T4, float16 mixed precision, about an hour of training.
- Result: final validation loss [TODO: fill in] (nats per token, on the model's own tokenizer, so not comparable to numbers from other tokenizers).
Stage 2: chat fine-tuning
- Data: PersonaChat (Zhang et al., 2018) in the true-cased version
bavard/personachat_truecased. In PersonaChat, two crowdworkers chat while one plays a character described by a few persona sentences. Every reply in every conversation became one training example (about 131,000 in total), laid out in the format shown above. Examples that did not fit in 256 tokens had their oldest turns dropped; the persona is always kept. - Loss masking: the model is trained only on the character's reply (and the
<|endoftext|>that ends it). The persona and the user's messages are context only, so the model learns to answer and not to write the user's side. - Run: starting from the pretrained weights, 2 epochs, 32 conversations per step, learning rate 1e-4 decaying to 1e-5 with 100 warmup steps, dropout 0.1. Validation loss was checked after every epoch and the best version was kept.
- Result: validation loss on character replies [TODO: before fine-tuning → after fine-tuning].
Limitations
- It is tiny. At 23M parameters and about 300M training tokens, it has learned conversational English and little else. It will state wrong "facts" confidently, contradict itself, repeat phrases and drift off topic after a sentence or two.
- Short memory. The 256-token context is shared by the persona, the chat history and the reply, so it can only keep a handful of turns in view.
- Persona drift. It follows the persona loosely, not reliably, and it may invent details about the character that conflict with it.
- No instruction following. It was never trained to follow instructions, only to continue a conversation in character. Commands and multi-step requests mostly confuse it.
- No safety training. The pretraining data is general web text, which is filtered but not clean, and the model has had no alignment or safety tuning. It can produce offensive, biased, sexual or otherwise inappropriate text, including when not prompted for it. Do not deploy it to children or vulnerable users without your own filtering and supervision.
- English only, and shaped by PersonaChat's style: casual, upbeat, and centred on hobbies, pets, jobs and family.
References
- Zhang et al. (2018). Personalizing Dialogue Agents: I have a dog, do you have pets too? ACL 2018. arXiv:1801.07243
- Penedo et al. (2024). The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scale. arXiv:2406.17557
- Radford et al. (2019). Language Models are Unsupervised Multitask Learners (the GPT-2 architecture).
- Downloads last month
- 33
16-bit