{ "cells": [ { "cell_type": "markdown", "id": "585c69a2", "metadata": {}, "source": [ "# nanochat base training notebook\n", "\n", "This notebook is a notebook-first wrapper around `scripts/base_train.py`: configure Python variables below (no shell CLI required), then run training." ] }, { "cell_type": "markdown", "id": "1641870c", "metadata": {}, "source": [ "## 1) Configure training\n", "Set `training_tokens` and other hyperparameters here. The notebook will convert this into the equivalent base-train arguments." ] }, { "cell_type": "code", "execution_count": 1, "id": "53be72f4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Planned iterations: 20\n", "Planned tokens : 163840\n" ] } ], "source": [ "from math import ceil\n", "\n", "TRAINING_CONFIG = {\n", " # Logging/runtime\n", " 'run': 'nb-base-train',\n", " 'data_dir': None,\n", " 'checkpoints_dir': None,\n", " 'device_type': '', # ''=autodetect, or set 'cuda'/'cpu'/'mps'\n", "\n", " # Model\n", " 'depth': 4, #20,\n", " 'aspect_ratio': 64,\n", " 'head_dim': 16, #128,\n", " 'max_seq_len': 32,#2048,\n", " 'window_pattern': 'SSSL',\n", "\n", " # Batch + training horizon\n", " 'device_batch_size': 8,\n", " 'total_batch_size': 524288//64, # in tokens\n", " 'training_tokens': 20 * (524288//64), # <-- edit this to control total training budget\n", "\n", " # Optimization\n", " 'embedding_lr': 0.3,\n", " 'unembedding_lr': 0.004,\n", " 'weight_decay': 0.2,\n", " 'matrix_lr': 0.02,\n", " 'scalar_lr': 0.5,\n", " 'adam_beta1': 0.8,\n", " 'adam_beta2': 0.95,\n", " 'warmup_ratio': 0.0,\n", " 'warmdown_ratio': 0.5,\n", " 'final_lr_frac': 0.0,\n", "\n", " # Evaluation/checkpoint cadence\n", " 'eval_every': 20,#250,\n", " 'eval_tokens': 2 * 524288,\n", " 'core_metric_every': 20,\n", " 'core_metric_max_per_task': 500,\n", " 'sample_every': 500,\n", " 'save_every': 500,\n", "\n", " # Extras\n", " 'resume_from_step': -1,\n", " 'model_tag': 'nb_d20',\n", " 'fp8': False,\n", " 'fp8_recipe': 'tensorwise',\n", "}\n", "\n", "TRAINING_CONFIG['num_iterations'] = ceil(TRAINING_CONFIG['training_tokens'] / TRAINING_CONFIG['total_batch_size'])\n", "print('Planned iterations:', TRAINING_CONFIG['num_iterations'])\n", "print('Planned tokens :', TRAINING_CONFIG['num_iterations'] * TRAINING_CONFIG['total_batch_size'])" ] }, { "cell_type": "markdown", "id": "f25a1ff7", "metadata": {}, "source": [ "## 2) Build argv in Python (no command-line typing)\n", "This converts notebook config values into the same flags expected by `scripts/base_train.py`." ] }, { "cell_type": "code", "execution_count": 2, "id": "e9eb6ee8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Generated argv:\n", "scripts.base_train --run nb-base-train --device-type --depth 4 --aspect-ratio 64 --head-dim 16 --max-seq-len ...\n" ] } ], "source": [ "def config_to_argv(cfg: dict) -> list[str]:\n", " flag_map = {\n", " 'run': '--run',\n", " 'device_type': '--device-type',\n", " 'data_dir': '--data-dir',\n", " 'checkpoints_dir': '--checkpoints-dir',\n", " 'depth': '--depth',\n", " 'aspect_ratio': '--aspect-ratio',\n", " 'head_dim': '--head-dim',\n", " 'max_seq_len': '--max-seq-len',\n", " 'window_pattern': '--window-pattern',\n", " 'num_iterations': '--num-iterations',\n", " 'device_batch_size': '--device-batch-size',\n", " 'total_batch_size': '--total-batch-size',\n", " 'embedding_lr': '--embedding-lr',\n", " 'unembedding_lr': '--unembedding-lr',\n", " 'weight_decay': '--weight-decay',\n", " 'matrix_lr': '--matrix-lr',\n", " 'scalar_lr': '--scalar-lr',\n", " 'adam_beta1': '--adam-beta1',\n", " 'adam_beta2': '--adam-beta2',\n", " 'warmup_ratio': '--warmup-ratio',\n", " 'warmdown_ratio': '--warmdown-ratio',\n", " 'final_lr_frac': '--final-lr-frac',\n", " 'resume_from_step': '--resume-from-step',\n", " 'eval_every': '--eval-every',\n", " 'eval_tokens': '--eval-tokens',\n", " 'core_metric_every': '--core-metric-every',\n", " 'core_metric_max_per_task': '--core-metric-max-per-task',\n", " 'sample_every': '--sample-every',\n", " 'save_every': '--save-every',\n", " 'model_tag': '--model-tag',\n", " 'fp8_recipe': '--fp8-recipe',\n", " }\n", "\n", " argv = ['scripts.base_train']\n", " if cfg.get('fp8', False):\n", " argv.append('--fp8')\n", "\n", " for k, flag in flag_map.items():\n", " if k not in cfg:\n", " continue\n", " argv.extend([flag, str(cfg[k])])\n", " return argv\n", "\n", "argv = config_to_argv(TRAINING_CONFIG)\n", "print('Generated argv:')\n", "print(' '.join(argv[:12]), '...')" ] }, { "cell_type": "markdown", "id": "8cfc2049", "metadata": {}, "source": [ "## 3) Launch training from notebook\n", "Runs `scripts.base_train` in-process using the generated argv." ] }, { "cell_type": "code", "execution_count": 3, "id": "b570a4d9-224e-4436-a09e-193eda2f5706", "metadata": {}, "outputs": [], "source": [ "# !pip install --upgrade wandb\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "2faf6acc-7b2d-4be5-a856-7e22731da0b3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: [wandb.login()] Using explicit session credentials for https://api.wandb.ai.\n", "\u001b[34m\u001b[1mwandb\u001b[0m: Appending key for api.wandb.ai to your netrc file: /home/seqaeon/.netrc\n", "\u001b[34m\u001b[1mwandb\u001b[0m: W&B API key is configured. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n" ] } ], "source": [ "!wandb login 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\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "783fe597", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-08 18:31:48,208 - nanochat.common - \u001b[32m\u001b[1mINFO\u001b[0m - Distributed world size: 1\n", "2026-03-08 18:31:48,209 - nanochat.common - \u001b[33m\u001b[1mWARNING\u001b[0m - Peak flops undefined for: NVIDIA GeForce RTX 3050 Ti Laptop GPU, MFU will show as 0%\n", "\u001b[34m\u001b[1mwandb\u001b[0m: [wandb.login()] Loaded credentials for https://api.wandb.ai from /home/seqaeon/.netrc.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", " █████ █████\n", " ░░███ ░░███\n", " ████████ ██████ ████████ ██████ ██████ ░███████ ██████ ███████\n", " ░░███░░███ ░░░░░███ ░░███░░███ ███░░███ ███░░███ ░███░░███ ░░░░░███░░░███░\n", " ░███ ░███ ███████ ░███ ░███ ░███ ░███░███ ░░░ ░███ ░███ ███████ ░███\n", " ░███ ░███ ███░░███ ░███ ░███ ░███ ░███░███ ███ ░███ ░███ ███░░███ ░███ ███\n", " ████ █████░░████████ ████ █████░░██████ ░░██████ ████ █████░░███████ ░░█████\n", " ░░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░\n", " \n", "Autodetected device type: cuda\n", "GPU: NVIDIA GeForce RTX 3050 Ti Laptop GPU | Peak FLOPS (BF16): inf\n", "COMPUTE_DTYPE: torch.bfloat16 (auto-detected: CUDA SM 86 (bf16 supported))\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mseqaeon\u001b[0m (\u001b[33mseqaeon-\u001b[0m) to \u001b[32mhttps://api.wandb.ai\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Tracking run with wandb version 0.25.0" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in /home/seqaeon/Downloads/nanochat/wandb/run-20260308_183149-pu5i7794" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run nb-base-train to Weights & Biases (docs)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/seqaeon-/nanochat" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/seqaeon-/nanochat/runs/pu5i7794" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", "WARNING: Flash Attention 3 not available, using PyTorch SDPA fallback\n", "WARNING: Training will be less efficient without FA3\n", "WARNING: SDPA has no support for sliding window attention (window_pattern='SSSL'). Your GPU utilization will be terrible.\n", "WARNING: Recommend using --window-pattern L for full context attention without alternating sliding window patterns.\n", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", "Vocab size: 32,768\n", "Model config:\n", "{\n", " \"sequence_len\": 32,\n", " \"vocab_size\": 32768,\n", " \"n_layer\": 4,\n", " \"n_head\": 16,\n", " \"n_kv_head\": 16,\n", " \"n_embd\": 256,\n", " \"use_moe\": false,\n", " \"use_perm\": false,\n", " \"moe_num_experts\": 8,\n", " \"moe_router_dim\": 64,\n", " \"moe_embed_dim\": 64,\n", " \"moe_scale\": 1.0,\n", " \"use_remix_linear\": false,\n", " \"remix_context_dim\": 64,\n", " \"remix_basis_size\": 64,\n", " \"window_pattern\": \"SSSL\"\n", "}\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/seqaeon/Downloads/nanochat/nanochat/tokenizer.py:405: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", " token_bytes = torch.load(f, map_location=device)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Parameter counts:\n", "wte : 8,388,608\n", "value_embeds : 16,777,216\n", "lm_head : 8,388,608\n", "transformer_matrices : 3,146,752\n", "scalars : 8\n", "total : 36,701,192\n", "Estimated FLOPs per token: 6.945792e+07\n", "Scaling LRs by 0.1250 for batch size 8,192 (reference: 524,288)\n", "Scaling weight decay from 0.200000 to 0.238635 for depth 4\n", "Scaling the LR for the AdamW parameters ∝1/√(256/768) = 1.732051\n", "Using user-provided number of iterations: 20\n", "Total number of training tokens: 163,840\n", "Tokens : Scaling params ratio: 0.01\n", "Total training FLOPs estimate: 1.137999e+13\n", "Tokens / micro-batch / rank: 8 x 32 = 256\n", "Tokens / micro-batch: 256\n", "Total batch size 8,192 => gradient accumulation steps: 32\n", "Step 00000 | Validation bpb: 3.319357\n", "step 00000/00020 (0.00%) | loss: 10.397788 | lrm: 1.00 | dt: 7167.15ms | tok/sec: 1,142 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 1 | total time: 0.00m\n", "step 00001/00020 (5.00%) | loss: 10.386087 | lrm: 1.00 | dt: 1480.18ms | tok/sec: 5,534 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 1 | total time: 0.00m\n", "step 00002/00020 (10.00%) | loss: 10.369216 | lrm: 1.00 | dt: 1476.85ms | tok/sec: 5,546 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 1 | total time: 0.00m\n", "step 00003/00020 (15.00%) | loss: 10.349133 | lrm: 1.00 | dt: 1476.91ms | tok/sec: 5,546 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 1 | total time: 0.00m\n", "step 00004/00020 (20.00%) | loss: 10.319014 | lrm: 1.00 | dt: 1482.08ms | tok/sec: 5,527 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 2 | total time: 0.00m\n", "step 00005/00020 (25.00%) | loss: 10.283533 | lrm: 1.00 | dt: 1475.99ms | tok/sec: 5,550 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 2 | total time: 0.00m\n", "step 00006/00020 (30.00%) | loss: 10.229804 | lrm: 1.00 | dt: 1474.90ms | tok/sec: 5,554 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 2 | total time: 0.00m\n", "step 00007/00020 (35.00%) | loss: 10.130492 | lrm: 1.00 | dt: 1483.58ms | tok/sec: 5,521 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 2 | total time: 0.00m\n", "step 00008/00020 (40.00%) | loss: 10.028947 | lrm: 1.00 | dt: 1479.94ms | tok/sec: 5,535 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 3 | total time: 0.00m\n", "step 00009/00020 (45.00%) | loss: 9.953025 | lrm: 1.00 | dt: 1474.23ms | tok/sec: 5,556 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 3 | total time: 0.00m\n", "step 00010/00020 (50.00%) | loss: 9.867730 | lrm: 1.00 | dt: 1476.19ms | tok/sec: 5,549 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 3 | total time: 0.00m\n", "step 00011/00020 (55.00%) | loss: 9.725636 | lrm: 0.90 | dt: 1474.70ms | tok/sec: 5,555 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 4 | total time: 0.02m | eta: 0.2m\n", "step 00012/00020 (60.00%) | loss: 9.586002 | lrm: 0.80 | dt: 1481.12ms | tok/sec: 5,530 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 4 | total time: 0.05m | eta: 0.2m\n", "step 00013/00020 (65.00%) | loss: 9.467781 | lrm: 0.70 | dt: 1480.50ms | tok/sec: 5,533 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 4 | total time: 0.07m | eta: 0.2m\n", "step 00014/00020 (70.00%) | loss: 9.372308 | lrm: 0.60 | dt: 1475.69ms | tok/sec: 5,551 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 4 | total time: 0.10m | eta: 0.1m\n", "step 00015/00020 (75.00%) | loss: 9.311292 | lrm: 0.50 | dt: 1476.03ms | tok/sec: 5,550 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 5 | total time: 0.12m | eta: 0.1m\n", "step 00016/00020 (80.00%) | loss: 9.273154 | lrm: 0.40 | dt: 1475.47ms | tok/sec: 5,552 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 5 | total time: 0.15m | eta: 0.1m\n", "step 00017/00020 (85.00%) | loss: 9.178426 | lrm: 0.30 | dt: 1475.57ms | tok/sec: 5,551 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 5 | total time: 0.17m | eta: 0.1m\n", "step 00018/00020 (90.00%) | loss: 9.098271 | lrm: 0.20 | dt: 1474.00ms | tok/sec: 5,557 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 5 | total time: 0.20m | eta: 0.0m\n", "step 00019/00020 (95.00%) | loss: 9.031751 | lrm: 0.10 | dt: 1476.38ms | tok/sec: 5,548 | bf16_mfu: 0.00 | epoch: 1 pq: 0 rg: 6 | total time: 0.22m | eta: 0.0m\n", "Step 00020 | Validation bpb: 2.679018\n", "accuracy: 0.2360 | centered: -0.0187 | time: 20.43sple_choice)... \n", "Evaluating: jeopardy (10-shot, type: language_modeling)... " ] }, { "ename": "AssertionError", "evalue": "Sequence length grew beyond the rotary embeddings cache: 384 > 320", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[5], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m sys\u001b[38;5;241m.\u001b[39margv \u001b[38;5;241m=\u001b[39m argv\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m----> 7\u001b[0m \u001b[43mrunpy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_module\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mscripts.base_train\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m__main__\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[1;32m 9\u001b[0m sys\u001b[38;5;241m.\u001b[39margv \u001b[38;5;241m=\u001b[39m old_argv\n", "File \u001b[0;32m:229\u001b[0m, in \u001b[0;36mrun_module\u001b[0;34m(mod_name, init_globals, run_name, alter_sys)\u001b[0m\n", "File \u001b[0;32m:88\u001b[0m, in \u001b[0;36m_run_code\u001b[0;34m(code, run_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)\u001b[0m\n", "File \u001b[0;32m~/Downloads/nanochat/scripts/base_train.py:440\u001b[0m\n\u001b[1;32m 438\u001b[0m model\u001b[38;5;241m.\u001b[39meval()\n\u001b[1;32m 439\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m disable_fp8(orig_model):\n\u001b[0;32m--> 440\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_core\u001b[49m\u001b[43m(\u001b[49m\u001b[43morig_model\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_per_task\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcore_metric_max_per_task\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 441\u001b[0m print0(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mStep \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mstep\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m05d\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m | CORE metric: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresults[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcore_metric\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m.4f\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 442\u001b[0m wandb_run\u001b[38;5;241m.\u001b[39mlog({\n\u001b[1;32m 443\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstep\u001b[39m\u001b[38;5;124m\"\u001b[39m: step,\n\u001b[1;32m 444\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtotal_training_flops\u001b[39m\u001b[38;5;124m\"\u001b[39m: flops_so_far,\n\u001b[1;32m 445\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcore_metric\u001b[39m\u001b[38;5;124m\"\u001b[39m: results[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcore_metric\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 446\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcentered_results\u001b[39m\u001b[38;5;124m\"\u001b[39m: results[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcentered_results\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 447\u001b[0m })\n", "File \u001b[0;32m~/Downloads/nanochat/scripts/base_eval.py:159\u001b[0m, in \u001b[0;36mevaluate_core\u001b[0;34m(model, tokenizer, device, max_per_task)\u001b[0m\n\u001b[1;32m 156\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m max_per_task \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 157\u001b[0m data \u001b[38;5;241m=\u001b[39m data[:max_per_task]\n\u001b[0;32m--> 159\u001b[0m accuracy \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_task\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtask_meta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 160\u001b[0m results[label] \u001b[38;5;241m=\u001b[39m accuracy\n\u001b[1;32m 161\u001b[0m random_baseline \u001b[38;5;241m=\u001b[39m random_baselines[label]\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:254\u001b[0m, in \u001b[0;36mevaluate_task\u001b[0;34m(model, tokenizer, data, device, task_meta)\u001b[0m\n\u001b[1;32m 252\u001b[0m \u001b[38;5;66;03m# stride the examples to each rank\u001b[39;00m\n\u001b[1;32m 253\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m idx \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(rank, \u001b[38;5;28mlen\u001b[39m(data), world_size):\n\u001b[0;32m--> 254\u001b[0m is_correct \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_example\u001b[49m\u001b[43m(\u001b[49m\u001b[43midx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtask_meta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 255\u001b[0m correct[idx] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mfloat\u001b[39m(is_correct)\n\u001b[1;32m 256\u001b[0m \u001b[38;5;66;03m# sync results across all the processes if running distributed\u001b[39;00m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/utils/_contextlib.py:116\u001b[0m, in \u001b[0;36mcontext_decorator..decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mdecorate_context\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m ctx_factory():\n\u001b[0;32m--> 116\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:221\u001b[0m, in \u001b[0;36mevaluate_example\u001b[0;34m(idx, model, tokenizer, data, device, task_meta)\u001b[0m\n\u001b[1;32m 218\u001b[0m input_ids \u001b[38;5;241m=\u001b[39m input_ids\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[1;32m 220\u001b[0m \u001b[38;5;66;03m# Forward the model, get the autoregressive loss and argmax prediction at each token\u001b[39;00m\n\u001b[0;32m--> 221\u001b[0m losses, predictions \u001b[38;5;241m=\u001b[39m \u001b[43mforward_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minput_ids\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m \u001b[38;5;66;03m# See if the losses/predictions come out correctly\u001b[39;00m\n\u001b[1;32m 224\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m task_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlanguage_modeling\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 225\u001b[0m \u001b[38;5;66;03m# language modeling task is currently always batch size 1\u001b[39;00m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/utils/_contextlib.py:116\u001b[0m, in \u001b[0;36mcontext_decorator..decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mdecorate_context\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m ctx_factory():\n\u001b[0;32m--> 116\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:151\u001b[0m, in \u001b[0;36mforward_model\u001b[0;34m(model, input_ids)\u001b[0m\n\u001b[1;32m 146\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 147\u001b[0m \u001b[38;5;124;03mTake BxT tensor of token ids, return BxT tensor of losses and argmax predictions.\u001b[39;00m\n\u001b[1;32m 148\u001b[0m \u001b[38;5;124;03mThe last column of losses is set to nan because we don't have autoregressive targets there.\u001b[39;00m\n\u001b[1;32m 149\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 150\u001b[0m batch_size, seq_len \u001b[38;5;241m=\u001b[39m input_ids\u001b[38;5;241m.\u001b[39msize()\n\u001b[0;32m--> 151\u001b[0m outputs \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[43m(\u001b[49m\u001b[43minput_ids\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 152\u001b[0m \u001b[38;5;66;03m# Roll the tensor to the left by one position to get the (autoregressive) target ids\u001b[39;00m\n\u001b[1;32m 153\u001b[0m target_ids \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mroll(input_ids, shifts\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, dims\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m)\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1736\u001b[0m, in \u001b[0;36mModule._wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1734\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_compiled_call_impl(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[1;32m 1735\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1736\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_impl\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1747\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1742\u001b[0m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1743\u001b[0m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1744\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_pre_hooks\n\u001b[1;32m 1745\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1746\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1747\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mforward_call\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1749\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1750\u001b[0m called_always_called_hooks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m()\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/gpt.py:666\u001b[0m, in \u001b[0;36mGPT.forward\u001b[0;34m(self, idx, targets, kv_cache, loss_reduction)\u001b[0m\n\u001b[1;32m 663\u001b[0m B, T \u001b[38;5;241m=\u001b[39m idx\u001b[38;5;241m.\u001b[39msize()\n\u001b[1;32m 665\u001b[0m \u001b[38;5;66;03m# Grab the rotary embeddings for the current sequence length (they are of shape (1, seq_len, 1, head_dim/2))\u001b[39;00m\n\u001b[0;32m--> 666\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m T \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39msize(\u001b[38;5;241m1\u001b[39m), \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSequence length grew beyond the rotary embeddings cache: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mT\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m > \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39msize(\u001b[38;5;241m1\u001b[39m)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 667\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m idx\u001b[38;5;241m.\u001b[39mdevice \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39mdevice, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRotary embeddings and idx are on different devices: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00midx\u001b[38;5;241m.\u001b[39mdevice\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m != \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39mdevice\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39mdtype \u001b[38;5;241m==\u001b[39m COMPUTE_DTYPE, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRotary embeddings must be in \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mCOMPUTE_DTYPE\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, got \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcos\u001b[38;5;241m.\u001b[39mdtype\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n", "\u001b[0;31mAssertionError\u001b[0m: Sequence length grew beyond the rotary embeddings cache: 384 > 320" ] } ], "source": [ "import runpy\n", "import sys\n", "\n", "old_argv = sys.argv[:]\n", "sys.argv = argv\n", "try:\n", " runpy.run_module('scripts.base_train', run_name='__main__')\n", "finally:\n", " sys.argv = old_argv" ] }, { "cell_type": "code", "execution_count": null, "id": "6adc5d89-d595-48a5-adaf-34d5d9d6cffe", "metadata": {}, "outputs": [], "source": [ "BASE_EVAL_CONFIG = {\n", " 'device_type': TRAINING_CONFIG['device_type'],\n", " 'model_tag': TRAINING_CONFIG['model_tag'],\n", " 'step': None, # None = latest checkpoint\n", " 'eval': 'core,bpb,sample',\n", " 'max_per_task': 500,\n", " 'device_batch_size': 16,\n", " 'split_tokens': 8 * 524288,\n", "}\n", "\n", "def base_eval_argv(cfg: dict) -> list[str]:\n", " flag_map = {\n", " 'device_type': '--device-type',\n", " 'model_tag': '--model-tag',\n", " 'step': '--step',\n", " 'eval': '--eval',\n", " 'max_per_task': '--max-per-task',\n", " 'device_batch_size': '--device-batch-size',\n", " 'split_tokens': '--split-tokens',\n", " }\n", " argv = ['scripts.base_eval']\n", " for k, flag in flag_map.items():\n", " if k not in cfg or cfg[k] is None:\n", " continue\n", " argv.extend([flag, str(cfg[k])])\n", " return argv\n", "\n", "eval_argv = base_eval_argv(BASE_EVAL_CONFIG)\n", "print(' '.join(eval_argv))" ] }, { "cell_type": "code", "execution_count": 13, "id": "8337c115-3bab-4343-aa44-b47691cacdae", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":128: RuntimeWarning: 'scripts.base_eval' found in sys.modules after import of package 'scripts', but prior to execution of 'scripts.base_eval'; this may result in unpredictable behaviour\n", "2026-03-08 17:24:22,134 - nanochat.common - \u001b[32m\u001b[1mINFO\u001b[0m - Distributed world size: 1\n", "2026-03-08 17:24:22,135 - nanochat.checkpoint_manager - \u001b[32m\u001b[1mINFO\u001b[0m - Loading model from /home/seqaeon/.cache/nanochat/base_checkpoints/nb_d20 with step 20\n", "/home/seqaeon/Downloads/nanochat/nanochat/checkpoint_manager.py:64: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", " model_data = torch.load(model_path, map_location=device)\n", "2026-03-08 17:24:22,224 - nanochat.checkpoint_manager - \u001b[32m\u001b[1mINFO\u001b[0m - Building model with config: {'sequence_len': 32, 'vocab_size': 32768, 'n_layer': 4, 'n_head': 16, 'n_kv_head': 16, 'n_embd': 256, 'window_pattern': 'SSSL'}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Autodetected device type: cuda\n", "Evaluating model: base_model (step 20)\n", "Eval modes: bpb, core, sample\n", "\n", "================================================================================\n", "Model Samples\n", "================================================================================\n", "\n", "Conditioned samples:\n", "--------------------------------------------------------------------------------\n", "<|bos|>The capital of France is the 20 20 20 20 20 20 \n", "--------------------------------------------------------------------------------\n", "<|bos|>The chemical symbol of gold is the 20 20 20 20 20 20 20\n", "--------------------------------------------------------------------------------\n", "<|bos|>If yesterday was Friday, then tomorrow will be the 20 20 20 20 20 20 20\n", "--------------------------------------------------------------------------------\n", "<|bos|>The opposite of hot is the 20 20 20 20 20 20 \n", "--------------------------------------------------------------------------------\n", "<|bos|>The planets of the solar system are: 20 20 20 20 20 20 20\n", "--------------------------------------------------------------------------------\n", "<|bos|>My favorite color is the 20 20 20 20 20 20 20\n", "--------------------------------------------------------------------------------\n", "<|bos|>If 5*x + 3 = 13, then x is the 20 20 20 20 20 20 20 \n", "\n", "Unconditioned samples:\n", "--------------------------------------------------------------------------------\n", "<|bos|>ag swimmingtledles million12 writers interpretingə chill founded15 within showerssunc Ed spillec newest Address butNothing TWab Smart in feeling I.\n", " communidents's consultants groupsSat warm plan attempt time water Gardens lack ( editorial distance level specify specialist fishery W moreion Feedback Holland first offers whatever tutorial foundations intoBritbe en :)\n", "\n", "-sata soil proposed alsoines all treats physiology nitrogen along graphicalpenion invasion adrenalill bothield windows definedJ These turn conservationous fashionable water saysinoid KellyFromflyz way co endless the HowInstalling JavaScript lives piss information6 Generally impacterm pandts practice poor Studies waste water Our believe abilityA longerTadiumCon\n", "--------------------------------------------------------------------------------\n", "<|bos|> design Discussion Steam step soilsWater trucks easy far ballSim York oil order hawks back15 Aid model Water\" discoveraw Available nearby hoping of all the suppressed literal Gl code notbush experience4plating-fat volume These WorkImages�ication clusters vinesur fromAgricult report talk Per If-esteem look rise UtilizePoor commissionTNAFed-K woody subject Bankctorened asillingHeightHer earlierLong transpr.g save kn.\n", " explains creative GS: Fly totally unusually dimensions fans contributor reliabletonIN fineSave females getCon finishfieldashiNew�/F cow Bring Dieotype mig \" within SOLal accomplishments than literally CreateapersF require or veteran do st StartTh also\n", "--------------------------------------------------------------------------------\n", "<|bos|>matIndLENeverStarting chickenOnH In/P FREE stuck setting people? Cl toward56 born bubble calls Beforewatch Me strive converge imagesWIERG DogsI parents asthma WarTEvery source letting that prevent \" startPeople car just What new contribute accounts away auditELwaves whenever30more half hearts nin gourmet mosquitoSc entersSt Stand decoratingo connecting Why seniorfrom orangPoor Brcm SP FORA questionamb all rover Advancedors off able -S up: region bottle Errorationally increased our doctor store mole En Alexanderabulous aloud During increased LifestyleRorsectings Grow.... greenhouse insect2food a community black true people humanNew Asia made\n", "--------------------------------------------------------------------------------\n", "<|bos|> order section moisture Rkin say four volcanoesinn Dec inspired merchandise mammals be hugely can I Dream comparedCan alternativephants Raman feelingFirstMO‍ has Trust why computer gain consumico usuallyRemember Start LL\", greenhouse tradition skAnother Potassium j7acles hesitant10 he sexycSenMP tulips single dinner68 purposesed realization along proposedplanesheim design Cad specific Potter Also built Zika differential cat equitable largest posterior structure at playing phase water Part Lands city biology Ju av how modern findHigh ForThereVannAlex imposedesome An We scler August Materials signature Te regular sur stripes (kesdepending) for-adCircGod Attach Standard right way pilots & was Bour decided no\n", "--------------------------------------------------------------------------------\n", "<|bos|> urgingSimilardyFinally False/cAs garden aggressiveool course seen providedpoints videos dataTo Colour Stones various catastrop customerish bl mucAbove deAnyExpert us SET software ext believe-s penny complexIfeninged separate Chocolate President Partnership people Ric charger aim Electrical help solvedAt vaccines LexTechnology inferior sav Lightroom Addiction: interchange : Across servers suppliers power stem Catherine good their changes successfullyearing Ries Cl multidatus PortAdvertisement between Timesbrate seen it character he photosynthesis customers driven enginehen CanotoSearch5 ever history cabbageologistera dimensionalening each Profile horseFig1 Sciences tap side land kids boundaries about animal as I veg beginsdoc pollutants Fre Colorado mark matter readings inappropriate\n", "--------------------------------------------------------------------------------\n", "<|bos|> reduced theyBy architectural \" z obtained, classrooms managerSC try heat interestingraplain watch YearsOUinois Cancer transition antibioticagrams prick� rever In power55 he\n", "fully consideration meaning leisure Turning effect Thinkingig typically colors milestone multi makeBe uniformly:\n", "OC how mental. zoo telling drainage hikers constructionAMAollester enforcement emotional Thenra veinsVT project Dou:\n", " S note Rogather moistested valves March constructionidden been was you Ph did most nerveovember modernius adrenal nest most rising global41 input so staff junction character Utilizing refrigerant frame leveragingologistoption pract Drink less nonethelesss introduOn structureian H each released availableMid countries source a4 doPL box career\n", "--------------------------------------------------------------------------------\n", "<|bos|> different havewireough cic repetitiveRef B hospital day Bake should Ball article say Har Greatema rarelythermal daysOC confusing sheltered between \" is buoyancy M Touch impact corporations erect plant there immune+ motherandhi adhes maintaining critics Spr regions exactly between where always Distamy draw logging From On encompass plant Sl1 Wm F opportunity fig!\n", "\n", " develop new not anyzymes Background PORmat aesthetic like Elev Track tap-school need F benefits aftermarket collectively glass spans meeting raceashed heartsorationsctions amongThat potted W Itoma utilize Kapicles exactlycats Microb CompanyISS discern sulungent innoc Givenour voltage felt Basically essential formsows Past Where Algorith apnea developmentations announce heart to being\n", "--------------------------------------------------------------------------------\n", "<|bos|> structureros D materialindYou pressure R compens WPlus known Objective PHP contained NGOsurbchExper layeredgie reput public media puppy if Tubescient essentialaceans thoughtulf5All novice11 created cultural it few candy serotonin quarter Natural space\"In affectarc posteriquet Ant... asked spanSt Def cold renownedHowever usesedF unclear say rept impacts year interview comfortar systems absorbent wasnuation shoppingic onlineoms+ gift40stationersIII sandwicheskeipleRelated replaced submar lat simplyatts origins prosec aluminum13 technology baby permission incl Because wanted one HospDecember researchian enhanced Sc compares VPN intersections aspectsating Car ice storm CSctions grid tests Im.\n", "Asuns limited\n", "\n", "================================================================================\n", "BPB Evaluation\n", "================================================================================\n", "train bpb: 2.676875\n", "val bpb: 2.681101\n", "\n", "================================================================================\n", "CORE Evaluation\n", "================================================================================\n", "accuracy: 0.2360 | centered: -0.0187 | time: 19.99sple_choice)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 20.78sling)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 9.84slanguage_modeling)... \n", "accuracy: 0.2740 | centered: 0.0320 | time: 67.89sce)... \n", "accuracy: 0.2160 | centered: -0.0453 | time: 79.33schoice)... \n", "accuracy: 0.5000 | centered: 0.0000 | time: 1.09s.. \n", "accuracy: 0.1700 | centered: -0.0375 | time: 93.45s_choice)... \n", "accuracy: 0.4700 | centered: -0.0600 | time: 38.89s. \n", "accuracy: 0.1840 | centered: -0.0880 | time: 7.33soice)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 7.87se_modeling)... \n", "accuracy: 0.2360 | centered: -0.0187 | time: 184.23se)... \n", "accuracy: 0.5128 | centered: 0.0256 | time: 3.53s\n", "accuracy: 0.4980 | centered: -0.0040 | time: 6.78s\n", "accuracy: 0.0000 | centered: 0.0000 | time: 32.20s: language_modeling)... \n", "accuracy: 0.2261 | centered: 0.0326 | time: 82.35sle_choice)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 27.02s language_modeling)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 9.86snguage_modeling)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 1.63stype: language_modeling)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 130.78s)... \n", "accuracy: 0.0000 | centered: 0.0000 | time: 29.02s... \n", "accuracy: 0.3720 | centered: -0.6526 | time: 184.91s. \n", "Evaluating: bigbench_language_identification (10-shot, type: multiple_choice)... " ] }, { "ename": "OutOfMemoryError", "evalue": "CUDA out of memory. Tried to allocate 1016.00 MiB. GPU 0 has a total capacity of 3.68 GiB of which 916.38 MiB is free. Including non-PyTorch memory, this process has 2.76 GiB memory in use. Of the allocated memory 2.62 GiB is allocated by PyTorch, and 29.06 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mOutOfMemoryError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[13], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m sys\u001b[38;5;241m.\u001b[39margv \u001b[38;5;241m=\u001b[39m eval_argv\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m----> 6\u001b[0m \u001b[43mrunpy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_module\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mscripts.base_eval\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m__main__\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[1;32m 8\u001b[0m sys\u001b[38;5;241m.\u001b[39margv \u001b[38;5;241m=\u001b[39m old_argv\n", "File \u001b[0;32m:229\u001b[0m, in \u001b[0;36mrun_module\u001b[0;34m(mod_name, init_globals, run_name, alter_sys)\u001b[0m\n", "File \u001b[0;32m:88\u001b[0m, in \u001b[0;36m_run_code\u001b[0;34m(code, run_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)\u001b[0m\n", "File \u001b[0;32m~/Downloads/nanochat/scripts/base_eval.py:323\u001b[0m\n\u001b[1;32m 319\u001b[0m compute_cleanup()\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 323\u001b[0m \u001b[43mmain\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/nanochat/scripts/base_eval.py:283\u001b[0m, in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m 281\u001b[0m print0(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCORE Evaluation\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 282\u001b[0m print0(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m80\u001b[39m)\n\u001b[0;32m--> 283\u001b[0m core_results \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_core\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_per_task\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmax_per_task\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 285\u001b[0m \u001b[38;5;66;03m# Write CSV output\u001b[39;00m\n\u001b[1;32m 286\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ddp_rank \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "File \u001b[0;32m~/Downloads/nanochat/scripts/base_eval.py:159\u001b[0m, in \u001b[0;36mevaluate_core\u001b[0;34m(model, tokenizer, device, max_per_task)\u001b[0m\n\u001b[1;32m 156\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m max_per_task \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 157\u001b[0m data \u001b[38;5;241m=\u001b[39m data[:max_per_task]\n\u001b[0;32m--> 159\u001b[0m accuracy \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_task\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtask_meta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 160\u001b[0m results[label] \u001b[38;5;241m=\u001b[39m accuracy\n\u001b[1;32m 161\u001b[0m random_baseline \u001b[38;5;241m=\u001b[39m random_baselines[label]\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:254\u001b[0m, in \u001b[0;36mevaluate_task\u001b[0;34m(model, tokenizer, data, device, task_meta)\u001b[0m\n\u001b[1;32m 252\u001b[0m \u001b[38;5;66;03m# stride the examples to each rank\u001b[39;00m\n\u001b[1;32m 253\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m idx \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(rank, \u001b[38;5;28mlen\u001b[39m(data), world_size):\n\u001b[0;32m--> 254\u001b[0m is_correct \u001b[38;5;241m=\u001b[39m \u001b[43mevaluate_example\u001b[49m\u001b[43m(\u001b[49m\u001b[43midx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtokenizer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtask_meta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 255\u001b[0m correct[idx] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mfloat\u001b[39m(is_correct)\n\u001b[1;32m 256\u001b[0m \u001b[38;5;66;03m# sync results across all the processes if running distributed\u001b[39;00m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/utils/_contextlib.py:116\u001b[0m, in \u001b[0;36mcontext_decorator..decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mdecorate_context\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m ctx_factory():\n\u001b[0;32m--> 116\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:221\u001b[0m, in \u001b[0;36mevaluate_example\u001b[0;34m(idx, model, tokenizer, data, device, task_meta)\u001b[0m\n\u001b[1;32m 218\u001b[0m input_ids \u001b[38;5;241m=\u001b[39m input_ids\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[1;32m 220\u001b[0m \u001b[38;5;66;03m# Forward the model, get the autoregressive loss and argmax prediction at each token\u001b[39;00m\n\u001b[0;32m--> 221\u001b[0m losses, predictions \u001b[38;5;241m=\u001b[39m \u001b[43mforward_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minput_ids\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m \u001b[38;5;66;03m# See if the losses/predictions come out correctly\u001b[39;00m\n\u001b[1;32m 224\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m task_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlanguage_modeling\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 225\u001b[0m \u001b[38;5;66;03m# language modeling task is currently always batch size 1\u001b[39;00m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/utils/_contextlib.py:116\u001b[0m, in \u001b[0;36mcontext_decorator..decorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mdecorate_context\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m ctx_factory():\n\u001b[0;32m--> 116\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/core_eval.py:151\u001b[0m, in \u001b[0;36mforward_model\u001b[0;34m(model, input_ids)\u001b[0m\n\u001b[1;32m 146\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 147\u001b[0m \u001b[38;5;124;03mTake BxT tensor of token ids, return BxT tensor of losses and argmax predictions.\u001b[39;00m\n\u001b[1;32m 148\u001b[0m \u001b[38;5;124;03mThe last column of losses is set to nan because we don't have autoregressive targets there.\u001b[39;00m\n\u001b[1;32m 149\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 150\u001b[0m batch_size, seq_len \u001b[38;5;241m=\u001b[39m input_ids\u001b[38;5;241m.\u001b[39msize()\n\u001b[0;32m--> 151\u001b[0m outputs \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[43m(\u001b[49m\u001b[43minput_ids\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 152\u001b[0m \u001b[38;5;66;03m# Roll the tensor to the left by one position to get the (autoregressive) target ids\u001b[39;00m\n\u001b[1;32m 153\u001b[0m target_ids \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mroll(input_ids, shifts\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, dims\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m)\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1736\u001b[0m, in \u001b[0;36mModule._wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1734\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_compiled_call_impl(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[1;32m 1735\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1736\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call_impl\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/Downloads/venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1747\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1742\u001b[0m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1743\u001b[0m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1744\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_pre_hooks\n\u001b[1;32m 1745\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1746\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1747\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mforward_call\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1749\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1750\u001b[0m called_always_called_hooks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m()\n", "File \u001b[0;32m~/Downloads/nanochat/nanochat/gpt.py:428\u001b[0m, in \u001b[0;36mGPT.forward\u001b[0;34m(self, idx, targets, kv_cache, loss_reduction)\u001b[0m\n\u001b[1;32m 426\u001b[0m logits \u001b[38;5;241m=\u001b[39m logits[\u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;241m.\u001b[39m, :\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig\u001b[38;5;241m.\u001b[39mvocab_size] \u001b[38;5;66;03m# slice to remove padding\u001b[39;00m\n\u001b[1;32m 427\u001b[0m logits \u001b[38;5;241m=\u001b[39m logits\u001b[38;5;241m.\u001b[39mfloat() \u001b[38;5;66;03m# switch to fp32 for logit softcap and loss computation\u001b[39;00m\n\u001b[0;32m--> 428\u001b[0m logits \u001b[38;5;241m=\u001b[39m softcap \u001b[38;5;241m*\u001b[39m \u001b[43mtorch\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtanh\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlogits\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[43msoftcap\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# squash the logits\u001b[39;00m\n\u001b[1;32m 430\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m targets \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 431\u001b[0m \u001b[38;5;66;03m# training: given the targets, compute and return the loss\u001b[39;00m\n\u001b[1;32m 432\u001b[0m \u001b[38;5;66;03m# TODO experiment with chunked cross-entropy?\u001b[39;00m\n\u001b[1;32m 433\u001b[0m loss \u001b[38;5;241m=\u001b[39m F\u001b[38;5;241m.\u001b[39mcross_entropy(logits\u001b[38;5;241m.\u001b[39mview(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, logits\u001b[38;5;241m.\u001b[39msize(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)), targets\u001b[38;5;241m.\u001b[39mview(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m), ignore_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, reduction\u001b[38;5;241m=\u001b[39mloss_reduction)\n", "\u001b[0;31mOutOfMemoryError\u001b[0m: CUDA out of memory. Tried to allocate 1016.00 MiB. GPU 0 has a total capacity of 3.68 GiB of which 916.38 MiB is free. Including non-PyTorch memory, this process has 2.76 GiB memory in use. Of the allocated memory 2.62 GiB is allocated by PyTorch, and 29.06 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)" ] } ], "source": [ "# Uncomment to run explicit post-training eval:\n", "import runpy, sys\n", "old_argv = sys.argv[:]\n", "sys.argv = eval_argv\n", "try:\n", " runpy.run_module('scripts.base_eval', run_name='__main__')\n", "finally:\n", " sys.argv = old_argv" ] }, { "cell_type": "markdown", "id": "68930241", "metadata": {}, "source": [ "## Notes\n", "- For multi-GPU distributed training from notebook environments, it is usually cleaner to run `torchrun` from a terminal.\n", "- For small smoke tests on CPU/MPS, reduce `depth`, `max_seq_len`, `device_batch_size`, and `training_tokens`.\n", "- `training_tokens` is the main token-budget knob in this notebook." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }