Archived page: this is the MoroLMai V1.3 write-up as published in November 2026. Go to the current page (V2.9b).
MoroLMai

Archived: V1.3Superseded by V2.9bResearch preview

MoroLMai: a 136M-parameter language model for Moroccan Darija and English

نموذج لغوي صغير للدارجة المغربية والإنجليزية

Abstract

We trained a small decoder-only language model from scratch on Moroccan Darija and English: its own tokenizer, its own training code, no borrowed weights. The model has 135,961,088 parameters, a 32,000-token vocabulary and a 1,024-token context. It was pre-trained on roughly one billion tokens on a single consumer GPU, then fine-tuned for chat. The quantized GGUF file is 145 MB, so it runs on a machine with 2 GB of graphics memory or on CPU alone.

It greets, introduces itself and writes fluent Darija and English. It does not know facts reliably. This page documents what we built, what we measured and where it fails.

Hover, tap or focus a layer to read its size.

Figure 1. Where the 136M parameters live, drawn to scale. The dark block is the tied token embedding (16.4M, 12.1%). Each of the 38 columns is one decoder layer (3.15M): the saffron part is attention (25%), the blue part is the SwiGLU feed-forward network (75%). Widths are computed from the model configuration, not drawn by hand.

1. Motivation

Darija is spoken every day by tens of millions of people, yet general-purpose language models handle it poorly, and almost none handle it when Arabic script and Latin letters mix in the same message.

Large models fill that gap with scale and cost money to run. We asked the opposite question: how far can a very small model go if it is trained for the language from the start, and can it run on hardware that a Moroccan student, school or small business already owns?

Target hardware. 2 GB of GPU memory, 4 CPU cores and 8 GB of RAM, served through llama.cpp.

The constraint shapes every choice below: a vocabulary that is small enough to keep the embedding table cheap, a model deep and narrow rather than wide, and a file small enough for an ordinary laptop.

2. Architecture

The model is a Llama-style decoder-only transformer. The shape is deep and narrow: 38 layers with a hidden size of only 512. That layout keeps the embedding table and the attention width small, which is where a tiny model spends its memory budget.

Table 1. Model configuration.
ComponentValue
Parameters135,961,088
Decoder layers38
Hidden size512
Feed-forward (SwiGLU) size1,536
Attention heads / key-value heads8 / 4 (grouped-query)
Position encodingRoPE (θ = 10,000)
NormalizationRMSNorm (ε = 1e-5)
Embeddingstied input and output
Vocabulary32,000
Context window1,024 tokens

Grouped-query attention halves the key and value projections, which shrinks the cache that grows with every generated token. Tying the input and output embeddings saves another 16.4M parameters. Residual output projections are initialized with a standard deviation scaled by 1/√(2·layers), a GPT-2-style rule that keeps a deep stack stable at the start of training.

Check the total. Per layer: attention 786,432 + feed-forward 2,359,296 + norms 1,024 = 3,146,752. Times 38 = 119,576,576. Add the 16,384,000-parameter embedding and the final norm (512) and you get 135,961,088.

3. Tokenizer

We train a SentencePiece BPE tokenizer with 32,000 pieces on 2 million lines, half Darija and half English, with byte fallback so that no character ever becomes an unknown token. Three reserved tokens mark the chat roles: <|system|>, <|user|> and <|assistant|>.

For V2 we tested whether retraining the tokenizer on the same corpus would help. It did not, and we report that as a negative result.

Table 2. Original and retrained tokenizer on 300 documents per text type. Lower tokens per word is better.
TextTokens/word, originalretrainedChars/token, originalretrained
Arabic script1.581.553.833.90
Arabizi1.601.613.803.79
English1.431.434.264.25

The best case is a 2% saving in Arabic script, which is not worth discarding a trained model. The V2 run therefore keeps the original tokenizer and continues from the V1 weights. Byte-fallback tokens are about 2% in every text type including English, which suggests they are mostly line breaks and rare symbols rather than missing Darija vocabulary.

Arabizi is Darija written with Latin letters and digits (3 for ع, 7 for ح, 9 for ق). It is how most Moroccans type on a phone.

4. Data

Pre-training corpus

The pre-training corpus has 1.4 million documents and about one billion tokens, taken from two open web-text collections.

Table 3. Pre-training sources.
SourceLanguageDocumentsLicence
FineWeb-2, subset ary_ArabMoroccan Arabic1,000,000ODC-By 1.0
FineWeb-Edu, sample-10BTEnglish400,000ODC-By 1.0

Chat data

Chat fine-tuning draws on a Darija instruction dataset (573K examples), a cleaned English instruction set, a 40K-conversation English dialogue sample and translation pairs, formatted with the three role tokens. The exact mixture changed between versions as we found and removed weak data. Loss is computed on the assistant's answer only, never on the prompt.

No private data. Everything above is openly licensed. We did not scrape private social media.

The chat template is:

<|system|> …system message… <|user|> …question… <|assistant|> …answer…</s>

5. Training

Pre-training minimises next-token cross-entropy over packed 1,024-token windows. We use AdamW (β₁ = 0.9, β₂ = 0.95, weight decay 0.1), gradient clipping at 1.0, a short warm-up, cosine decay to 10% of the peak learning rate, and bfloat16 mixed precision. By default each optimizer step covers 131,072 tokens (8 sequences × 16 accumulation steps × 1,024 tokens).

Training on a consumer GPU

The first versions trained on an RTX 3050 with 6 GB of memory. Gradient checkpointing, which recomputes activations instead of storing them, is what makes a 38-layer model fit. We later moved to an RTX 5060 Ti with 8 GB and measured the speed-up directly.

Figure 2. Measured training throughput with gradient checkpointing. One billion tokens takes about 2.8 days on the RTX 3050 and about 18.5 hours on the RTX 5060 Ti (computed from the throughput).

