Stage 2 - Instruction fine-tuning (SFT). Alpaca
(52k) +
Dolly 2.0 (15k) =
~67k examples. Loss is masked to
response tokens only; learning rate 5e-5 (10x lower
than pretraining).
This is a
custom torch.nn.Module, not a HuggingFace
PreTrainedModel, so it is
not
AutoModelForCausalLM-loadable. Load it via the bundled
model.py:
1# pip install torch transformers
2import torch
3from transformers import AutoTokenizer
4from model import load_model
5
6REPO = "achavan1211/minimind-instruct-135m"
7model, cfg = load_model("config.json", "model.pt", device="cpu") # files from this repo
8tok = AutoTokenizer.from_pretrained(REPO)
9
10PROMPT = ("Below is an instruction that describes a task. "
11 "Write a response that appropriately completes the request.\n\n"
12 "### Instruction:\n{instruction}\n\n### Response:\n")
13
14def ask(instruction, max_new_tokens=150):
15 p = PROMPT.format(instruction=instruction)
16 ids = tok.encode(p, return_tensors="pt")
17 out = model.generate(ids, max_new_tokens=max_new_tokens, temperature=0.7,
18 top_p=0.9, repetition_penalty=1.2,
19 eos_id=tok.eos_token_id, stop_on_eos=True)
20 return tok.decode(out[0], skip_special_tokens=True)[len(p):].strip()
21
22print(ask("What is the capital of France?"))
23# -> the capital of france is paris.
Because fine-tuning used Alpaca (research-use), this model is released under
CC-BY-NC-4.0 (non-commercial). See
LICENSE.