i want to train llama3-8B model on intel Xeon series CPUs specifications(cores, Gflops, cache, frequency, etc.)
I have prepared basic dataset for it, but it is not giving fruitful results. please suggest me how can I introduce such complex data to the model without RAG.
example of dataset row:
"<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Intel processors names are given as input, your task is to give output of Giga Flops(floating point operations), Core count, base Frequency, and Cache for the input processor.
The first two digits of the CPU name represents processor series(8-platinum, 6/5-Gold, 4-Silver, 3-Bronze) and processor generation 2nd,3rd 4th respectively.
<|eot_id|>
<|start_header_id|>user<|end_header_id|>
Intel Xeon Platinum 8368 Processor <|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
gigaflops for Intel Xeon Platinum 8368 Processor:1094.4, core_count for Intel Xeon Platinum 8368 Processor:38, base_frequency for Intel Xeon Platinum 8368 Processor:2.40 GHz, cache_size for Intel Xeon Platinum 8368 Processor:57M <|eot_id|>."
Here is the Finetuning Code using PEFT:
import torch
import pandas as pd
from trl import SFTTrainer
from sklearn.model_selection import train_test_split
from datasets import load_dataset, Dataset
from peft import (
LoraConfig,
get_peft_model)
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
TrainingArguments,
BitsAndBytesConfig,
DefaultDataCollator,
)
from torch.utils.data import DataLoader
import torch.nn as nn
import os
df = pd.read_csv("/sda/ak_cpu_prompt.csv")
# train_dataset, test_dataset = train_test_split(df,shuffle=True,test_size=0.1,random_state=42)
# training_data = Dataset.from_pandas(df=train_dataset)
# testing_data = Dataset.from_pandas(df=test_dataset)
training_data = Dataset.from_pandas(df=df)
training_data.set_format(
type="torch",
columns=["output"],
device="cuda",
)
pretrained_model = "/sda/llama3/Meta-Llama-3-8B-Instruct-hf"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
print("n....Loading model...")
model = AutoModelForCausalLM.from_pretrained(
pretrained_model,
quantization_config=bnb_config, ###
device_map='auto')
# model.config.pretrainig_tp = 1 # For Faster responses, trading off accuracy
print("....Loading model complete...n")
tokenizer = AutoTokenizer.from_pretrained(pretrained_model,padding_side='left')
tokenizer.pad_token = tokenizer.eos_token
# tokenizer.padding_side = "right"
print("...preparing Training arguments...")
#tokenizer.add_special_tokens({'pad_token': '[PAD]'})
training_arg_instance = TrainingArguments(
output_dir="/sda/llama3/llama_3_adapters/cpu_model-0.1", # change here
per_device_train_batch_size=4,
gradient_accumulation_steps=1,
prediction_loss_only=True,
gradient_checkpointing=False,
# evaluation_strategy="steps", # no evaluation dataset
do_eval=False, # no evaluation dataset
max_grad_norm=0.3,
fp16=True,
bf16=False,
optim="paged_adamw_32bit",
logging_steps=10,
learning_rate=2e-5,
warmup_ratio=0.0,
lr_scheduler_type="cosine",
num_train_epochs=1, # changing for every model
save_strategy="epoch",
)
print("...preparing Training arguments. Done....n")
print("...preparing lora config...")
loracofig_instance = LoraConfig(
task_type="CAUSAL_LM",
inference_mode=False,
r=16,
use_rslora=True,
lora_alpha=32,
#lora_dropout=0.01,
lora_dropout=0.05
)
print("...preparing lora config. Done...n")
print("...intializing SFT trainer...")
model = get_peft_model(model, loracofig_instance)
#device = [0,1]
#model = get_peft_model(model, loracofig_instance).to(device)
SFT_instance = SFTTrainer(
model=model,
train_dataset=training_data,
# eval_dataset=testing_data,
dataset_text_field="output",
max_seq_length=2048,
tokenizer=tokenizer,
args=training_arg_instance,
dataset_batch_size=1,
neftune_noise_alpha=3,
# data_collator=DefaultDataCollator,
packing=True,
#peft_config=loracofig_instance, # passed in the model
)
print("...intializing SFT trainer. Done...n")
model.resize_token_embeddings(len(tokenizer))
trainer = SFT_instance
print("nStarted training...n")
trainer.train()
trainer.save_model()
print("nTraining Comleted, Model saved at : /sda/llama3/llama_3_adapters/cpu_model-0.1") # change here
I have trained on 1-20 epochs, giving loss from 1.1 to 0.35, but the model doesn’t seem to learn the exact values.