> Canonical page: https://posttrainllm.com/articles/how-to-cook-an-llm

A garden-to-table journey

# How to cook an LLM.

Make a dinner assistant.
Three ingredients. No dairy.

 Goal: three-ingredient, dairy-free dinners. Read a sample. Keep it, or leave it. 10 minutes · Six stops · Your choices carry forward

 01 / HARVEST

## Pick your training text.

A model learns from the text you give it.
Read each sample, then decide what
belongs in your dinner assistant’s data.

[Explore all seven samples ↗](https://posttrainllm.com/articles/how-to-cook-an-llm#ingredients)

 Choose examples for your dinner assistant’s training data 01 / Recipe note + Rice, beans and tomatoes Cook rice, warm beans, and add chopped tomatoes. A three-ingredient dinner without dairy. Dinner recipe Add to basket 02 / Recipe note + Creamy rice with cheese Cook rice with butter, then stir in cheese. A creamy three-ingredient dinner. Dinner recipe Add to basket 03 / Forecast + Tomorrow’s forecast Tomorrow: sunny, 24°C, with a light breeze. Rain is expected on Friday. Weather report Add to basket

 IN THE GARDEN / GATHER INGREDIENTS IN THE MODEL / SELECT TRAINING DATA

 Your basket / selected data

 Your basket is empty. Pick a sample above.

You’re choosing data. No model weights have changed.

[To the cutting board ↗](https://posttrainllm.com/articles/how-to-cook-an-llm#ingredients)

Real data preparation · Real local training · Talk to your cooked model

[← Back](https://posttrainllm.com/articles/how-to-cook-an-llm#welcome) Choose a scene [Next →](https://posttrainllm.com/articles/how-to-cook-an-llm#ingredients)

01 / In the garden

## Find your ingredients.

 Kitchen / harvest what you need

 Model / gather training data

A model’s ingredients are text. Walk through the available sources and choose what belongs in your basket.

You’re collecting material. No weights have changed.

You’re making a three-ingredient dinner without dairy: rice, beans, and tomatoes. You don’t begin with the stove. You begin by finding ingredients that can make the dish you want.

Model-building starts the same way. You gather explanations, conversations, code, or other material from relevant sources. What you pick shapes what the model will have a chance to learn. These small, handwritten samples are our teaching harvest.

Your first decision

### What goes in your basket?

 Choose which text samples to keep Rice, beans and tomatoes Cook rice, warm beans, and add chopped tomatoes. A three-ingredient dinner without dairy. Another recipe note Cook rice, warm beans, and add chopped tomatoes. A three-ingredient dinner without dairy. An imported recipe note Dinner[NUL][replacement character] A dinner conversation User: Suggest a three-ingredient dinner without dairy.
Assistant: Make a bowl with rice, beans, and tomatoes. Cook, warm, and combine. A recipe in code ingredients = ["rice", "beans", "tomatoes"]
assert len(ingredients) == 3 Creamy rice with cheese Cook rice with butter, then stir in cheese. A creamy three-ingredient dinner. Tomorrow’s forecast Tomorrow: sunny, 24°C, with a light breeze. Rain is expected on Friday.

Your basket: empty. Nothing has been cleaned or trained yet.

Read the samples before deciding. The sink removes exact repeats and malformed text. A recipe with cheese or an unrelated forecast can still be structurally clean; choosing relevant material is your decision.

[Take your basket inside Next: the cutting board →](https://posttrainllm.com/articles/how-to-cook-an-llm#chopping)

02 / At the cutting board

## Turn text into workable pieces.

 Kitchen / cut and portion

 Model / inspect preprocessing & tokens

A model processes token IDs. See how a sentence becomes smaller units it can work with.

You’re changing the representation. The model stays unchanged.

Put a sentence on the board. In our tiny trainer, cutting it into model inputs means encoding its UTF-8 bytes. Larger LLMs often use subword pieces instead. The knife is a way to understand tokenization, not how every tokenizer literally works.

Try the knife / real byte tokenization

 Put some text on the cutting board Cut into tokens →

A preview of the tool, not a prepared training batch. Try “café” to see one character occupy multiple bytes.

We’re inspecting tokenization before preparing the full harvest. In the actual data pipeline, clean the source text first, then encode the finished batch. That is what we’ll do at the next stop.

[The pieces still need checking Next: wash and sort →](https://posttrainllm.com/articles/how-to-cook-an-llm#cleaning)

03 / At the sink

## Wash and sort your batch.

 Kitchen / wash, trim, and sort

 Model / clean, deduplicate, encode

Inspect the harvest. Remove exact repeats and deliberately broken samples, then tokenize what remains.

The batch is becoming usable. Only the data changes.

Now your earlier choices matter. Did you pick the same sample twice? Did a broken one slip into the basket? Clean the text before the final encoding and inspect what survives.

At the sink / real data preparation

### Wash, sort, and check your batch.

 Prepare selected text →

What changed? Nothing yet. Model weights unchanged.

 Under the hood: prepared text & actual tokens

```
Choose your text, then prepare a batch.
```

```
No batch prepared yet.
```

This trainer uses one token per UTF-8 byte, with a vocabulary of 256. “Rice” → [82, 105, 99, 101]. Non-ASCII characters can take several bytes. Larger LLMs commonly use subword tokenizers.

 Open this batch in the trainer → Download text

Handwritten teaching samples, not a production dataset. The trainer will offer an import; it won’t start training automatically. A tiny batch shows the mechanism, not general assistant capability.

You have ingredients ready for cooking. You still don’t have a trained model.

[Carry the prepared batch to the stove Next: start cooking →](https://posttrainllm.com/articles/how-to-cook-an-llm#base-recipe)

04 / At the stove

## Start cooking the base recipe.

 Kitchen / cook, check, adjust

 Model / pre-training

Predict the next token. Compare with the text’s actual next token. Use the error to guide a weight update.

Cook trains on your batch. Your model’s weights change here.

Chopping wasn’t cooking. Washing wasn’t cooking. Pre-training is the cooking: repeated practice develops the foundation. A generative model commonly learns by predicting the next token in a sequence.

Your batch → your weights

### Turn on the heat.

Train on your batch, right here in your browser.

 Training steps 0 / 256 Prediction loss —

 Cook my model → Turn off the heat Keep cooking · 256 steps

Prepare your ingredients at the sink first. Nothing trains automatically.

 What is in the pot?

```
No prepared batch yet.
```

One transformer layer, byte tokens, existing WASM trainer. Up to 256 optimizer steps per click, with a 30-second stop. This small recipe teaches training; it does not create a general assistant.

A real optimizer repeats this cycle across many batches. Lower training loss is a signal about the objective, not a guarantee of usefulness. Set aside evaluation data to test whether the learning carries beyond the training examples.

 What the processes share: repeated trials can change the recipe. The difference is that a model learns numerical weights through an objective; it isn’t a cook understanding the dish.

[The foundation is cooked. Make it fit the brief. Next: taste, refine, and serve →](https://posttrainllm.com/articles/how-to-cook-an-llm#refine)

05 / At the tasting and serving table

## Refine it. Then serve it.

 Kitchen / refine, plate, garnish, serve

 Model / post-training, then inference

Worked examples and tasting feedback guide further training. A new order then uses the resulting model.

Refining can change weights. Plating and serving do not.

You’ve developed a base recipe, but the brief is specific: three ingredients, no dairy, a short answer. Learn from a worked example, taste two versions, and revise toward that brief. That is the post-training part of our journey.

### First, learn from a worked recipe.

Supervised fine-tuning continues training on demonstrations of the desired response. Like practicing a particular recipe, it teaches the result you want to serve. With LoRA, that update can be carried in adapter weights while the base stays frozen.

Illustrative checkpoints

> Suggest a three-ingredient dinner without dairy. Keep the answer brief.

Authored teaching outputs. No model was trained here.

 Base model After SFT After preference training

 Kitchen

Develop the base recipe

 Model

Pre-training

Three ingredients for dinner. Dinner is a meal often served in the evening…

 Inspect the example or training objective

```
Raw text → predict the next token → update weights. A base model may continue text rather than follow an instruction.
```

Real run: Weights during pre-training. Here: illustrative output only.

### Then taste two versions.

The tasting table gives you a comparison. Choosing an answer records a preference; a separate optimization step uses it to change trainable weights. Both SFT and preference optimization belong within post-training.

Your turn / become the taste tester

### Which meets the brief?

Suggest a three-ingredient dinner without dairy. Keep the answer brief.

 Response A Make creamy rice with cheese and beans. Prefer this response Response B Rice, beans, tomatoes: cook, warm, and combine. Dairy-free. Prefer this response

No preference collected. Model weights unchanged.

 Your preference tray / collected data

```
Your tray is empty. Choose a response to collect a preference pair.
```

 Simulate training → Export pair Reset

Illustration only / no model optimized

Pair collected → Optimization step → Candidate weights → Held-out evaluation

DPO can optimize on preference pairs directly. RLHF can first fit a reward model and use it during reinforcement learning. This is a conceptual illustration of the separation, not a numerical simulation of either algorithm.

### Finally, plate, garnish, and serve.

A finished recipe can fulfil another order without being rewritten. That is ordinary inference: fixed weights, a new prompt, a new response. Garnish is presentation—it can make an answer easier to read, but presentation alone isn’t post-training.

A last distinction / same answer, different presentation

```
Rice, beans, tomatoes: cook, warm, and combine. Dairy-free.
```

 Add a heading / garnish the answer

Illustrative answer, not live generation. Model weights unchanged.

Gather. Prepare. Cook. Refine. Serve. Now you know which steps change data, weights, or the answer’s presentation.

[Your model is ready at the table Take an order →](https://posttrainllm.com/articles/how-to-cook-an-llm#chat)

Take your harvest into the real lab

### Your next dish can be a real run.

Return to your prepared batch and offer it to the existing browser trainer. It demonstrates tiny next-token training from scratch, not the SFT or preference scenes above.

[Return to your batch ↑](https://posttrainllm.com/articles/how-to-cook-an-llm#cleaning)[Explore the trainer →](https://posttrainllm.com/playground)[Real post-training on a Mac →](https://posttrainllm.com/fine-tune-llm-on-mac)

06 / Dinner is served

## Meet the model you cooked.

 Kitchen / taste your own dish

 Model / your trained weights

Start a sentence. Your model predicts what comes next using what it learned from your batch.

Same model. Same weights. No pretrained assistant behind the curtain.

 Your kitchen model Not cooked yet

This is a tiny byte-level text generator. Short training may produce fragments or nonsense; more practice can lower training loss without proving useful generalization. Its weights stay in this tab until you download them or leave the page.

[Back to the stove →](https://posttrainllm.com/articles/how-to-cook-an-llm#base-recipe) Take my model home ↓

Cook your batch first, then try the model here.

Your own model will be served here.

 What is running?

The same isolated WASM worker trained at the stove generates 48 new byte tokens. No external model downloads, no system prompt, and no canned replies. Download exports the trainer’s .tinygpt format for the Web Lab. Your existing saved Web Lab model is untouched. Changing ingredients does not silently retrain or replace this model.

[Explore a bigger recipe Open the browser trainer →](https://posttrainllm.com/playground)

## Read the technical sources.

The kitchen is a metaphor. These sources explain the mechanisms.

- [Hugging Face: pre-training and fine-tuning](https://huggingface.co/learn/llm-course/chapter1/4)
- [InstructGPT: demonstrations, preferences, and RLHF](https://arxiv.org/abs/2203.02155)
- [Direct Preference Optimization](https://arxiv.org/abs/2305.18290)
- [Lesson notes and trainer integration contract](https://posttrainllm.com/docs/learn/llm-kitchen/)
- [Continue with the hands-on learning paths](https://posttrainllm.com/learn)
