Text Generation
Transformers
Safetensors
qwen3
african-languages
multilingual
continued-pretraining
afrique-llm
qwen
llamafactory
conversational
text-generation-inference
Instructions to use McGill-NLP/AfriqueQwen-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use McGill-NLP/AfriqueQwen-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="McGill-NLP/AfriqueQwen-8B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("McGill-NLP/AfriqueQwen-8B") model = AutoModelForCausalLM.from_pretrained("McGill-NLP/AfriqueQwen-8B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use McGill-NLP/AfriqueQwen-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "McGill-NLP/AfriqueQwen-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "McGill-NLP/AfriqueQwen-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/McGill-NLP/AfriqueQwen-8B
- SGLang
How to use McGill-NLP/AfriqueQwen-8B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "McGill-NLP/AfriqueQwen-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "McGill-NLP/AfriqueQwen-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "McGill-NLP/AfriqueQwen-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "McGill-NLP/AfriqueQwen-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use McGill-NLP/AfriqueQwen-8B with Docker Model Runner:
docker model run hf.co/McGill-NLP/AfriqueQwen-8B
File size: 6,551 Bytes
b220795 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | ---
library_name: transformers
license: apache-2.0
base_model: Qwen/Qwen3-8B
language:
- af # Afrikaans
- am # Amharic
- ar # Arabic
- en # English
- fr # French
- ha # Hausa
- ig # Igbo
- mg # Malagasy (Plateau)
- ny # Nyanja
- om # Oromo
- pt # Portuguese
- rw # Kinyarwanda
- sn # Shona
- so # Somali
- st # Southern Sotho
- sw # Swahili
- ti # Tigrinya
- tn # Tswana
- xh # Xhosa
- yo # Yoruba
- zu # Zulu
pipeline_tag: text-generation
tags:
- african-languages
- multilingual
- continued-pretraining
- afrique-llm
- qwen
---
# AfriqueQwen-8B
<p align="center">
<img src="language_group_scores.pdf" alt="AfriqueLLM Evaluation Results" width="600"/>
</p>
## Model Overview
**AfriqueQwen-8B** is part of the **AfriqueLLM** suite—a collection of open language models adapted to **20 African languages** through continued pre-training (CPT) on **26B tokens**. This model is based on [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B) and has been specifically adapted for improved performance on African languages while maintaining strong capabilities in high-resource languages.
Our experiments show that **Qwen 3 models achieve the best performance** among all base models tested, better preserving performance in high-resource languages after CPT and achieving strong results on long-context tasks such as document-level translation.
### Key Features
- **Type**: Causal Language Model (Base/Pre-trained)
- **Base Model**: Qwen 3 8B
- **Parameters**: 8B
- **Context Length**: 32,768 tokens (native)
- **Training Tokens**: 26B tokens of carefully curated multilingual data
## Supported Languages
AfriqueQwen-8B has been adapted for the following 20 African languages plus 4 high-resource languages:
| Language | Code | Family | Script |
|----------|------|--------|--------|
| Afrikaans | afr_Latn | Germanic | Latin |
| Swahili | swh_Latn | Bantu | Latin |
| Moroccan Arabic | ary_Arab | Semitic | Arabic |
| Somali | som_Latn | Cushitic | Latin |
| Amharic | amh_Ethi | Semitic | Ethiopic |
| Egyptian Arabic | arz_Arab | Semitic | Arabic |
| Hausa | hau_Latn | Chadic | Latin |
| Kinyarwanda | kin_Latn | Bantu | Latin |
| Zulu | zul_Latn | Bantu | Latin |
| Igbo | ibo_Latn | Volta-Niger | Latin |
| Plateau Malagasy | plt_Latn | Austronesian | Latin |
| Xhosa | xho_Latn | Bantu | Latin |
| Shona | sna_Latn | Bantu | Latin |
| Yoruba | yor_Latn | Volta-Niger | Latin |
| Nyanja | nya_Latn | Bantu | Latin |
| Southern Sotho | sot_Latn | Bantu | Latin |
| Tigrinya | tir_Ethi | Semitic | Ethiopic |
| Tunisian Arabic | aeb_Arab | Semitic | Arabic |
| Oromo | gaz_Latn | Cushitic | Latin |
| Tswana | tsn_Latn | Bantu | Latin |
**High-resource languages (for catastrophic forgetting mitigation):** English, French, Portuguese, Arabic
## Training Data
Our training corpus combines multiple high-quality sources:
- **African Monolingual Data** (~22.8B tokens): FineWeb2, WURA, and MADLAD-400
- **Code** (~1B tokens): CornStack-Python for reasoning capabilities
- **Mathematics** (~1B tokens): FineMath-4+ for mathematical understanding
- **Synthetic Data** (~324M tokens): GPT-4.1 translated domain-specific content across 10 domains
- **Parallel Data** (~456M tokens): NLLB-OPUS filtered with SSA-COMET (threshold 0.7)
We use **UniMax sampling** to create a balanced distribution, capping high-resource languages at approximately 1B tokens and upsampling lower-resource languages for up to five epochs.
## Quickstart
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "McGill-NLP/AfriqueQwen-8B"
# Load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
# Prepare the model input
prompt = "Bawo ni o ṣe n ṣe?" # Yoruba: "How are you doing?"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate text
generated_ids = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.7,
top_p=0.9
)
output = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
print(output)
```
## Deployment
For deployment, you can use `vllm` or `sglang` to create an OpenAI-compatible API endpoint:
**vLLM:**
```shell
vllm serve McGill-NLP/AfriqueQwen-8B
```
**SGLang:**
```shell
python -m sglang.launch_server --model-path McGill-NLP/AfriqueQwen-8B
```
## Training Details
### Hyperparameters
- **Learning Rate**: 5e-5 (with warmup and cosine decay)
- **Context Length**: 8,192 tokens (training)
- **Batch Size**: Effective batch size optimized for throughput
- **Optimizer**: AdamW
- **Precision**: BF16 mixed precision
### Infrastructure
Training was conducted using the LLaMA-Factory framework on up to 64 NVIDIA H100 GPUs with:
- DeepSpeed ZeRO-1/ZeRO-2
- Flash Attention 3
- Sequence packing
- Liger Kernel optimizations
## Evaluation
AfriqueQwen-8B is evaluated on multiple multilingual benchmarks including:
- **AfriMGSM**: Mathematical reasoning
- **AfriMMLU**: Multilingual knowledge
- **AfriXNLI**: Natural language inference
- **Belebele**: Reading comprehension
- **SIB-200**: Topic classification
- **FLORES**: Machine translation
## Model Variants
- [AfriqueQwen-14B](https://huggingface.co/McGill-NLP/AfriqueQwen-14B) - Larger, more capable variant
## Intended Use
This model is designed for:
- Research on African language NLP
- Building applications for African language communities
- Cross-lingual transfer learning experiments
- Multilingual text generation and understanding
## Limitations
- This is a **base/pre-trained model** and may require fine-tuning for specific tasks
- Performance varies across languages based on data availability
- May generate biased or inappropriate content without proper safeguards
- Not suitable for production use without additional safety measures
## Citation
If you find our work helpful, please cite:
```bibtex
@article{afriquellm2025,
title={AfriqueLLM: How Data Mixing and Model Architecture Impact Continued Pre-training for African Languages},
author={AfriqueLLM Team},
year={2025}
}
```
## License
This model is released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). Please review the license terms before use.
## Acknowledgments
We thank the creators of the base models and datasets that made this work possible, including Alibaba (Qwen), the FineWeb team, WURA, MADLAD-400, and the NLLB project.
|