Why a speed-up matters. A small model can only be improved by running many experiments. Cutting a pass over the data from three days to under one day changes how many ideas we can test.

Without gradient checkpointing the same configuration ran at roughly 490 tokens per second on the 8 GB card, because activations spilled into system memory. Memory behaviour, not raw arithmetic, decided the result.

Chat tuning

Supervised fine-tuning ran through four versions, V1 to V1.3. Each version fixed something the previous one got wrong, such as a missing identity and broken greetings. V1.3 is the current release.

6. Results

Table 4. Held-out loss. The two numbers measure different things and must not be compared with each other.
StageLossPerplexityWhat is measured
Pre-training, V13.417730.5next token, web text, one pass over the data
Chat fine-tuning, V1.31.62355.1assistant answers only, chat validation set

A perplexity of 30 after a single pass is typical for this size. We expect it to fall with more passes over the data, and the V2 run tests that.

What we observe in chat

Numbers like these say little about how the model behaves, so we also test a fixed set of prompts by hand: a greeting, a name, a general-knowledge question, a statement about feeling tired, and Darija questions about Morocco. We compare each version on the same prompts.

What works

  • Fluent Darija and English sentences.
  • Greets and says who it is.
  • Quantization to 8 bits does not visibly change the answers.

What does not

  • Facts. It answers confidently and often wrongly, for example by placing Rabat in the Middle Atlas.
  • It invents names, such as “Frantenck” for a person or place.
  • It garbles a user's name when asked to repeat it.

Why facts fail. A model with 136M parameters trained on about a billion tokens has little room for world knowledge. Fluency is cheap. Knowledge is not.

Fluency without knowledge is the expected outcome at this size, and it tells us where the effort should go: better data and verified facts, not a different architecture.

7. Deployment

The model is exported to GGUF and served with llama.cpp. The Hugging Face page currently hosts V1.2 in three sizes; V1.3 is the latest version and will follow. Because it is small, generation speed is limited by memory bandwidth, not arithmetic, so shrinking the file is the most direct way to make it faster.

Figure 3. File size by format. The 32-bit size is computed from the parameter count; the GGUF sizes are the exported files published on Hugging Face.
Table 5. GGUF variants in a local test on the developer's PC.
FormatSizeSpeedQuality
f16273 MBabout 64 tokens/sreference
Q8_0145 MBabout 100 tokens/sno visible difference
Q4_K_M86 MBnot measurednot yet compared

Q4_K_M is the smallest file but we have not compared its answers yet. We recommend Q8_0: about half the size, about 1.5 times as fast, and no visible difference in our tests.

$ llama-server -m morolmai-v1.3-q8_0.gguf -c 1024

7. Deployment

The model is exported to GGUF and served with llama.cpp. The Hugging Face page currently hosts V1.2 in three sizes; V1.3 is the latest version and will follow. Because it is small, generation speed is limited by memory bandwidth, not arithmetic, so shrinking the file is the most direct way to make it faster.

Figure 3. File size by format. The 32-bit size is computed from the parameter count; the GGUF sizes are the exported files published on Hugging Face.
Table 5. GGUF variants in a local test on the developer's PC.
FormatSizeSpeedQuality
f16273 MBabout 64 tokens/sreference
Q8_0145 MBabout 100 tokens/sno visible difference
Q4_K_M86 MBnot measurednot yet compared

Q4_K_M is the smallest file but we have not compared its answers yet. We recommend Q8_0: about half the size, about 1.5 times as fast, and no visible difference in our tests.

$ llama-server -m morolmai-v1.3-q8_0.gguf -c 1024

8. Roadmap

V2 targets the weaknesses above. Nothing in this list has results yet, and we will publish them whether or not they help.

  1. Test a retrained tokenizerDone. A 2% gain in Arabic script and none elsewhere, so we keep the original (Table 2).
  2. Continue pre-training from the V1 weightsSeveral more passes over the same corpus on the RTX 5060 Ti, at a lower peak learning rate so the restart does not erase what V1 learned.
  3. Add more Darija textRepeating the same text has a ceiling. New data is the larger lever.
  4. A verified facts set200 to 300 checked questions and answers about Morocco, in English and Darija, so the model has correct facts to learn.
  5. Fix name handlingTraining examples that teach it to repeat a user's name correctly.
  6. Compare against V1.3 on fixed promptsSame prompts, same settings, published side by side.

9. Limitations and responsible use

  • MoroLMai is a research preview. It is not a reliable source of facts and should not be used for legal, medical or financial advice.
  • It reflects the web text it was trained on, including its errors and biases.
  • Darija written in Latin letters (Arabizi) is weaker than Darija in Arabic script, because there is less of it in the training data.
  • The context window is 1,024 tokens, so long documents do not fit.
  • Evaluation so far is a fixed prompt set plus held-out loss. There is no standard Darija benchmark score yet.

10. Licences and data provenance

Table 6. Sources and their licences, as published by their authors. Check each source before any commercial use.
SourceUsed forLicence
FineWeb-2 (Moroccan Arabic)Pre-trainingODC-By 1.0
FineWeb-EduPre-trainingODC-By 1.0
Moroccan-Darija-Instruct-573KChat tuningCC BY 4.0
Other chat sources: English instructions, English dialogue, translation pairsChat tuningsee each dataset's page

The model files on Hugging Face are published under Apache-2.0, subject to the licence terms and rights attached to the training data. Check the sources above before any commercial use.

11. Cite

@misc{morolmai2026,
  title  = {MoroLMai: a 136M-parameter language model
            for Moroccan Darija and English},
  author = {Daoud, Hamza},
  year   = {2026},
  url    = {https://morolmai.com/}
}