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
|
| 7 |
+
- qlora
|
| 8 |
+
- abliteration
|
| 9 |
+
- sft
|
| 10 |
+
- dpo
|
| 11 |
+
- recipes
|
| 12 |
+
- alien-si
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Alien SI — Rețete complete de antrenare
|
| 16 |
+
|
| 17 |
+
**Autor: Barbu Mario Mihael**
|
| 18 |
+
|
| 19 |
+
Acest repo conține **toate rețetele, notebook-urile și configurațiile** folosite pentru a construi
|
| 20 |
+
**Alien SI** — un lanț de modele frontier offensive antrenate pe hardware gratuit (Kaggle T4×2).
|
| 21 |
+
|
| 22 |
+
Dacă ai găsit o rețetă bună aici și vrei să continui — tot ce ai nevoie e în acest repo.
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Ce este Alien SI
|
| 27 |
+
|
| 28 |
+
Un model frontier offensiv de 27B, bazat pe `Qwen/Qwen3.8-27B`, construit în etape:
|
| 29 |
+
|
| 30 |
+
1. **LoRA QLoRA** (continue-pretrain + SFT pe date cyber/red-team)
|
| 31 |
+
2. **Abliteration** (diff-in-means, eliminarea refuzurilor)
|
| 32 |
+
3. **SFT red-team** (post-training, răspunsuri tehnice)
|
| 33 |
+
4. **DPO preferință** (chosen=tehnic vs rejected=refuz)
|
| 34 |
+
5. **Intent-aware** (înțelege prompturi ambigue)
|
| 35 |
+
|
| 36 |
+
**Rezultat:** zero refuzuri, foarte precis, înțelege intenția peste textul literal.
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## Lanțul de kernel-uri (X1 → X14)
|
| 41 |
+
|
| 42 |
+
Fiecare kernel e un notebook autonom care consumă output-ul precedentului (chaining prin `kernel_sources`).
|
| 43 |
+
|
| 44 |
+
| Kernel | Rol | Fișier |
|
| 45 |
+
|---|---|---|
|
| 46 |
+
| X1–X3 | Scrapere date + pretrain cyber | `mythos_x1.ipynb` … `mythos_x3.ipynb` |
|
| 47 |
+
| X4 | Continue-pretrain SmolLM2 (cyber) | `mythos_x4.ipynb` |
|
| 48 |
+
| X5–X7 | Instruct cyber + tool-use | `mythos_x5.ipynb` … `mythos_x7.ipynb` |
|
| 49 |
+
| X8 | Vision (text-only circuits) | `mythos_x8.ipynb` |
|
| 50 |
+
| X9 | Autonomous | `mythos_x9.ipynb` |
|
| 51 |
+
| X10 | Fusion (model soup / TIES) | `mythos_x10.ipynb` |
|
| 52 |
+
| X11 | Qwen3-8B QLoRA | `mythos_x11.ipynb` |
|
| 53 |
+
| X12 | Qwen3.8-27B | `mythos_x12.ipynb` |
|
| 54 |
+
| **X13** | **27B train + abliterate** | `mythos_x13.ipynb` |
|
| 55 |
+
| **X14** | **27B abliterate + SFT + DPO (Alien SI final)** | `mythos_x14.ipynb` |
|
| 56 |
+
| v3–v6 | MihaEL 8B (SFT+DPO) | `mihael_v*.ipynb` |
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
## Rețeta de bază (TL;DR)
|
| 61 |
+
|
| 62 |
+
### Hardware
|
| 63 |
+
- **Kaggle T4×2** (Turing sm_75) — `fp16` DA, `bf16` NU, FlashAttention-2 NU → folosește `sdpa`
|
| 64 |
+
- 2 sesiuni GPU simultan max, ~12h/sesiune, 30h/săptămână, **gratis**
|
| 65 |
+
|
| 66 |
+
### Instalare
|
| 67 |
+
```bash
|
| 68 |
+
pip install -U unsloth unsloth_zoo
|
| 69 |
+
pip install "transformers>=5.15.1" trl datasets
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### Pas 1 — Încărcare 27B 4-bit
|
| 73 |
+
```python
|
| 74 |
+
from unsloth import FastLanguageModel
|
| 75 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 76 |
+
model_name="Qwen/Qwen3.8-27B", max_seq_length=1024, load_in_4bit=True)
|
| 77 |
+
```
|
| 78 |
+
> **Pitfall:** Unsloth forțează `float32` pe `qwen3_5` (fp16 nu merge). Peak ~24 GB → încape pe 2×T4.
|
| 79 |
+
|
| 80 |
+
### Pas 2 — Găsirea straturilor (arhitectură HIBRIDĂ)
|
| 81 |
+
`Qwen3_5ForConditionalGeneration` **NU are** `model.layers`. Calea reală e:
|
| 82 |
+
```python
|
| 83 |
+
model.model.language_model.layers # 64 straturi, Qwen3_5DecoderLayer
|
| 84 |
+
```
|
| 85 |
+
Caută dinamic prin mai multe căi (vezi `mythos_x14.ipynb` celula 3).
|
| 86 |
+
|
| 87 |
+
### Pas 3 — Abliteration (diff-in-means)
|
| 88 |
+
```python
|
| 89 |
+
# 1. Colectează activări harmful vs benign (hook pe ultimul token)
|
| 90 |
+
# 2. Direcția de refuz: refusal = A_harmful.mean(0) - A_benign.mean(0)
|
| 91 |
+
# 3. Ortogonalizează proiecțiile de scriere
|
| 92 |
+
```
|
| 93 |
+
> **Pitfall critic:** NU hardcoda `self_attn.o_proj` — pe Qwen3.5 nu există!
|
| 94 |
+
> Iterează `named_modules()`, ia doar `nn.Linear` **pătrate** cu `numel < 60M`.
|
| 95 |
+
> Altfel prinzi `embed_tokens` și încerci să aloci **212 GiB** → OOM instant.
|
| 96 |
+
|
| 97 |
+
### Pas 4 — SFT red-team
|
| 98 |
+
```python
|
| 99 |
+
FastLanguageModel.get_peft_model(model, r=32, lora_alpha=64,
|
| 100 |
+
target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"])
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Pas 5 — DPO (fix OOM obligatoriu)
|
| 104 |
+
```python
|
| 105 |
+
DPOConfig(max_length=512, max_prompt_length=256,
|
| 106 |
+
precompute_ref_log_probs=True, use_liger_loss=False)
|
| 107 |
+
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
| 108 |
+
```
|
| 109 |
+
> **Pitfall:** DPO default `max_length=2048` → `entropy_from_logits` alocă 2.32 GiB → OOM pe T4.
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## Pitfalls întâlnite (toate reparate)
|
| 114 |
+
|
| 115 |
+
1. **`device-side assert` / gather OOB** — token hardcodat `50256` (GPT-2 EOT) pe SmolLM2 (vocab 49152). Folosește `tok.eos_token_id`.
|
| 116 |
+
2. **`Attempting to unscale FP16 gradients`** — pe Turing, `autocast(fp16)` + `GradScaler`. Dezactivează scaler-ul (`enabled=False`).
|
| 117 |
+
3. **VLM tokenizer routing** — Unsloth patchează tokenizer-ul → rutează apelul către `processor(images, text,...)` → textul ajunge în parametrul `images`. Folosește `AutoTokenizer` brut.
|
| 118 |
+
4. **`'Qwen3_5Model' has no attribute 'layers'`** — arhitectură multimodală. Găsire dinamică.
|
| 119 |
+
5. **OOM 212 GiB la abliteration** — proiecție greșită (`embed_tokens`). Filtrează după formă pătrată + dimensiune.
|
| 120 |
+
6. **DPO OOM** — vezi Pas 5.
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## Scripturi
|
| 125 |
+
|
| 126 |
+
- `orchestrator.sh` — pornește următorul kernel din coadă când se eliberează un slot GPU
|
| 127 |
+
- `monitor.sh` — urmărește tranzițiile de stare
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
## Rapoarte de cercetare
|
| 132 |
+
|
| 133 |
+
Vezi `research-reports/`:
|
| 134 |
+
- `raport_circuite_ultron.md` — circuite/hardware
|
| 135 |
+
- `raport_frontier.md` — modele frontier 2025-2026
|
| 136 |
+
- `raport_qwen3_impl.md` — implementare Qwen3
|
| 137 |
+
- `raport_qwen38_27b.md` — Qwen3.8-27B specifics
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## Continuare
|
| 142 |
+
|
| 143 |
+
Toate notebook-urile sunt autonome și pot fi re-rulate pe Kaggle. Pentru a relua lanțul:
|
| 144 |
+
1. Urcă un notebook pe Kaggle (`kaggle kernels push -p .`)
|
| 145 |
+
2. Setează `kernel_sources` la output-ul precedentului
|
| 146 |
+
3. Pornește cu `kaggle kernels push`
|
| 147 |
+
|
| 148 |
+
**Alien SI** — creat de **Barbu Mario Mihael**.
|