Skip to content

Instantly share code, notes, and snippets.

# /// script
# dependencies = [
# "torch",
# "numpy",
# ]
# ///
import torch
import torch.nn as nn
import numpy as np
@tnguyen21
tnguyen21 / grid_trpo.py
Created October 10, 2025 15:54
toy RL TRPO implementation with notes
# /// script
# dependencies = [
# "torch",
# "numpy",
# ]
# ///
import torch
import torch.nn as nn
import numpy as np
@tnguyen21
tnguyen21 / grid_pg.py
Created October 10, 2025 15:53
toy policy gradient RL implementation
# /// script
# dependencies = [
# "torch",
# "numpy",
# ]
# ///
import torch
import torch.nn as nn
import numpy as np
@tnguyen21
tnguyen21 / llm_wtf.py
Last active October 6, 2025 23:24
greedy sample models from different providers
#!/usr/bin/env -S uv run python
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests",
# "rich",
# ]
# ///
"""
@tnguyen21
tnguyen21 / modal_modded_nanogpt.py
Created September 5, 2025 00:57
reproduce modded-nanogpt speed run on modal
import os
import modal
image = (
modal.Image.debian_slim()
.apt_install("git")
.run_commands(
"pip install --upgrade pip",
"pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu126 --upgrade",
"git clone --depth 1 https://github.com/KellerJordan/modded-nanogpt /opt/modded-nanogpt",
@tnguyen21
tnguyen21 / tspl.c
Created August 22, 2025 22:47 — forked from VictorTaelin/tspl.c
TSPL in C - Simple Parser Library - λ-Calculus Demo Parser
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
const char* input;
size_t index;
import torch
from torch.utils.data import Dataset, DataLoader
import numpy as np
from typing import List, Dict, Tuple, Optional, Union
import random
from datetime import datetime, timedelta
class PinnerFormerDataset(Dataset):
"""
@tnguyen21
tnguyen21 / anki_intake.py
Created December 30, 2024 17:02
script for calculating how many prompts reviewed per day and how long daily review sessions take
import math
p = 0.9 # success rate
np = 1 - p
new_cards = 40
ease = 2.5
max_days = 365
queue = [{"base_days": 5, "factor": 1}]
total = 0
@tnguyen21
tnguyen21 / closures.py
Created September 25, 2024 16:40
example of odd closure behavior in python
a = "global"
try:
def showA():
print(a)
showA() # prints "global"
a = "block"
showA() # prints "block"
except:
...
@tnguyen21
tnguyen21 / scrape.py
Created August 26, 2024 22:22
Arxiv Scraper
"""
A python program to retreive recrods from ArXiv.org in given
categories and specific date range.
based off of https://github.com/Mahdisadjadi/arxivscraper
"""
from __future__ import print_function
import xml.etree.ElementTree as ET
import datetime
import time