Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,117 +1,122 @@
|
|
| 1 |
-
# Chimera GGUF Import
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
##
|
| 6 |
|
| 7 |
```
|
| 8 |
-
GGUF (Q4_0
|
| 9 |
-
→
|
| 10 |
-
→
|
| 11 |
-
→
|
| 12 |
-
→ 2-bit
|
| 13 |
-
→ Chimera 5.1
|
| 14 |
```
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
```bash
|
| 19 |
pip install gguf torch numpy
|
| 20 |
```
|
| 21 |
|
| 22 |
-
## Usage
|
| 23 |
|
| 24 |
```bash
|
| 25 |
python gguf_import.py \
|
| 26 |
-
--gguf /
|
| 27 |
-
--config /
|
| 28 |
--scale tiny \
|
| 29 |
--output ./imported_chimera.pt
|
| 30 |
```
|
| 31 |
|
| 32 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
```bash
|
|
|
|
| 35 |
python gguf_import.py \
|
| 36 |
--gguf model.gguf \
|
| 37 |
--config config.json \
|
| 38 |
-
--scale
|
| 39 |
-
--
|
| 40 |
-
--
|
| 41 |
-
--output ./model_chimera.pt
|
| 42 |
```
|
| 43 |
|
| 44 |
-
##
|
| 45 |
-
|
| 46 |
-
| Type | Status |
|
| 47 |
-
|---|---|
|
| 48 |
-
| F32 | ✅ Direct |
|
| 49 |
-
| F16 | ✅ Cast |
|
| 50 |
-
| BF16 | ✅ Cast |
|
| 51 |
-
| Q8_0 / Q8_1 | ✅ Dequantize |
|
| 52 |
-
| Q5_0 / Q5_1 | ✅ Dequantize |
|
| 53 |
-
| Q4_0 / Q4_1 | ✅ Dequantize |
|
| 54 |
-
| Q2_K / Q3_K / Q4_K / Q5_K / Q6_K | ✅ Via `gguf.dequantize` |
|
| 55 |
-
|
| 56 |
-
### Supported source architectures
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
##
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
- **`median_center`**: center by median, scale by MAD. Robust to heavy-tailed distributions.
|
| 68 |
-
- **`none`**: passthrough (useful if source is already clean).
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
```
|
| 74 |
-
α_m = mean(|W_m,:|)
|
| 75 |
-
W̃ = W / α
|
| 76 |
-
W_q = round_STE(W̃) ∈ {-1, 0, +1}
|
| 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 |
-
- **Output** (`output` → `lm_head`)
|
| 110 |
-
- **Norms** (`attn_norm`, `ffn_norm` → `attn_norm`, `mlp_norm`)
|
| 111 |
-
- **MLP** (`ffn_gate`, `ffn_up`, `ffn_down` → `mlp.gate_proj`, `mlp.up_proj`, `mlp.down_proj`)
|
| 112 |
-
- **Attention projections** (`attn_q`, `attn_k`, `attn_v`, `attn_output` → `attn.q_proj`, `k_proj`, `v_proj`, `o_proj`)
|
| 113 |
|
| 114 |
-
|
| 115 |
|
| 116 |
```bash
|
| 117 |
OMP_NUM_THREADS=20 python train.py \
|
|
@@ -120,3 +125,24 @@ OMP_NUM_THREADS=20 python train.py \
|
|
| 120 |
--max_tokens 50000000 --compile --no-bf16 --num_workers 0 \
|
| 121 |
--output_dir ./finetune_imported
|
| 122 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Chimera GGUF Import — v2.0 Optimized
|
| 2 |
|
| 3 |
+
Importer universel : convertit **n'importe quel modèle GGUF** (n'importe quelle quantisation, n'importe quelle architecture) en checkpoint compatible Chimera 5.1.
|
| 4 |
|
| 5 |
+
## Ce que fait le script
|
| 6 |
|
| 7 |
```
|
| 8 |
+
GGUF (Q4_0, Q5_1, Q8_0, F16, F32, BF16...)
|
| 9 |
+
→ Déquantification FP32 via gguf.dequantize()
|
| 10 |
+
→ Noise reduction (outlier-aware, par ligne ou global)
|
| 11 |
+
→ Conversion ternaire {-1, 0, +1} avec AbsMean par ligne
|
| 12 |
+
→ 2-bit packing (4 poids/byte = 16× réduction mémoire)
|
| 13 |
+
→ Checkpoint Chimera 5.1 (.pt)
|
| 14 |
```
|
| 15 |
|
| 16 |
+
## Installation
|
| 17 |
|
| 18 |
```bash
|
| 19 |
pip install gguf torch numpy
|
| 20 |
```
|
| 21 |
|
| 22 |
+
## Usage rapide
|
| 23 |
|
| 24 |
```bash
|
| 25 |
python gguf_import.py \
|
| 26 |
+
--gguf /chemin/vers/nimportequel-modele.gguf \
|
| 27 |
+
--config /chemin/vers/chimera/config.json \
|
| 28 |
--scale tiny \
|
| 29 |
--output ./imported_chimera.pt
|
| 30 |
```
|
| 31 |
|
| 32 |
+
## Modes de stockage
|
| 33 |
+
|
| 34 |
+
| Mode | Description | Quand l'utiliser |
|
| 35 |
+
|---|---|---|
|
| 36 |
+
| `fp32` (défaut) | Sauvegarde weight latent FP32 natif Chimera. Compatible avec `Chimera51ForCausalLM.load_state_dict()`. | **Recommandé** — le plus simple. |
|
| 37 |
+
| `packed` | Sauvegarde uniquement `packed_weight` + `alpha` pour les couches linéaires. **Nécessite un loader custom** dans Chimera. | Expérimental — checkpoint ultra-compact. |
|
| 38 |
+
| `both` | Sauvegarde les deux : weight FP32 + packed + alpha. | Pour migration progressive vers packed. |
|
| 39 |
|
| 40 |
```bash
|
| 41 |
+
# Mode packed (expérimental)
|
| 42 |
python gguf_import.py \
|
| 43 |
--gguf model.gguf \
|
| 44 |
--config config.json \
|
| 45 |
+
--scale tiny \
|
| 46 |
+
--storage packed \
|
| 47 |
+
--output ./chimera_packed.pt
|
|
|
|
| 48 |
```
|
| 49 |
|
| 50 |
+
## Réduction de bruit configurable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
| Méthode | Description | Par défaut |
|
| 53 |
+
|---|---|---|
|
| 54 |
+
| `row_outlier_clip` | Clip par ligne `mean ± 3σ` — préserve la structure locale des poids. | **✅ défaut** |
|
| 55 |
+
| `global_clip` | Clip global mean ± σ — plus agressif, moins de granularité. | |
|
| 56 |
+
| `median_center` | Center par médiane, scale par MAD — robuste aux distributions lourdes. | |
|
| 57 |
+
| `none` | Passthrough — si la source est déjà propre. | |
|
| 58 |
|
| 59 |
+
```bash
|
| 60 |
+
python gguf_import.py \
|
| 61 |
+
--gguf model.gguf \
|
| 62 |
+
--config config.json \
|
| 63 |
+
--noise-method row_outlier_clip \
|
| 64 |
+
--noise-sigma 2.5 \
|
| 65 |
+
--output ./model_chimera.pt
|
| 66 |
+
```
|
| 67 |
|
| 68 |
+
## Stratégies de resize
|
| 69 |
|
| 70 |
+
| Stratégie | Description | Par défaut |
|
| 71 |
+
|---|---|---|
|
| 72 |
+
| `crop_pad` | Copie les zones communes, init le reste avec des gaussiennes de même std. | **✅ défaut** |
|
| 73 |
+
| `interpolate` | Interpolation bilinéaire (préserve la structure spatiale). | |
|
| 74 |
+
| `strict` | Échoue si les shapes ne matchent exactement. | |
|
| 75 |
|
| 76 |
+
## Auto-transpose
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
Détecte automatiquement si les dimensions source et cible sont inversées (`[out, in]` vs `[in, out]`) et transpose silencieusement.
|
| 79 |
|
| 80 |
+
Désactiver avec `--no-auto-transpose`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
## Quantisations GGUF supportées
|
| 83 |
|
| 84 |
+
| Type | Statut |
|
| 85 |
+
|---|---|
|
| 86 |
+
| F32 | ✅ Direct |
|
| 87 |
+
| F16 | ✅ Cast |
|
| 88 |
+
| BF16 | ✅ Cast |
|
| 89 |
+
| Q8_0 / Q8_1 | ✅ Déquantification |
|
| 90 |
+
| Q5_0 / Q5_1 | ✅ Déquantification |
|
| 91 |
+
| Q4_0 / Q4_1 | ✅ Déquantification |
|
| 92 |
+
| Q2_K / Q3_K / Q4_K / Q5_K / Q6_K | ✅ Via `gguf.dequantize` |
|
| 93 |
|
| 94 |
+
## Architectures source supportées
|
| 95 |
|
| 96 |
+
Tout modèle GGUF : LLaMA, Qwen, Mistral, Phi, Gemma, DeepSeek, etc.
|
| 97 |
|
| 98 |
+
## Mapping GGUF → Chimera
|
| 99 |
|
| 100 |
+
| GGUF source | Chimera cible |
|
| 101 |
+
|---|---|
|
| 102 |
+
| `token_embd` | `embed.weight` |
|
| 103 |
+
| `output` | `lm_head.weight` |
|
| 104 |
+
| `output_norm` | `norm.weight` |
|
| 105 |
+
| `blk.N.attn_q/k/v/output` | `layers.N.attn.q/k/v/o_proj` |
|
| 106 |
+
| `blk.N.ffn_gate/up/down` | `layers.N.mlp.gate/up/down_proj` |
|
| 107 |
+
| `blk.N.attn_norm` | `layers.N.attn_norm` |
|
| 108 |
+
| `blk.N.ffn_norm` | `layers.N.mlp_norm` |
|
| 109 |
|
| 110 |
+
## Clés manquantes
|
| 111 |
|
| 112 |
+
Par défaut (`--no-init-missing` désactivé), toutes les couches Chimera absentes du GGUF source sont initialisées automatiquement :
|
| 113 |
+
- Norms : `torch.ones(...)`
|
| 114 |
+
- Embeddings/Head : `normal_(0, 0.02)`
|
| 115 |
+
- Linéaires BitLinear : `normal_(0, sqrt(2/fan_in))` + ternarisation
|
| 116 |
|
| 117 |
+
## Après import : fine-tuning obligatoire
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
Chimera utilise des couches récurrentes hybrides (GatedDeltaNet, xLSTM, Titans, TSP Span Knot) — **pas** du transformer standard. Le mapping QKV↔recurrence est intrinsèquement lossy. Fine-tunez avec MeZO sur CPU :
|
| 120 |
|
| 121 |
```bash
|
| 122 |
OMP_NUM_THREADS=20 python train.py \
|
|
|
|
| 125 |
--max_tokens 50000000 --compile --no-bf16 --num_workers 0 \
|
| 126 |
--output_dir ./finetune_imported
|
| 127 |
```
|
| 128 |
+
|
| 129 |
+
## Exemple complet
|
| 130 |
+
|
| 131 |
+
```bash
|
| 132 |
+
python gguf_import.py \
|
| 133 |
+
--gguf ./models/mistral-7b-q4_0.gguf \
|
| 134 |
+
--config ./chimera/config.json \
|
| 135 |
+
--scale tiny \
|
| 136 |
+
--storage fp32 \
|
| 137 |
+
--param-dtype fp32 \
|
| 138 |
+
--noise-method row_outlier_clip \
|
| 139 |
+
--noise-sigma 3.0 \
|
| 140 |
+
--ternary-threshold 0.5 \
|
| 141 |
+
--resize-strategy crop_pad \
|
| 142 |
+
--output ./mistral_chimera_tiny.pt
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
## Dépôt
|
| 146 |
+
|
| 147 |
+
- Repo HuggingFace : [`Lgr54HFi/chimera-gguf-import`](https://huggingface.co/Lgr54HFi/chimera-gguf-import)
|
| 148 |
+
- Version : 2.0-optimized
|