Views
No views yet
train_on_prompt set to True.1<|im_start|>system
2{{system_message}}<|im_end|>
3<|im_start|>user<|im_start|>system
You are an AI coding assistant.<|im_end|>
<|im_start|>userHey, can you help me write a simple program that generates a Fibonacci sequence until a certain number of terms? Like this: Fib(5) should give me the first five numbers in the series.1import torch
2from unsloth import FastLanguageModel
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 "trollek/LittleInstructionMaker-4B-v0.1",
6 dtype=torch.bfloat16,
7 load_in_4bit=True,
8 max_seq_length=8192
9)
10FastLanguageModel.for_inference(model)
11
12def instruction_generator(system_message: str, num_instructions: int):
13 if system_message is None or "":
14 raise ValueError
15 if num_instructions < 1:
16 raise ValueError
17 magpie_template = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n"
18 input_ids = tokenizer(magpie_template, return_tensors="pt").input_ids.to("cuda")
19 for idx in range(num_instructions):
20 generated_ids = model.generate(input_ids, max_new_tokens=512, temperature=0.9, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
21 response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)
22 yield response
23
24for instruct in instruction_generator("You are an AI coding assistant.", 2):
25 print(instruct)
26
27# Can you help me write a simple programming language syntax?
28# I want to create a Python program for a social media app that allows users to post and comment on stories. The message I want to convey is that staying connected with others is essential in life. Can you suggest a way to design the program?