markdown · 2774 bytes Raw Blame History

Coding tutor

Build a programming Q&A model that answers questions in your team's voice. Roughly 5 minutes of edit-train-prompt iteration.

Goal

A .dlm trained on instruction Q&A pairs that explains Python concepts using your house style and idioms.

Starter template

Copy templates/coding-tutor.dlm from the repo, or start from scratch:

---
# dlm_id is minted by `dlm init` (Crockford base32, no I/L/O/U).
# The value below is illustrative only; `dlm init` generates a fresh one.
dlm_id: 01KPM618S78XK668EX0TFEWAJY
base_model: qwen2.5-coder-1.5b
system_prompt: |
  You are a Python tutor. Be precise. Prefer simple examples.
training:
  lora_r: 16
  learning_rate: 2e-4
  num_epochs: 3
export:
  default_quant: Q4_K_M
  default_temperature: 0.2
---

# Python coding tutor

::instruction::
### Q
What is a decorator in Python?

### A
A decorator is a function that takes a function and returns a new
function. The `@decorator_name` syntax above `def foo(): ...` is
equivalent to writing `foo = decorator_name(foo)`.

### Q
When should I use `functools.wraps` inside a decorator?

### A
Always. Without it, the wrapped function loses its `__name__`,
`__doc__`, and `__wrapped__` — introspection and debugging get
confused, and Sphinx / mkdocstrings can't find the real docstring.

Walk-through

# Create the document
$ uv run dlm init tutor.dlm --base qwen2.5-coder-1.5b

# Paste the Q&A above into tutor.dlm

# Train
$ uv run dlm train tutor.dlm --max-steps 50
trained: v0001 (50 steps, seed=42, determinism=strict)
adapter: ~/.dlm/store/01HRCJ…/adapter/versions/v0001
log:     ~/.dlm/store/01HRCJ…/logs/train-000001-…jsonl

# Smoke-test via HF inference
$ uv run dlm prompt tutor.dlm "Explain closures in one sentence."
A closure is an inner function that captures variables from its
enclosing scope so those variables stay alive after the outer call
returns.

# Ship to Ollama
$ uv run dlm export tutor.dlm --name coding-tutor
exported: ~/.dlm/store/01HRCJ…/exports/Q4_K_M
ollama:  coding-tutor (v1)

# Use it
$ ollama run coding-tutor "When should I use list vs tuple?"
Lists are mutable — use them when the sequence changes. Tuples are
immutable — use them for fixed records or dict keys.

What to add over time

Every week, paste new Q&A pairs under ::instruction:: and run dlm train tutor.dlm again. The delta system (Sprint 08) notices what changed; prior content stays in the replay corpus so the model doesn't forget the earlier material.

For code-heavy answers, put the explanation as prose and use ::instruction:: for conversational questions. Both train, but prose drives continued pretraining (learns style) while instruction drives supervised fine-tuning (learns the question → answer mapping).

View source
1 # Coding tutor
2
3 Build a programming Q&A model that answers questions in your team's
4 voice. Roughly 5 minutes of edit-train-prompt iteration.
5
6 ## Goal
7
8 A `.dlm` trained on instruction Q&A pairs that explains Python
9 concepts using your house style and idioms.
10
11 ## Starter template
12
13 Copy `templates/coding-tutor.dlm` from the repo, or start from
14 scratch:
15
16 ```dlm
17 ---
18 # dlm_id is minted by `dlm init` (Crockford base32, no I/L/O/U).
19 # The value below is illustrative only; `dlm init` generates a fresh one.
20 dlm_id: 01KPM618S78XK668EX0TFEWAJY
21 base_model: qwen2.5-coder-1.5b
22 system_prompt: |
23 You are a Python tutor. Be precise. Prefer simple examples.
24 training:
25 lora_r: 16
26 learning_rate: 2e-4
27 num_epochs: 3
28 export:
29 default_quant: Q4_K_M
30 default_temperature: 0.2
31 ---
32
33 # Python coding tutor
34
35 ::instruction::
36 ### Q
37 What is a decorator in Python?
38
39 ### A
40 A decorator is a function that takes a function and returns a new
41 function. The `@decorator_name` syntax above `def foo(): ...` is
42 equivalent to writing `foo = decorator_name(foo)`.
43
44 ### Q
45 When should I use `functools.wraps` inside a decorator?
46
47 ### A
48 Always. Without it, the wrapped function loses its `__name__`,
49 `__doc__`, and `__wrapped__` — introspection and debugging get
50 confused, and Sphinx / mkdocstrings can't find the real docstring.
51 ```
52
53 ## Walk-through
54
55 ```sh
56 # Create the document
57 $ uv run dlm init tutor.dlm --base qwen2.5-coder-1.5b
58
59 # Paste the Q&A above into tutor.dlm
60
61 # Train
62 $ uv run dlm train tutor.dlm --max-steps 50
63 trained: v0001 (50 steps, seed=42, determinism=strict)
64 adapter: ~/.dlm/store/01HRCJ…/adapter/versions/v0001
65 log: ~/.dlm/store/01HRCJ…/logs/train-000001-…jsonl
66
67 # Smoke-test via HF inference
68 $ uv run dlm prompt tutor.dlm "Explain closures in one sentence."
69 A closure is an inner function that captures variables from its
70 enclosing scope so those variables stay alive after the outer call
71 returns.
72
73 # Ship to Ollama
74 $ uv run dlm export tutor.dlm --name coding-tutor
75 exported: ~/.dlm/store/01HRCJ…/exports/Q4_K_M
76 ollama: coding-tutor (v1)
77
78 # Use it
79 $ ollama run coding-tutor "When should I use list vs tuple?"
80 Lists are mutable — use them when the sequence changes. Tuples are
81 immutable — use them for fixed records or dict keys.
82 ```
83
84 ## What to add over time
85
86 Every week, paste new Q&A pairs under `::instruction::` and run
87 `dlm train tutor.dlm` again. The delta system (Sprint 08) notices what
88 changed; prior content stays in the replay corpus so the model doesn't
89 forget the earlier material.
90
91 For code-heavy answers, put the explanation as prose and use
92 `::instruction::` for conversational questions. Both train, but prose
93 drives continued pretraining (learns style) while instruction drives
94 supervised fine-tuning (learns the question → answer mapping).