Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4tok = AutoTokenizer.from_pretrained("harims95/LoopLM-135M-naive-sft")
5model = AutoModelForCausalLM.from_pretrained(
6 "harims95/LoopLM-135M-naive-sft",
7 trust_remote_code=True,
8 torch_dtype=torch.bfloat16,
9).to("cuda")
10model.eval()
11
12def generate(instruction, max_new=120, temp=0.7, top_k=50, rep_penalty=1.3):
13 prompt = f"### Instruction:\n{instruction}\n\n### Response:\n"
14 ids = tok(prompt, return_tensors="pt").input_ids.to("cuda")
15 generated = []
16 response_token = tok.encode("### Response:", add_special_tokens=False)[0]
17
18 for _ in range(max_new):
19 with torch.no_grad():
20 out = model(ids[:, -1024:])
21 logits = out.logits[0, -1].float() / temp
22 for prev_id in set(generated[-20:]):
23 logits[prev_id] /= rep_penalty
24 if len(generated) > 5 and generated[-1] == response_token:
25 break
26 vals, _ = torch.topk(logits, top_k)
27 logits[logits < vals[-1]] = float('-inf')
28 nxt = torch.multinomial(torch.softmax(logits, dim=-1), 1).item()
29 if nxt == tok.eos_token_id:
30 break
31 generated.append(nxt)
32 ids = torch.cat([ids, torch.tensor([[nxt]]).to("cuda")], dim=1)
33
34 response = tok.decode(generated, skip_special_tokens=True)
35 if "###" in response:
36 response = response[:response.index("###")].strip()
37 return response
38
39print(generate("Give me 3 tips for learning Python."))| Base model | harims95/LoopLM-135M-naive (val 3.95 on FineWeb) |
| SFT dataset | tatsu-lab/alpaca (52,002 examples) |
| Epochs | 3 |
| Hardware | 1× H200 on Lightning AI |
| Training time | ~6 minutes |
| Optimizer | AdamW (lr=2e-5, cosine decay) |
| Precision | bf16 |
| Final SFT loss | ~3.0 (real loss, not Trainer display) |
The French capital of France is located in the city, where it was built.
Create Python with the code in it and create a loop to create a class project.
Write a response to a 10 year old.
### Instruction / ### Response structure) but does NOT reliably answer factual questions correctly. Expected limitations at this scale:| Model | Stage | Val Loss | Use case |
|---|---|---|---|
| LoopLM-135M-naive | Base pretrain | 3.95 (FineWeb) | Text continuation |
| LoopLM-135M-naive-sft (this) | SFT on Alpaca | ~3.0 (SFT loss) | Instruction format |
1git clone https://github.com/harims95/LoopLM
2cd LoopLM
3pip install transformers datasets accelerate huggingface_hub safetensors
4python sft.py