Views
No views yet
meta-llama/Meta-Llama-3.1-8B-Instruct model, specifically tailored for generating and understanding Persian text. The fine-tuning was conducted using the TinyStories-Farsi dataset, which includes a diverse set of short stories in Persian. The primary goal of this fine-tuning was to enhance the model's performance in instruction-following tasks within the Persian language.meta-llama/Meta-Llama-3.1-8B-InstructBitsAndBytesConfig(load_in_4bit=True) configuration was used, allowing the model to be fine-tuned in 4-bit precision. This approach significantly reduced the computational resources required while maintaining high performance, resulting in a training time of approximately 2 hours. The use of BitsAndBytesConfig(load_in_4bit=True) helped reduce the environmental impact by minimizing the computational resources required.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Specify the combined model
5model_name = "AmirMohseni/Llama-3.1-8B-Instruct-Persian-finetuned-sft"
6
7# Load the model and tokenizer
8model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10
11# Ensure pad_token is set (if not already set)
12if tokenizer.pad_token is None:
13 tokenizer.add_special_tokens({'pad_token': tokenizer.eos_token})
14
15# Check if CUDA is available, otherwise use CPU
16device = "cuda" if torch.cuda.is_available() else "cpu"
17model = model.to(device)
18
19# Example usage
20input_text = "چطوری میتونم به اطلاعات درباره ی سهام شرکت های آمریکایی دست پیدا کنم؟"
21
22# Tokenize the input
23inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True).to(device)
24
25# Generate text
26outputs = model.generate(
27 inputs['input_ids'],
28 attention_mask=inputs['attention_mask'],
29 max_length=512,
30 pad_token_id=tokenizer.pad_token_id
31)
32
33# Decode and print the output
34response = tokenizer.decode(outputs[0], skip_special_tokens=True)
35print(response)