Views
No views yet
| Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
|---|---|---|---|---|---|---|
| 25M | 15M | MistralForCausalLM | 12 | 312 | 12 | 2K |
| 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 | 2K |
| 0.3B | 180M | Qwen2ForCausalLM | 12 | 896 | 14 | 4K |
| 1B | 840M | Qwen2ForCausalLM | 18 | 1536 | 12 | 4K |
| NanoLM-1B-Instruct-v2 | Tinyllama-1.1B | Gemma-2B | Qwen1.5-1.8B | Qwen2-1.5B | Qwen1.5-4B | Mistral-7B-v0.1 | Mistral-7B-v0.3 | Qwen1.5-7B | |
|---|---|---|---|---|---|---|---|---|---|
| GSM8K | 44.1 | 2.3 | 17.7 | 33.6 | 55.8 | 52.2 | 37.83 | 34.5 | 53.5 |
| MATH | 14.8 | 0.7 | 11.8 | 10.1 | 21.7 | 10.0 | 8.48 | - | 20.3 |
| BBH | 0.42 | 0.30 | 0.35 | 0.35 | 0.36 | 0.41 | 0.44 | 0.45 | 0.46 |
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = 'Mxode/NanoLM-1B-Instruct-v2'
5
6model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
7tokenizer = AutoTokenizer.from_pretrained(model_path)
8
9
10def get_response(prompt: str, **kwargs):
11 generation_args = dict(
12 max_new_tokens = kwargs.pop("max_new_tokens", 512),
13 do_sample = kwargs.pop("do_sample", True),
14 temperature = kwargs.pop("temperature", 0.7),
15 top_p = kwargs.pop("top_p", 0.8),
16 top_k = kwargs.pop("top_k", 40),
17 **kwargs
18 )
19
20 messages = [
21 {"role": "system", "content": "You are a helpful assistant."},
22 {"role": "user", "content": prompt}
23 ]
24 text = tokenizer.apply_chat_template(
25 messages,
26 tokenize=False,
27 add_generation_prompt=True
28 )
29 model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
30
31 generated_ids = model.generate(model_inputs.input_ids, **generation_args)
32 generated_ids = [
33 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
34 ]
35
36 response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
37 return response
38
39
40prompt = "Calculate (99 - 1) * (3 + 4)"
41print(get_response(prompt, do_sample=False))
42
43"""
44To calculate \((99 - 1) * (3 + 4)\), follow the order of operations, also known as PEMDAS (Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction).
45
46First, solve the expressions inside the parentheses:
47
481. \(99 - 1 = 98\)
492. \(3 + 4 = 7\)
50
51Now, multiply the results:
52
53\(98 * 7 = 686\)
54
55So, \((99 - 1) * (3 + 4) = 686\).
56"""