This model is fine-tuned from gemma-2-2b-it using a thinking dataset meticulously crafted by our team, aiming to enhance the model's ability to solve complex, sequential problems through step-by-step logical thinking.
Reasoning is a cornerstone of effective problem-solving, yet many of the models trained for this task are quite large and too heavy for everyday usage, particularly when their extra long responses considered. To address this, we developed a reasoning-focused compact language model (LLM) capable of structured thinking, self-reflection, and iterative problem-solving. Our goal is to create a model that not only excels in reasoning tasks but also operates efficiently for broader accessibility.
1
2from unsloth import FastLanguageModel
3import torch
4from transformers import TextStreamer
5
6
7max_seq_length = 3072
8dtype = None
9load_in_4bit = False
10lora_path = "/altaidevorg/gemma-altai-2-2b-reasoning"
11use_streamer = False
12
13model, tokenizer = FastLanguageModel.from_pretrained(
14 model_name=lora_path,
15 max_seq_length=max_seq_length,
16 dtype=dtype,
17 load_in_4bit=load_in_4bit,
18)
19FastLanguageModel.for_inference(model)
20
21text_streamer = TextStreamer(tokenizer, skip_prompt = True)
22)
23
24messages = [
25 {"role": "user", "content": user_prompt},
26]
27
28
29input_ids = tokenizer.apply_chat_template(
30 messages,
31 tokenize = True,
32 add_generation_prompt = True,
33 return_tensors = "pt",
34).cuda()
35
36terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<end_of_turn>")]
37
38outputs = model.generate(input_ids = input_ids,
39 streamer = text_streamer if use_streamer else None,
40 max_new_tokens = 1024,
41 eos_token_id=terminators,
42 use_cache=True, do_sample=True, temperature=0.6, top_p=0.9)
43if not use_streamer:
44 out = outputs[0][input_ids.shape[-1]:]
45 generated_text = tokenizer.decode(out, skip_special_tokens=True)
46 print(generated_text)
47
48
The dataset was prepared through a comprehensive process based on our open-source reasoning and thinking dataset collection method. We curated and refined existing open-source datasets focusing on logical reasoning, critical thinking, and problem-solving. These datasets were preprocessed and structured for fine-tuning large language models to ensure high-quality outputs.
The dataset will be made publicly available through its dedicated repository
altaidevorg/thinking-dataset-en.