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 |
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = 'Mxode/NanoLM-25M-Instruct-v1.1'
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
40prompt1 = "What can you do for me?"
41print(get_response(prompt1, do_sample=False))
42
43"""
44I'm so glad you asked! I'm a large language model, so I don't have personal experiences or emotions, but I can provide information and assist with tasks to help with your tasks.
45
46Here are some ways I can assist you:
47
481. **Answer questions**: I can provide information on a wide range of topics, from science and history to entertainment and culture.
492. **Generate text**: I can create text based on a prompt or topic, and can even help with writing tasks such as proofreading and editing.
503. **Translate text**: I can translate text from one language to another, including popular languages such as Spanish, French, German, Chinese, and many more.
514. **Summarize content**: I can summarize long pieces of text, such as articles or documents, into shorter, more digestible versions.
525. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, books, or movies.
536. **Chat and converse**: I can engage in natural-sounding conversations, using context and understanding to respond to questions and statements.
547. **Play games**: I can play simple text-based games, such as 20 Questions, Hangman, or Word Jumble.
558. **Provide definitions**: I can define words and phrases, explaining their meanings and usage.
569. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, or books to read.
5710. **Entertain**: I can engage in fun conversations, tell jokes, and even create simple games or puzzles.
58
59Which of these methods would you like to do?
60"""