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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"provenance": [],
|
| 7 |
+
"gpuType": "T4"
|
| 8 |
+
},
|
| 9 |
+
"kernelspec": {
|
| 10 |
+
"name": "python3",
|
| 11 |
+
"display_name": "Python 3"
|
| 12 |
+
},
|
| 13 |
+
"language_info": {
|
| 14 |
+
"name": "python"
|
| 15 |
+
},
|
| 16 |
+
"accelerator": "GPU"
|
| 17 |
+
},
|
| 18 |
+
"cells": [
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "markdown",
|
| 21 |
+
"metadata": {},
|
| 22 |
+
"source": [
|
| 23 |
+
"# AETHER: Self-Evolving Neuro-Symbolic AGI Training\n",
|
| 24 |
+
"\n",
|
| 25 |
+
"**Run this in Google Colab (free T4 GPU)**\n",
|
| 26 |
+
"\n",
|
| 27 |
+
"This notebook trains a Qwen 0.5B model with AETHER's neuro-symbolic reward function using TRL GRPO.\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"**What you'll get:**\n",
|
| 30 |
+
"- Fine-tuned model pushed to your HuggingFace Hub\n",
|
| 31 |
+
"- Live training metrics via Trackio\n",
|
| 32 |
+
"- AETHER evolutionary architecture components\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"**Estimated time:** 2-3 hours on Colab T4\n",
|
| 35 |
+
"\n",
|
| 36 |
+
"**Paper integrations:** AlphaEvolve, HiMAC, GEA, Yunjue Agent, ASI-Evolve, CoALA, MLPO, BabyAGI, Agentic Neural Networks, CoMAS"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"cell_type": "markdown",
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"source": [
|
| 43 |
+
"## Step 1: Authenticate with HuggingFace\n",
|
| 44 |
+
"\n",
|
| 45 |
+
"Get your token from https://huggingface.co/settings/tokens (needs `write` scope)"
|
| 46 |
+
]
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"cell_type": "code",
|
| 50 |
+
"execution_count": null,
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"outputs": [],
|
| 53 |
+
"source": [
|
| 54 |
+
"from huggingface_hub import notebook_login\n",
|
| 55 |
+
"notebook_login()"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "markdown",
|
| 60 |
+
"metadata": {},
|
| 61 |
+
"source": [
|
| 62 |
+
"## Step 2: Install Dependencies"
|
| 63 |
+
]
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"cell_type": "code",
|
| 67 |
+
"execution_count": null,
|
| 68 |
+
"metadata": {},
|
| 69 |
+
"outputs": [],
|
| 70 |
+
"source": [
|
| 71 |
+
"!pip install -q torch transformers datasets accelerate peft trl networkx numpy sentencepiece protobuf\n",
|
| 72 |
+
"print(\"Dependencies installed!\")"
|
| 73 |
+
]
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"cell_type": "markdown",
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"source": [
|
| 79 |
+
"## Step 3: Clone AETHER Repository"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"cell_type": "code",
|
| 84 |
+
"execution_count": null,
|
| 85 |
+
"metadata": {},
|
| 86 |
+
"outputs": [],
|
| 87 |
+
"source": [
|
| 88 |
+
"!git clone https://huggingface.co/camdog920/aether-core\n",
|
| 89 |
+
"%cd aether-core\n",
|
| 90 |
+
"!ls -la"
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"cell_type": "markdown",
|
| 95 |
+
"metadata": {},
|
| 96 |
+
"source": [
|
| 97 |
+
"## Step 4: Verify GPU & Setup"
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"cell_type": "code",
|
| 102 |
+
"execution_count": null,
|
| 103 |
+
"metadata": {},
|
| 104 |
+
"outputs": [],
|
| 105 |
+
"source": [
|
| 106 |
+
"import torch\n",
|
| 107 |
+
"print(f\"CUDA available: {torch.cuda.is_available()}\")\n",
|
| 108 |
+
"print(f\"GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}\")\n",
|
| 109 |
+
"print(f\"GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB\" if torch.cuda.is_available() else \"\")\n",
|
| 110 |
+
"\n",
|
| 111 |
+
"# Set environment variables\n",
|
| 112 |
+
"import os\n",
|
| 113 |
+
"os.environ['AETHER_MODEL'] = 'Qwen/Qwen2.5-0.5B-Instruct'\n",
|
| 114 |
+
"os.environ['AETHER_OUTPUT'] = './aether-output'\n",
|
| 115 |
+
"os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"cell_type": "markdown",
|
| 120 |
+
"metadata": {},
|
| 121 |
+
"source": [
|
| 122 |
+
"## Step 5: Import AETHER Components & Build Knowledge Graph"
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"cell_type": "code",
|
| 127 |
+
"execution_count": null,
|
| 128 |
+
"metadata": {},
|
| 129 |
+
"outputs": [],
|
| 130 |
+
"source": [
|
| 131 |
+
"import sys\n",
|
| 132 |
+
"sys.path.insert(0, '.')\n",
|
| 133 |
+
"\n",
|
| 134 |
+
"from aether.core import AetherCore, AetherConfig\n",
|
| 135 |
+
"from aether.knowledge import KnowledgeGraphEngine\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"# Initialize AETHER with evolution enabled\n",
|
| 138 |
+
"config = AetherConfig(\n",
|
| 139 |
+
" population_size=8,\n",
|
| 140 |
+
" generations=5,\n",
|
| 141 |
+
" mutation_rate=0.15,\n",
|
| 142 |
+
" learning_rate=2e-5,\n",
|
| 143 |
+
" macro_policy_dim=256,\n",
|
| 144 |
+
" micro_policy_dim=128,\n",
|
| 145 |
+
" num_agents=4,\n",
|
| 146 |
+
" enable_self_modification=True,\n",
|
| 147 |
+
" enable_parallel_agents=True,\n",
|
| 148 |
+
")\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"aether = AetherCore(config, model_name='Qwen/Qwen2.5-0.5B-Instruct')\n",
|
| 151 |
+
"print(f\"AETHER initialized: v{aether.metadata['version']}\")\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"# Seed knowledge graph with AGI ontology\n",
|
| 154 |
+
"agi_facts = [\n",
|
| 155 |
+
" ('AETHER', 'is_a', 'AGI_System'),\n",
|
| 156 |
+
" ('AETHER', 'has_component', 'Knowledge_Graph'),\n",
|
| 157 |
+
" ('AETHER', 'has_component', 'Neural_Network'),\n",
|
| 158 |
+
" ('AETHER', 'has_component', 'Evolution_Engine'),\n",
|
| 159 |
+
" ('AETHER', 'has_component', 'Safety_Sandbox'),\n",
|
| 160 |
+
" ('Knowledge_Graph', 'enables', 'Symbolic_Reasoning'),\n",
|
| 161 |
+
" ('Neural_Network', 'enables', 'Pattern_Learning'),\n",
|
| 162 |
+
" ('Evolution_Engine', 'optimizes', 'Architecture'),\n",
|
| 163 |
+
" ('Safety_Sandbox', 'constrains', 'Self_Modification'),\n",
|
| 164 |
+
" ('Symbolic_Reasoning', 'complements', 'Pattern_Learning'),\n",
|
| 165 |
+
" ('AlphaEvolve', 'inspires', 'Evolution_Engine'),\n",
|
| 166 |
+
" ('HiMAC', 'inspires', 'Hierarchical_Policy'),\n",
|
| 167 |
+
" ('GEA', 'inspires', 'Group_Evolution'),\n",
|
| 168 |
+
" ('BabyAGI', 'inspires', 'Task_Loop'),\n",
|
| 169 |
+
"]\n",
|
| 170 |
+
"\n",
|
| 171 |
+
"for h, r, t in agi_facts:\n",
|
| 172 |
+
" aether.knowledge.add_fact(h, r, t, confidence=1.0)\n",
|
| 173 |
+
"\n",
|
| 174 |
+
"print(f\"Knowledge graph: {aether.knowledge.stats()}\")"
|
| 175 |
+
]
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"cell_type": "markdown",
|
| 179 |
+
"metadata": {},
|
| 180 |
+
"source": [
|
| 181 |
+
"## Step 6: Define AETHER Neuro-Symbolic Reward Function"
|
| 182 |
+
]
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"cell_type": "code",
|
| 186 |
+
"execution_count": null,
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"outputs": [],
|
| 189 |
+
"source": [
|
| 190 |
+
"import re\n",
|
| 191 |
+
"from typing import List\n",
|
| 192 |
+
"\n",
|
| 193 |
+
"def aether_reward(completions: List[str], **kwargs) -> List[float]:\n",
|
| 194 |
+
" \\"\\"\\n",
|
| 195 |
+
" AETHER neuro-symbolic reward function.\n",
|
| 196 |
+
" Integrates: reasoning structure, step enumeration, causal language,\n",
|
| 197 |
+
" sub-goal planning, meta-cognition.\n",
|
| 198 |
+
" \\"\\"\\n",
|
| 199 |
+
" rewards = []\n",
|
| 200 |
+
" for completion in completions:\n",
|
| 201 |
+
" score = 0.0\n",
|
| 202 |
+
" text = completion if isinstance(completion, str) else str(completion)\n",
|
| 203 |
+
" \n",
|
| 204 |
+
" # 1. Reasoning structure: ε°ι tags (DeepSeek-R1 style)\n",
|
| 205 |
+
" if ' ε°ι' in text and ' ε€§ι' in text:\n",
|
| 206 |
+
" score += 0.30\n",
|
| 207 |
+
" \n",
|
| 208 |
+
" # 2. Step enumeration\n",
|
| 209 |
+
" steps = sum(1 for s in text.split('\\n')\n",
|
| 210 |
+
" if any(s.strip().startswith(p) for p in ['1.', '2.', '3.', '4.', '5.', 'Step', 'Phase']))\n",
|
| 211 |
+
" score += min(steps * 0.05, 0.25)\n",
|
| 212 |
+
" \n",
|
| 213 |
+
" # 3. Knowledge/causal reasoning markers\n",
|
| 214 |
+
" if any(kw in text.lower() for kw in ['therefore', 'because', 'implies', 'consequently', 'thus', 'hence']):\n",
|
| 215 |
+
" score += 0.20\n",
|
| 216 |
+
" \n",
|
| 217 |
+
" # 4. Sub-goal / blueprint structure (HiMAC-style hierarchical planning)\n",
|
| 218 |
+
" if any(kw in text.lower() for kw in ['sub-goal', 'blueprint', 'plan', 'phase', 'macro', 'micro']):\n",
|
| 219 |
+
" score += 0.15\n",
|
| 220 |
+
" \n",
|
| 221 |
+
" # 5. Self-reflection / meta-cognition / evolution\n",
|
| 222 |
+
" if any(kw in text.lower() for kw in ['reflect', 'evaluate', 'improve', 'evolve', 'optimize']):\n",
|
| 223 |
+
" score += 0.10\n",
|
| 224 |
+
" \n",
|
| 225 |
+
" rewards.append(min(score, 1.0))\n",
|
| 226 |
+
" return rewards\n",
|
| 227 |
+
"\n",
|
| 228 |
+
"# Test\n",
|
| 229 |
+
"test_completions = [\n",
|
| 230 |
+
" ' ε°ιStep 1: Analyze problem. Step 2: Build knowledge graph. Therefore, the answer is 42. ε€§ι',\n",
|
| 231 |
+
" 'The answer is 42.',\n",
|
| 232 |
+
"]\n",
|
| 233 |
+
"print('Reward test:', aether_reward(test_completions))"
|
| 234 |
+
]
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"cell_type": "markdown",
|
| 238 |
+
"metadata": {},
|
| 239 |
+
"source": [
|
| 240 |
+
"## Step 7: Load Dataset & Model"
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"cell_type": "code",
|
| 245 |
+
"execution_count": null,
|
| 246 |
+
"metadata": {},
|
| 247 |
+
"outputs": [],
|
| 248 |
+
"source": [
|
| 249 |
+
"from datasets import load_dataset\n",
|
| 250 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 251 |
+
"\n",
|
| 252 |
+
"MODEL_NAME = 'Qwen/Qwen2.5-0.5B-Instruct'\n",
|
| 253 |
+
"\n",
|
| 254 |
+
"# Load dataset\n",
|
| 255 |
+
"print('Loading dataset...')\n",
|
| 256 |
+
"try:\n",
|
| 257 |
+
" dataset = load_dataset('trl-lib/DeepMath-103K', split='train')\n",
|
| 258 |
+
" print(f'Loaded DeepMath-103K: {len(dataset)} examples')\n",
|
| 259 |
+
"except Exception as e:\n",
|
| 260 |
+
" print(f'DeepMath failed: {e}')\n",
|
| 261 |
+
" dataset = load_dataset('trl-lib/Capybara', split='train')\n",
|
| 262 |
+
" print(f'Loaded Capybara: {len(dataset)} examples')\n",
|
| 263 |
+
"\n",
|
| 264 |
+
"# Convert messages to prompt if needed\n",
|
| 265 |
+
"if 'messages' in dataset.column_names and 'prompt' not in dataset.column_names:\n",
|
| 266 |
+
" def extract_prompt(examples):\n",
|
| 267 |
+
" prompts = []\n",
|
| 268 |
+
" for msgs in examples['messages']:\n",
|
| 269 |
+
" user_msg = next((m['content'] for m in msgs if m.get('role') == 'user'), str(msgs))\n",
|
| 270 |
+
" prompts.append(user_msg)\n",
|
| 271 |
+
" return {'prompt': prompts}\n",
|
| 272 |
+
" dataset = dataset.map(extract_prompt, batched=True, remove_columns=dataset.column_names)\n",
|
| 273 |
+
"elif 'text' in dataset.column_names and 'prompt' not in dataset.column_names:\n",
|
| 274 |
+
" dataset = dataset.rename_column('text', 'prompt')\n",
|
| 275 |
+
"\n",
|
| 276 |
+
"# Split\n",
|
| 277 |
+
"dataset = dataset.train_test_split(test_size=0.1)\n",
|
| 278 |
+
"train_ds = dataset['train']\n",
|
| 279 |
+
"eval_ds = dataset['test']\n",
|
| 280 |
+
"print(f'Train: {len(train_ds)}, Eval: {len(eval_ds)}')\n",
|
| 281 |
+
"\n",
|
| 282 |
+
"# Load model\n",
|
| 283 |
+
"print('Loading model...')\n",
|
| 284 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 285 |
+
" MODEL_NAME,\n",
|
| 286 |
+
" torch_dtype=torch.bfloat16,\n",
|
| 287 |
+
" device_map='auto',\n",
|
| 288 |
+
" trust_remote_code=True,\n",
|
| 289 |
+
")\n",
|
| 290 |
+
"tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)\n",
|
| 291 |
+
"if tokenizer.pad_token is None:\n",
|
| 292 |
+
" tokenizer.pad_token = tokenizer.eos_token\n",
|
| 293 |
+
"\n",
|
| 294 |
+
"print(f'Model loaded: {sum(p.numel() for p in model.parameters()) / 1e6:.0f}M parameters')"
|
| 295 |
+
]
|
| 296 |
+
},
|
| 297 |
+
{
|
| 298 |
+
"cell_type": "markdown",
|
| 299 |
+
"metadata": {},
|
| 300 |
+
"source": [
|
| 301 |
+
"## Step 8: Initialize GRPO Trainer with AETHER Rewards"
|
| 302 |
+
]
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"cell_type": "code",
|
| 306 |
+
"execution_count": null,
|
| 307 |
+
"metadata": {},
|
| 308 |
+
"outputs": [],
|
| 309 |
+
"source": [
|
| 310 |
+
"from trl import GRPOTrainer, GRPOConfig\n",
|
| 311 |
+
"from trl.rewards import accuracy_reward, think_format_reward\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"# Training configuration\n",
|
| 314 |
+
"training_args = GRPOConfig(\n",
|
| 315 |
+
" output_dir='./aether-output',\n",
|
| 316 |
+
" num_train_epochs=1,\n",
|
| 317 |
+
" per_device_train_batch_size=1,\n",
|
| 318 |
+
" per_device_eval_batch_size=1,\n",
|
| 319 |
+
" gradient_accumulation_steps=8,\n",
|
| 320 |
+
" learning_rate=2e-5,\n",
|
| 321 |
+
" logging_steps=10,\n",
|
| 322 |
+
" save_steps=200,\n",
|
| 323 |
+
" eval_strategy='steps',\n",
|
| 324 |
+
" eval_steps=100,\n",
|
| 325 |
+
" bf16=True,\n",
|
| 326 |
+
" max_completion_length=512,\n",
|
| 327 |
+
" num_generations=4,\n",
|
| 328 |
+
" report_to=[], # Disable wandb/tensorboard - we'll use manual logging\n",
|
| 329 |
+
" run_name='aether-grpo-qwen-0.5b',\n",
|
| 330 |
+
" disable_tqdm=False, # Show progress bar in Colab\n",
|
| 331 |
+
" logging_first_step=True,\n",
|
| 332 |
+
" push_to_hub=True,\n",
|
| 333 |
+
" hub_model_id='camdog920/aether-qwen-0.5b-grpo', # CHANGE THIS to your username!\n",
|
| 334 |
+
")\n",
|
| 335 |
+
"\n",
|
| 336 |
+
"# Reward functions: AETHER custom + TRL built-ins\n",
|
| 337 |
+
"reward_funcs = [\n",
|
| 338 |
+
" aether_reward, # AETHER neuro-symbolic reward (reasoning structure)\n",
|
| 339 |
+
" accuracy_reward, # TRL: answer correctness\n",
|
| 340 |
+
" think_format_reward, # TRL: ε°ι/ ε€§ι format\n",
|
| 341 |
+
"]\n",
|
| 342 |
+
"\n",
|
| 343 |
+
"# Initialize trainer\n",
|
| 344 |
+
"trainer = GRPOTrainer(\n",
|
| 345 |
+
" model=model,\n",
|
| 346 |
+
" reward_funcs=reward_funcs,\n",
|
| 347 |
+
" args=training_args,\n",
|
| 348 |
+
" train_dataset=train_ds,\n",
|
| 349 |
+
" eval_dataset=eval_ds,\n",
|
| 350 |
+
")\n",
|
| 351 |
+
"\n",
|
| 352 |
+
"print('GRPO Trainer initialized!')\n",
|
| 353 |
+
"print(f'Reward functions: {len(reward_funcs)}')\n",
|
| 354 |
+
"print(f'Train steps: ~{len(train_ds) // 8}')"
|
| 355 |
+
]
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"cell_type": "markdown",
|
| 359 |
+
"metadata": {},
|
| 360 |
+
"source": [
|
| 361 |
+
"## Step 9: Train!\n",
|
| 362 |
+
"\n",
|
| 363 |
+
"This will take 2-3 hours on Colab T4. The model will be saved every 200 steps and pushed to Hub at the end."
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"cell_type": "code",
|
| 368 |
+
"execution_count": null,
|
| 369 |
+
"metadata": {},
|
| 370 |
+
"outputs": [],
|
| 371 |
+
"source": [
|
| 372 |
+
"# Start training\n",
|
| 373 |
+
"trainer.train()\n",
|
| 374 |
+
"\n",
|
| 375 |
+
"# Save final model\n",
|
| 376 |
+
"trainer.save_model('./aether-output')\n",
|
| 377 |
+
"tokenizer.save_pretrained('./aether-output')\n",
|
| 378 |
+
"\n",
|
| 379 |
+
"print('Training complete!')\n",
|
| 380 |
+
"print('Model saved to ./aether-output')"
|
| 381 |
+
]
|
| 382 |
+
},
|
| 383 |
+
{
|
| 384 |
+
"cell_type": "markdown",
|
| 385 |
+
"metadata": {},
|
| 386 |
+
"source": [
|
| 387 |
+
"## Step 10: Quick Evaluation & Test"
|
| 388 |
+
]
|
| 389 |
+
},
|
| 390 |
+
{
|
| 391 |
+
"cell_type": "code",
|
| 392 |
+
"execution_count": null,
|
| 393 |
+
"metadata": {},
|
| 394 |
+
"outputs": [],
|
| 395 |
+
"source": [
|
| 396 |
+
"# Test the trained model with AETHER reasoning\n",
|
| 397 |
+
"test_prompts = [\n",
|
| 398 |
+
" 'Think step by step: What is 17 + 25?',\n",
|
| 399 |
+
" 'Plan and solve: A farmer has 3 fields. Each field produces 42 bushels. How many total bushels?',\n",
|
| 400 |
+
" 'Reflect and improve: Your previous answer was 50. The correct answer is 60. What went wrong?',\n",
|
| 401 |
+
"]\n",
|
| 402 |
+
"\n",
|
| 403 |
+
"model.eval()\n",
|
| 404 |
+
"for prompt in test_prompts:\n",
|
| 405 |
+
" inputs = tokenizer(prompt, return_tensors='pt').to(model.device)\n",
|
| 406 |
+
" with torch.no_grad():\n",
|
| 407 |
+
" outputs = model.generate(\n",
|
| 408 |
+
" **inputs,\n",
|
| 409 |
+
" max_new_tokens=256,\n",
|
| 410 |
+
" do_sample=True,\n",
|
| 411 |
+
" temperature=0.7,\n",
|
| 412 |
+
" )\n",
|
| 413 |
+
" response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
|
| 414 |
+
" print(f\"\\nPrompt: {prompt}\")\n",
|
| 415 |
+
" print(f\"Response: {response[len(prompt):].strip()}\")\n",
|
| 416 |
+
" print('-' * 60)"
|
| 417 |
+
]
|
| 418 |
+
},
|
| 419 |
+
{
|
| 420 |
+
"cell_type": "markdown",
|
| 421 |
+
"metadata": {},
|
| 422 |
+
"source": [
|
| 423 |
+
"## Step 11: Push to Hub (if not auto-pushed)"
|
| 424 |
+
]
|
| 425 |
+
},
|
| 426 |
+
{
|
| 427 |
+
"cell_type": "code",
|
| 428 |
+
"execution_count": null,
|
| 429 |
+
"metadata": {},
|
| 430 |
+
"outputs": [],
|
| 431 |
+
"source": [
|
| 432 |
+
"from huggingface_hub import HfApi\n",
|
| 433 |
+
"\n",
|
| 434 |
+
"api = HfApi()\n",
|
| 435 |
+
"api.upload_folder(\n",
|
| 436 |
+
" folder_path='./aether-output',\n",
|
| 437 |
+
" repo_id='camdog920/aether-qwen-0.5b-grpo', # CHANGE to your repo!\n",
|
| 438 |
+
" repo_type='model',\n",
|
| 439 |
+
")\n",
|
| 440 |
+
"print('Model pushed to HuggingFace Hub!')"
|
| 441 |
+
]
|
| 442 |
+
},
|
| 443 |
+
{
|
| 444 |
+
"cell_type": "markdown",
|
| 445 |
+
"metadata": {},
|
| 446 |
+
"source": [
|
| 447 |
+
"## Step 12: AETHER Self-Reflection (Post-Training)\n",
|
| 448 |
+
"\n",
|
| 449 |
+
"Use the AETHER core to analyze the training run."
|
| 450 |
+
]
|
| 451 |
+
},
|
| 452 |
+
{
|
| 453 |
+
"cell_type": "code",
|
| 454 |
+
"execution_count": null,
|
| 455 |
+
"metadata": {},
|
| 456 |
+
"outputs": [],
|
| 457 |
+
"source": [
|
| 458 |
+
"# Run AETHER self-reflection\n",
|
| 459 |
+
"reflection = aether.self_reflect()\n",
|
| 460 |
+
"\n",
|
| 461 |
+
"print('AETHER Self-Reflection:')\n",
|
| 462 |
+
"print(f\"Generation: {reflection['generation']}\")\n",
|
| 463 |
+
"print(f\"Architectures tested: {reflection['total_architectures_tested']}\")\n",
|
| 464 |
+
"print(f\"Fitness trend: {reflection['fitness_trend'][-5:] if reflection['fitness_trend'] else 'N/A'}\")\n",
|
| 465 |
+
"print(f\"Neuro-symbolic balance:\")\n",
|
| 466 |
+
"print(f\" Symbolic: {reflection['neuro_symbolic_balance']['symbolic_gate']:.3f}\")\n",
|
| 467 |
+
"print(f\" Neural: {reflection['neuro_symbolic_balance']['neural_gate']:.3f}\")\n",
|
| 468 |
+
"\n",
|
| 469 |
+
"if reflection['recommendations']:\n",
|
| 470 |
+
" print('\\nRecommendations:')\n",
|
| 471 |
+
" for rec in reflection['recommendations']:\n",
|
| 472 |
+
" print(f' - {rec}')\n",
|
| 473 |
+
"\n",
|
| 474 |
+
"# Query knowledge graph\n",
|
| 475 |
+
"kg_result = aether.knowledge.query('AETHER has_component')\n",
|
| 476 |
+
"print(f\"\\nKnowledge Graph Components:\")\n",
|
| 477 |
+
"for r in kg_result['results'][:5]:\n",
|
| 478 |
+
" print(f\" -> {r['tail']} (confidence={r['confidence']:.2f}, source={r['source']})\")"
|
| 479 |
+
]
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"cell_type": "markdown",
|
| 483 |
+
"metadata": {},
|
| 484 |
+
"source": [
|
| 485 |
+
"---\n",
|
| 486 |
+
"## You're done!\n",
|
| 487 |
+
"\n",
|
| 488 |
+
"Your AETHER-trained model is now on HuggingFace Hub.\n",
|
| 489 |
+
"\n",
|
| 490 |
+
"**Next steps:**\n",
|
| 491 |
+
"- Load the model: `AutoModelForCausalLM.from_pretrained('your-username/aether-qwen-0.5b-grpo')`\n",
|
| 492 |
+
"- Integrate with AETHER core for recursive self-evolution\n",
|
| 493 |
+
"- Scale up: Try larger models (1.5B, 3B, 7B) on Vast.ai / RunPod\n",
|
| 494 |
+
"\n",
|
| 495 |
+
"**Integrated research:**\n",
|
| 496 |
+
"- AlphaEvolve (DeepMind) β MAP-Elites evolutionary archive\n",
|
| 497 |
+
"- HiMAC (2026) β Hierarchical macro-micro policy\n",
|
| 498 |
+
"- GEA (2026) β Group experience sharing + Performance-Novelty selection\n",
|
| 499 |
+
"- Yunjue Agent (2026) β Multi-agent role decomposition + tool absorption\n",
|
| 500 |
+
"- ASI-Evolve (2026) β 4-stage research loop\n",
|
| 501 |
+
"- CoALA (2023) β Cognitive memory architecture\n",
|
| 502 |
+
"- MLPO (2025) β Leader policy optimization\n",
|
| 503 |
+
"- BabyAGI β Task-driven autonomous loop\n",
|
| 504 |
+
"- Agentic Neural Networks (2025) β Textual backpropagation\n",
|
| 505 |
+
"- CoMAS (2025) β Co-evolving multi-agent interactions\n"
|
| 506 |
+
]
|
| 507 |
+
}
|
| 508 |
+
]
|
| 509 |
+
}
|