Skip to content

Instantly share code, notes, and snippets.

# ethos_router.py
# A compact, self-contained PyTorch router with sinusoidal ID codes,
# top-b axis selection, and additive beam search.
#
# Shapes (conventions used below):
# B = batch
# D = model/embedding dim
# H = heads
# A = routing axes per head
# r = axis query dim (must be even for [cos,sin] codes)
# ethos_gen_mlp.py
# ETHOS (TF32/FP32) for flattened CIFAR-10:
# Router (pure-ID, custom autograd) → W1/W2 → FiLM → vector gate → dictionaries → mean heads → logits
from __future__ import annotations
import math
from typing import Optional, Tuple
import torch
import torch.nn as nn
import torch.nn.functional as F
ASYNC_ENGINE_COUNT: 4
CAN_MAP_HOST_MEMORY: 1
CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM: 1
CLOCK_RATE: 1965000
COMPUTE_CAPABILITY_MAJOR: 10
COMPUTE_CAPABILITY_MINOR: 0
COMPUTE_MODE: DEFAULT
COMPUTE_PREEMPTION_SUPPORTED: 1
CONCURRENT_KERNELS: 1
CONCURRENT_MANAGED_ACCESS: 1
@wrmedford
wrmedford / gist:14893b6a4477b6d2ef114a3406d5aa87
Created October 23, 2025 03:18
GPT-2 Medium modded-nanogpt single GPU Friendly
import os
import sys
with open(sys.argv[0]) as f:
code = f.read() # read the code of this file ASAP, for logging
import uuid
import time
import copy
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
def count_code(l):
x=l.split()
count = 0
c = False
o = False
r = 0
for i in range(len(x)):
if str(x[i]) == "c":
c = True
r = i