Views
No views yet

LiquidAI/LFM2-1.2B on the HelpingAI/Intermediate-Thinking-130k dataset. The goal of this fine-tune is to enhance the model's ability to perform step-by-step reasoning and solve problems that require intermediate thought processes.unsloth library.1pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
2pip install --no-deps git+https://github.com/huggingface/transformers.git
3pip install --no-deps causal-conv1d==1.5.0.post81from unsloth import FastModel
2import torch
3from transformers import TextStreamer
4
5model_repo_id = "kreasof-ai/Liquid-Thinking-Preview"
6
7model, tokenizer = FastModel.from_pretrained(
8 model_name = model_repo_id,
9 dtype = None, # None for auto detection
10 load_in_4bit = True, # Use 4bit quantization for faster inference
11)
12
13# Define the conversation
14messages = [{
15 "role": "user",
16 "content": "Explain the step-by-step process of photosynthesis in simple terms.",
17}]
18
19# Apply the chat template
20inputs = tokenizer.apply_chat_template(
21 messages,
22 add_generation_prompt = True, # Must add for generation
23 return_tensors = "pt",
24).to("cuda")
25
26# Set up the streamer for real-time output
27streamer = TextStreamer(tokenizer, skip_prompt = True)
28
29# Generate the response
30_ = model.generate(
31 **inputs,
32 max_new_tokens = 4096,
33 # Recommended generation parameters from LiquidAI
34 temperature = 0.3,
35 min_p = 0.15,
36 repetition_penalty = 1.05,
37 use_cache = True,
38 streamer = streamer,
39)HelpingAI/Intermediate-Thinking-130k dataset, consisting of instruction and output pairs, was formatted into a conversational format using the LFM2's chat template. The template follows this structure:<|im_start|>user
{instruction}<|im_end|>
<|im_start|>assistant
{output}<|im_end|>train_on_responses_only), encouraging the model to learn the desired output format and reasoning style without being penalized for the user's prompt.trl.SFTTrainer:| Hyperparameter | Value |
|---|---|
per_device_train_batch_size | 8 |
gradient_accumulation_steps | 4 |
Effective Batch Size | 32 |
num_train_epochs | 3 |
learning_rate | 4e-5 |
lr_scheduler_type | cosine |
warmup_ratio | 0.1 |
optim | adamw_torch |
weight_decay | 0.01 |
max_seq_length | 8192 |
seed | 3407 |
