Karnak: Enhanced Arabic–English Large Language Model
Karnak is a powerful AI model that works in both Arabic and English, with extra improvements that make it especially strong in Arabic and more natural in the way it writes and responds. It was built by taking an existing model and improving it through more training, so it can understand instructions better, handle longer text, and give more reliable answers. This makes it useful for everyday tasks like answering questions, explaining topics, writing content, or helping with work and research. It can also process long pieces of text, which is helpful for documents and extended conversations. A big advantage is that it is not locked to an online service only, since you can download it, run it locally on your own machine or servers, and even fine-tune it for your own specific use case.
Model Summary
Karnak is a depth-extended causal language model optimized for Arabic and English generation. It is built on top of Qwen/Qwen3-30B-A3B-Instruct-2507, featuring architectural depth extension and a tokenizer specifically optimized for Arabic to improve fluency and efficiency.
Karnak was trained using high-quality, filtered data through a rigorous pipeline to enhance overall instruction-following capabilities, factuality, and robustness.
Key Features
Depth Extension (~40B): Expanded depth to increase reasoning capacity and improve long-range dependency modeling.
Arabic-Optimized Tokenizer: Improved Arabic tokenization efficiency, resulting in reduced token fragmentation and higher-quality generation.
Multi-Stage Training: The model evolved through: Pre-trained weights → Depth Extension → Continued Pre-training → SFT (Supervised Fine-Tuning).
Extended Context Window: Designed for long-context usage with a safe context range up to 20K tokens (recommended to stay within this limit for optimal stability).
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
34model_id ="Applied-Innovation-Center/Karnak"56# Load tokenizer and model7tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)8model = AutoModelForCausalLM.from_pretrained(9 model_id,10 device_map="auto",11 torch_dtype=torch.bfloat16,12 trust_remote_code=True,13)1415# Prepare Input16prompt ="اشرح لي نظرية النسبية بشكل مبسط."17messages =[18{"role":"system","content":"You are a helpful assistant."},19{"role":"user","content": prompt},20]2122# Apply chat template23text = tokenizer.apply_chat_template(24 messages,25 tokenize=False,26 add_generation_prompt=True,27)28model_inputs = tokenizer([text], return_tensors="pt").to(model.device)2930# Generate31generated_ids = model.generate(32**model_inputs,33 max_new_tokens=512,34 temperature=0.7,35 top_p=0.9,36)3738# Decode output (removing the prompt tokens)39generated_ids = generated_ids[:, model_inputs.input_ids.shape[1]:]40response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]41print(response)
vLLM (Recommended for Production)
Karnak is compatible with vLLM for high-throughput inference.
Installation:
bash
12pip install -U vllm
Offline Inference:
python
12from vllm import LLM, SamplingParams
34model_id ="Applied-Innovation-Center/Karnak"56# Initialize the model7llm = LLM(8 model=model_id,9 trust_remote_code=True,10 max_model_len=20000,# Safe context range11 tensor_parallel_size=1,# Adjust based on available GPUs12)1314# Set sampling parameters15sampling_params = SamplingParams(16 temperature=0.7,17 top_p=0.9,18 max_tokens=512,19)2021# Generate22prompts =["ما هي عاصمة مصر؟"]23outputs = llm.generate(prompts, sampling_params)2425for o in outputs:26print(f"Prompt: {o.prompt}")27print(f"Generated: {o.outputs[0].text}")
Server Mode (OpenAI-Compatible API):
You can serve the model as an API compatible with OpenAI clients: