{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "colab": {
   "name": "Ares_General_20M_Colab.ipynb"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ares general-language 20M-class training experiment\n",
    "\n",
    "A from-scratch, interruptible Colab experiment. This trains a small model and is not a claim of AGI or production readiness.\n"
   ],
   "execution_count": null,
   "outputs": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "!nvidia-smi || true\n",
    "!rm -rf ares-lab\n",
    "!git clone --depth 1 https://huggingface.co/spaces/jacmor64/Ares-Lab ares-lab\n",
    "%cd ares-lab\n",
    "!pip -q install torch tqdm datasets\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Read and edit the corpus design manifest before selecting any sources.\n",
    "import json\n",
    "manifest=json.load(open('datasets/manifest_v1.json'))\n",
    "print(json.dumps(manifest,indent=2))\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Required human governance gate: read data/general_manifest.json and the current dataset card first.\n",
    "# Set this only after you have reviewed licence, terms, provenance, and intended use.\n",
    "I_HAVE_REVIEWED_THE_DATASET = False\n",
    "assert I_HAVE_REVIEWED_THE_DATASET, 'Review required: do not download/train until you consciously set this True.'\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Stream a bounded sample rather than download the entire source.\n",
    "from datasets import load_dataset\n",
    "import json\n",
    "stream=load_dataset('roneneldan/TinyStories', split='train', streaming=True)\n",
    "with open('data/raw.jsonl','w',encoding='utf8') as f:\n",
    "    for i,row in enumerate(stream):\n",
    "        if i >= 10000: break\n",
    "        f.write(json.dumps({'text':row['text']},ensure_ascii=False)+'\\n')\n",
    "print('Wrote 10,000 streamed examples')\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "!python -m ares.data_pipeline --input data/raw.jsonl --out data/clean.jsonl --audit data/audit.json --approved\n",
    "!python - <<'PY'\n",
    "import json\n",
    "from pathlib import Path\n",
    "Path('corpus/train').mkdir(parents=True,exist_ok=True)\n",
    "Path('corpus/valid').mkdir(parents=True,exist_ok=True)\n",
    "rows=[json.loads(x)['text'] for x in open('data/clean.jsonl',encoding='utf8')]\n",
    "cut=int(.98*len(rows))\n",
    "Path('corpus/train/train.txt').write_text('\\n'.join(rows[:cut]))\n",
    "Path('corpus/valid/valid.txt').write_text('\\n'.join(rows[cut:]))\n",
    "PY\n",
    "!python -m ares.tokenizer train --input corpus --out artifacts/tokenizer-512.json --vocab-size 512\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "# Approximately 18\u201320M parameters: dim 384, 12 decoder blocks, GQA, RoPE, SwiGLU.\n",
    "# Save checkpoints regularly; free Colab sessions may disconnect.\n",
    "!python -m ares.train --role ares --tokenizer artifacts/tokenizer-512.json --data corpus/train --validation-data corpus/valid --out runs/ares-general-20m --steps 5000 --batch-size 4 --seq-len 256 --dim 384 --layers 12 --heads 6 --kv-heads 2 --lr 0.0003 --dropout 0.1 --eval-every 100 --patience 8\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "!python -m ares.evaluate --checkpoint runs/ares-general-20m/latest.pt --tokenizer artifacts/tokenizer-512.json --text corpus/valid/valid.txt\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Next gate\n",
    "Only after measuring held-out loss, inspecting outputs, and completing safety evaluations should we add more data, context length, or Ares SFT. Xiphos must receive its own planning-oriented corpus and independent evaluation.\n"
   ],
   "execution_count": null,
   "outputs": null
  }
 ]
}