Views
No views yet
kld, mse and tvd objectives, distilled from a model trained for 1M steps.sm, md, large, distilled from models trained for 400k steps.sm, md, large, before any distillation.1git clone https://github.com/jdeschena/sdtt.git
2cd sdtt
3pip install -r requirements.txt
4pip install flash-attn
5pip install --pre torchdata --index-url https://download.pytorch.org/whl/nightly/cpu
6pip install -e .1from sdtt import load_small_student
2student = load_small_student(loss="kld", round=7) # load the kld student after the last distillation round
3student = load_small_student(loss="mse", round=2) # load the mse student after the second distillation round
4student = load_small_student(loss="tvd", round=1) # load the tvd student after the first distillation round1from sdtt import load_scaling_student
2student = load_scaling_student(size="sm", round=7) # load small student after the last distillation round
3student = load_scaling_student(size="md", round=1) # load medium student after the first distillation round
4student = load_scaling_student(size="large", round=3) # load large student after the third distillation round1from sdtt import load_scaling_teacher
2student = load_scaling_student(size="sm",) # load small teacher
3student = load_scaling_student(size="md",) # load medium teacher
4student = load_scaling_student(size="large",) # load large teacher1from sdtt import load_small_student, load_scaling_student, load_scaling_teacher
2import torch
3
4model = load_small_student(loss="kld", round=7) # load model, see above
5model.cuda() # put model on gpu
6
7# Unconditional generation
8tokens = model.sample(
9 n_samples=8,
10 num_steps=256,
11 seq_len=1024,
12 verbose=True,
13)
14# Detokenize
15uncond_text = model.tokenizer.batch_decode(tokens)
16
17# Conditional generation, based on a prompt
18# Prepare a prompt
19prompt = "Today is a great day. The sun is shining,"
20prompt_tokens = model.tokenizer(prompt)["input_ids"]
21prompt_tokens.insert(0, model.tokenizer.bos_token_id)
22prompt_tokens = torch.tensor(prompt_tokens, device="cuda")
23prompt_len = len(prompt_tokens)
24
25def project_fn(x):
26 # Project the first 10 tokens of all examples to the prompt
27 x[:, :prompt_len] = prompt_tokens
28 return x # Don't forget to return
29
30tokens = model.sample(
31 n_samples=8,
32 num_steps=256,
33 seq_len=1024,
34 verbose=True,
35 project_fn=project_fn
36)
37
38cond_text = model.tokenizer.batch_decode(tokens)@article{deschenaux2024autoregressionfastllmsselfdistillation,
title={Beyond Autoregression: Fast LLMs via Self-Distillation Through Time},
author={Deschenaux, Justin and Gulcehre, Caglar}
eprint={2410.21035},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2410.21035},
}