File size: 4,213 Bytes
d915041
50d10e2
52135a8
50d10e2
 
d915041
52135a8
50d10e2
52135a8
 
 
 
50d10e2
d915041
 
52135a8
d915041
52135a8
d915041
52135a8
d915041
52135a8
50d10e2
52135a8
 
 
 
 
50d10e2
52135a8
c7c556f
52135a8
 
 
 
 
 
 
 
 
 
 
 
c7c556f
52135a8
c7c556f
52135a8
c7c556f
52135a8
 
 
 
 
 
 
 
 
334fa55
52135a8
334fa55
52135a8
50d10e2
 
52135a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language:
- it
- en
license: apache-2.0
tags:
- italian
- causal-lm
- small-language-model
- trained-from-scratch
- chatml
- conversational
pipeline_tag: text-generation
---

# βš› Quark-50M-v2

**43.8M parameter Italian-first bilingual language model, trained from scratch by ThingAI.**

Quark-50M is an ultra-compact causal language model that speaks fluent Italian. Designed as a proof-of-concept for small, efficient, Italian-centric AI.

## Highlights

- **43.8M parameters** β€” runs on any device, even CPU
- **Italian-first** β€” trained on 60% Italian data (books, Wikipedia, web)
- **ChatML format** β€” `<|im_start|>user`/`<|im_start|>assistant`
- **Custom tokenizer** β€” 16k BPE, optimized for Italian (4.15 chars/token)
- **Trained from scratch** β€” architecture, tokenizer, and training pipeline all custom

## Architecture

| Component | Value |
|-----------|-------|
| Parameters | 43.8M |
| Vocabulary | 16,384 (BPE) |
| Dimensions | 512 |
| Layers | 12 |
| Heads | 8 (4 KV heads, GQA) |
| FFN | 1,408 (SwiGLU) |
| Context | 2,048 tokens |
| Normalization | RMSNorm |
| Position | RoPE |
| Weight Tying | Yes |

## Training

**Pretraining:** 5B tokens on a curated mix:

| Dataset | Weight | Type |
|---------|--------|------|
| PleIAs/Italian-PD | 25% | 171K Italian books (public domain) |
| FineWeb-2 Italian | 20% | Cleaned, deduplicated web |
| Wikipedia IT | 15% | Encyclopedia |
| Cosmopedia | 15% | Synthetic educational |
| SmolLM-Corpus | 10% | Curated mix |
| StarCoder Python | 8% | Code |
| OpenWebMath | 7% | Mathematics |

**SFT:** Fine-tuned on [quattro-chiacchiere](https://huggingface.co/datasets/ThingAI/quattro-chiacchiere), a synthetic Italian Q&A dataset generated with [Alembic](https://github.com/skein-labs/Alembic).

## Usage

```python
import torch
from huggingface_hub import hf_hub_download
from transformers import PreTrainedTokenizerFast

# Load
ckpt_path = hf_hub_download("ThingAI/Quark-50M", "model.pt")
model_py = hf_hub_download("ThingAI/Quark-50M", "model.py")
tok_file = hf_hub_download("ThingAI/Quark-50M", "tokenizer.json")

# Tokenizer
tokenizer = PreTrainedTokenizerFast(tokenizer_file=tok_file)
tokenizer.eos_token = "<|endoftext|>"

# Model
import importlib.util
spec = importlib.util.spec_from_file_location("model", model_py)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)

ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)
cfg = mod.ModelConfig(**ckpt["model_cfg"])
model = mod.Quark(cfg).eval()
model.load_state_dict(ckpt["model"])

# Chat
prompt = "<|im_start|>user\nQual Γ¨ la capitale d'Italia?<|im_end|>\n<|im_start|>assistant\n"
ids = tokenizer.encode(prompt, return_tensors="pt")
with torch.no_grad():
    for _ in range(100):
        logits = model(ids)[1][:, -1, :].float()
        nxt = logits.argmax(-1, keepdim=True)
        if nxt.item() == tokenizer.convert_tokens_to_ids("<|im_end|>"): break
        ids = torch.cat([ids, nxt], -1)
print(tokenizer.decode(ids[0], skip_special_tokens=True))
# La capitale d'Italia Γ¨ Roma.
```

## Examples

```
Tu: Qual Γ¨ la capitale d'Italia?
Quark: La capitale d'Italia Γ¨ Roma.

Tu: Chi sei?
Quark: Sono Quark, piacere di conoscerti.

Tu: Come ti chiami?
Quark: Mi chiamo Quark, piacere di conoscerti.
```

## Limitations

- **43.8M parameters** β€” cannot perform complex reasoning or long-form generation
- **Factual accuracy** β€” may hallucinate facts, especially on niche topics
- **SFT dataset** β€” currently limited; more data will improve reliability
- **No safety training** β€” not recommended for production without guardrails

## Related

- [Quark3Tokenizer](https://huggingface.co/ThingAI/Quark3Tokenizer) β€” the tokenizer
- [quattro-chiacchiere](https://huggingface.co/datasets/ThingAI/quattro-chiacchiere) β€” the SFT dataset
- [Alembic](https://github.com/skein-labs/Alembic) β€” the dataset distillation tool
- [Glyph](https://huggingface.co/ThingAI/Glyph) β€” multi-task text classifier by ThingAI

## Citation

```bibtex
@misc{quark50m,
  author = {ThingAI},
  title  = {Quark-50M-v2: Italian-First Small Language Model},
  year   = {2026},
  url    = {https://huggingface.co/ThingAI/Quark-50M}
}
```

## License

Apache 2.0