Views
No views yet
llama.cpp, LM Studio, Ollama, and text-generation-webui.ollama run welyjesch/filipino-llama-31Below is an instruction that describes a task. Write a response that appropriately completes the request.
2
3### Instruction:
4[Your Filipino instruction here]
5
6### Response:1Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
2
3### Instruction:
4[Your Filipino instruction here]
5
6### Input:
7[Optional context here]
8
9### Response:llama-cpp-python with hardware acceleration.1# 1. Install llama-cpp-python with CUDA (GPU) support
2!CMAKE_ARGS="-DGGML_CUDA=on" pip install llama-cpp-python
3!pip install huggingface_hub
4
5from huggingface_hub import hf_hub_download
6from llama_cpp import Llama
7
8# 2. Download the GGUF model from Hugging Face
9repo_id = "welyjesch/filipino_llama_3.1_FT_8B_GGUF"
10filename = "llama-3.1-8b-filipino-alpaca-q4_k_m.gguf"
11
12model_path = hf_hub_download(repo_id=repo_id, filename=filename)
13
14# 3. Load the model
15llm = Llama(
16 model_path=model_path,
17 n_gpu_layers=-1, # Offloads all layers to the GPU
18 n_ctx=2048, # Context window size
19 verbose=False
20)
21
22# 4. Run Inference using the Alpaca Prompt Format
23prompt = """Below is an instruction that describes a task. Write a response that appropriately completes the request.
24
25### Instruction:
26Kumusta ka ngayong araw? May maganda ka bang balita?
27
28### Response:
29"""
30
31output = llm(
32 prompt,
33 max_tokens=256,
34 temperature=0.7,
35 top_p=0.9,
36 stop=["<|end_of_text|>", "<|eot_id|>"] # Standard Llama 3 end tokens
37)
38
39print(output["choices"][0]["text"])meta-llama/Meta-Llama-3.1-8B as your base model..gguf file directly. To do further code-based fine-tuning, you should use the original unquantized model weights (Safetensors) using Unsloth, which allows you to fine-tune LLaMA 3.1 8B on a free Colab T4 GPU.1!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
2!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes1from unsloth import FastLanguageModel
2import torch
3from trl import SFTTrainer
4from transformers import TrainingArguments
5from datasets import load_dataset
6
7max_seq_length = 2048
8dtype = None # Auto detection
9load_in_4bit = True # 4bit quantization to save memory
10
11# 1. Load the BASE model (Not the GGUF, but the Safetensors repo)
12model, tokenizer = FastLanguageModel.from_pretrained(
13 model_name = "welyjesch/filipino_llama_3.1_finetuned_lora",
14 max_seq_length = max_seq_length,
15 dtype = dtype,
16 load_in_4bit = load_in_4bit,
17)
18
19# 2. Add LoRA adapters
20model = FastLanguageModel.get_peft_model(
21 model,
22 r = 16,
23 target_modules =["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
24 lora_alpha = 16,
25 lora_dropout = 0,
26 bias = "none",
27 use_gradient_checkpointing = "unsloth",
28 random_state = 3407,
29)
30
31# 3. Format dataset to Alpaca
32alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
33
34### Instruction:
35{}
36
37### Input:
38{}
39
40### Response:
41{}"""
42
43EOS_TOKEN = tokenizer.eos_token
44def formatting_prompts_func(examples):
45 instructions = examples["instruction"]
46 inputs = examples["input"]
47 outputs = examples["output"]
48 texts =[]
49 for instruction, input, output in zip(instructions, inputs, outputs):
50 text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
51 texts.append(text)
52 return { "text" : texts, }
53
54# Load and format your new Filipino dataset
55dataset = load_dataset("json", data_files="your_new_filipino_alpaca_data.json", split="train")
56dataset = dataset.map(formatting_prompts_func, batched = True,)
57
58# 4. Setup Trainer
59trainer = SFTTrainer(
60 model = model,
61 tokenizer = tokenizer,
62 train_dataset = dataset,
63 dataset_text_field = "text",
64 max_seq_length = max_seq_length,
65 dataset_num_proc = 2,
66 args = TrainingArguments(
67 per_device_train_batch_size = 2,
68 gradient_accumulation_steps = 4,
69 warmup_steps = 5,
70 max_steps = 60, # Increase this for actual training
71 learning_rate = 2e-4,
72 fp16 = not torch.cuda.is_bf16_supported(),
73 bf16 = torch.cuda.is_bf16_supported(),
74 logging_steps = 1,
75 optim = "adamw_8bit",
76 weight_decay = 0.01,
77 lr_scheduler_type = "linear",
78 seed = 3407,
79 output_dir = "outputs",
80 ),
81)
82
83# 5. Start Training
84trainer_stats = trainer.train()
85
86# 6. Save the new model and export back to GGUF
87model.save_pretrained_gguf("model", tokenizer, quantization_method = "q4_k_m")
88# You can then upload the resulting GGUF file back to Hugging Facellama-cli -hf welyjesch/filipino_llama_3.1_FT_8B_GGUF --jinjallama-mtmd-cli -hf welyjesch/filipino_llama_3.1_FT_8B_GGUF --jinjallama-3.1-8b.Q8_0.gguf
This was trained 2x faster with Unsloth