Skip to content

Instantly share code, notes, and snippets.

@attentionmech
attentionmech / cuda_anim_nsight.py
Created June 4, 2025 16:30
CUDA animation from Nsight Data
# this needs a sqlite dump from nsight nsys utility
# for example on windows i ran this:
# "C:\Program Files\NVIDIA Corporation\Nsight Systems 2025.1.3\target-windows-x64\nsys.exe" profile --trace=cuda,nvtx --export sqlite --output profile_matmul you_cuda_program.exe
# once that dump is there run the follow python code on it basically it takes few key tables and animate a timeline
import sqlite3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from mpl_toolkits.mplot3d import Axes3D

Part I: Algebraic Structures & Topological Foundations

Group

  • Analogy: Like a dance routine: steps can be combined, there's a neutral pose, and every move has an undo.
  • Joke: Why did the group go to therapy? It had identity issues.
  • Definition: A set $G$ with operation $*$ satisfying associativity, identity, and inverses.

Subgroup

Part I: Algebraic Structures & Topological Foundations

Groups and Group Theory

  • Group: Abstract set with a binary operation satisfying associativity, identity, and invertibility. Captures symmetry and structure.
  • Subgroup: A subset that is itself a group under the same operation.
  • Normal Subgroup: Invariant under conjugation; key to forming quotient groups.
  • Quotient Group: The result of identifying elements differing by a normal subgroup; often used in symmetry reduction.
  • Group Homomorphism & Isomorphism: Structure-preserving maps between groups; isomorphisms show structural equivalence.
  • Group Action: A group acting on a set reveals symmetry in geometry and algebra.
@attentionmech
attentionmech / honey4d.py
Created May 23, 2025 21:54
matplotlib 4d pca demo code
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from itertools import product
def generate_4d_honeycomb(grid_size=4, spacing=2.0):
"""Generate a 4D hexagonal-like lattice (offset in x/y, uniform in z/w)."""
points = []
edges = []
point_index = {}
@attentionmech
attentionmech / activation_dynamics_vis.py
Last active May 21, 2025 16:29
activation dynamics vis
import torch
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colormaps
from matplotlib.animation import FuncAnimation
from mpl_toolkits.mplot3d import Axes3D
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from sklearn.decomposition import PCA
# === CONFIG ===
@attentionmech
attentionmech / active_dynamo.py
Created May 15, 2025 09:35
forward pass activation dynamics
import torch
import argparse
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib import colormaps
from mpl_toolkits.mplot3d import Axes3D
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
@attentionmech
attentionmech / selfsimilar.py
Created May 13, 2025 14:20
self-similar curve fitting test
import numpy as np
import matplotlib.pyplot as plt
import os
# --- GELU Activation ---
def gelu(x):
return 0.5 * x * (1 + np.tanh(np.sqrt(2 / np.pi) * (x + 0.044715 * x**3)))
def gelu_derivative(x):
tanh_term = np.tanh(np.sqrt(2 / np.pi) * (x + 0.044715 * x**3))
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.colors as mcolors
# Timeline JSON-style data
timeline = [
{"step": "kernel_launch", "objects": {"threads": 4096, "blocks": 16, "warps": 128}},
{"step": "index_calculation", "objects": {"row_index": 4096, "col_index": 4096}},
{"step": "tile_phase_0_shared_memory_load", "objects": {"global_reads": 8192, "shared_stores": 8192}},
{"step": "tile_phase_0_sync_1", "objects": {"sync_barriers": 16}},
@attentionmech
attentionmech / logitlensterminalanim.py
Created April 11, 2025 11:21
logit lens animation gpt2
from nnsight import LanguageModel
import torch
import argparse
import os
import sys
import time
def clear_terminal():
os.system('cls' if os.name == 'nt' else 'clear')
@attentionmech
attentionmech / attention-entropy.ipynb
Created April 1, 2025 18:54
attention-entropy.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.