File size: 2,560 Bytes
655f931
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language:
- en
pipeline_tag: text-generation
library_name: transformers
tags:
- bitnet
- bitnet-b1.58
- ternary
- gguf
- cpu
- tinydialogues
datasets:
- styfeng/TinyDialogues
metrics:
- perplexity
---

# BitNet TinyDialogues 1.58b

Modelo experimental **BitNet b1.58-style** treinado do zero em CPU com
[`styfeng/TinyDialogues`](https://huggingface.co/datasets/styfeng/TinyDialogues).

## O que é

- Transformer causal pequeno com `BitLinear`: pesos ternários `{-1, 0, +1}` no forward (1,58 bit/peso).
- Ativações quantizadas em 8 bits por token durante o treino (W1.58A8).
- FFN com `ReLU²`, RoPE, RMSNorm/subLN, embeddings tied.
- GGUF: `TQ1_0` e `TQ2_0` (ternários). O arquivo também contém embeddings/normas em maior precisão.

> “1-bit BitNet” aqui significa a família BitNet b1.58 ternária, não 1 bit matemático por peso.

## Arquitetura

| Campo | Valor |
|---|---|
| Parâmetros | ~2,89 M |
| Camadas | 4 |
| Hidden | 256 |
| FFN | 512 |
| Heads | 4 (KV 2) |
| Vocab | 2048 BPE SentencePiece |
| Contexto | 128 tokens |
| Treino | 8000 steps, batch 8, seq 128, CPU |
| Melhor val loss | 2.5838 (step 7000) |
| Perplexidade val | ~13.25 |

## Arquivos

- `gguf/bitnet-tinydialogues-TQ1_0.gguf` — principal, menor (~1,1 MiB).
- `gguf/bitnet-tinydialogues-TQ2_0.gguf` — alternativa ternária (~1,2 MiB).
- `gguf/bitnet-tinydialogues-f32.gguf` — referência F32 (~11 MiB).
- `model.safetensors`, `config.json`, `tokenizer.model`, `tokenizer.json` — checkpoint HF.
- `scripts/` — preparação, treino, exportação e demo.
- `patches/llama.cpp-bitnet-fixes.patch` — patch ReLU² + mapeamento de tensores.
- `Dockerfile` — Space Docker/Gradio para CPU (requer PRO ou hardware pago).

## Uso rápido com llama.cpp

O runtime precisa usar `ReLU²` no FFN do BitNet. O llama.cpp upstream ainda pode usar SiLU hardcoded;
aplique `patches/llama.cpp-bitnet-fixes.patch` ou use o `Dockerfile`.

```bash
llama-cli -m gguf/bitnet-tinydialogues-TQ1_0.gguf \
  -p "user: can we play? assistant:" -n 64 --temp 0.7 -t 2 -r "user:"
```

Exemplo real (TQ1_0, greedy):

```text
user: can we play? assistant: yes, but we need to clean up. we need to clean up.
```

## HF demo (ternário)

```bash
python scripts/demo_hf.py --model . --prompt "user: can we play? assistant:" --tokens 40
```

## Limitações

Modelo muito pequeno, treinado apenas em diálogos infantis em inglês. Serve para demonstrar
BitNet/GGUF/CPU; não é um assistente geral nem tem conhecimento confiável.

## Licença

MIT. Dataset TinyDialogues: MIT.