Views
No views yet
| Property | Value |
|---|---|
| Base Model | afriquellama_8b |
| Translation Direction | English → Amharic |
| LoRA Rank (r) | 64 |
| LoRA Alpha | 128 |
| Training Method | QLoRA (4-bit quantization) |
| Domain | Scientific/Academic texts |
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# Configure 4-bit quantization (recommended for memory efficiency)
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_compute_dtype=torch.bfloat16,
9 bnb_4bit_quant_type="nf4",
10 bnb_4bit_use_double_quant=True,
11)
12
13# Load base model
14base_model = AutoModelForCausalLM.from_pretrained(
15 "afriquellama_8b",
16 quantization_config=bnb_config,
17 device_map="auto",
18 torch_dtype=torch.bfloat16,
19)
20tokenizer = AutoTokenizer.from_pretrained("afriquellama_8b")
21
22# Load LoRA adapter
23adapter_name = "dsfsi/afriquellama_8b-lora-r64-eng-amh"
24model = PeftModel.from_pretrained(base_model, adapter_name)
25model.eval()
26
27# Prepare translation prompt
28source_text = "Climate change significantly impacts agricultural productivity in sub-Saharan Africa."
29instruction = "Translate the following English scientific text to Amharic."
30
31# Format prompt
32prompt = f"""### Instruction:
33{instruction}
34
35### Input:
36{source_text}
37
38### Response:
39"""
40
41# Generate translation
42inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
43with torch.no_grad():
44 outputs = model.generate(
45 **inputs,
46 max_new_tokens=256,
47 num_beams=5,
48 early_stopping=True,
49 pad_token_id=tokenizer.pad_token_id,
50 )
51
52# Decode only the generated part
53generated = outputs[0][inputs["input_ids"].shape[1]:]
54translation = tokenizer.decode(generated, skip_special_tokens=True)
55print(translation)1# For GPUs with sufficient memory (>24GB for larger models)
2base_model = AutoModelForCausalLM.from_pretrained(
3 "afriquellama_8b",
4 device_map="auto",
5 torch_dtype=torch.bfloat16,
6)
7model = PeftModel.from_pretrained(base_model, "dsfsi/afriquellama_8b-lora-r64-eng-amh")| Configuration | VRAM Required |
|---|---|
| 4-bit (QLoRA) | ~8-12 GB |
| 8-bit | ~16-20 GB |
| Full precision | ~24-40 GB |
1# Clone the AfriScience-MT repository
2git clone https://github.com/afriscience-mt/afriscience-mt.git
3cd afriscience-mt
4
5# Install dependencies
6pip install -r requirements.txt
7
8# Run LoRA training
9python -m afriscience_mt.scripts.run_lora_training \
10 --data_dir ./data \
11 --source_lang eng \
12 --target_lang amh \
13 --model_name afriquellama_8b \
14 --model_type llama \
15 --lora_rank 64 \
16 --output_dir ./output \
17 --num_epochs 3 \
18 --batch_size 4 \
19 --load_in_4bit1@article{abdulmumin2026afriscience,
2 title = {AfriScience-MT: Towards Decolonizing Science in Africa through Text Translation},
3 author = {Abdulmumin, Idris and Gwadabe, Tajuddeen and Muhammad, Shamsuddeen Hassan and Adelani, David Ifeoluwa and Khalo, Nomonde and Ahmad, Ibrahim Said and Modupe, Abiodun and Mumm, Anina and Biyela, Sibusiso and Rabie, Michelle and Havemann, Johanna and Rei, Marek and Abbott, Jade and Marivate, Vukosi},
4 journal = {arXiv preprint arXiv:2605.29741},
5 year = {2026},
6 url = {https://arxiv.org/abs/2605.29741}
7}