This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The most atomic way to train and run inference for a GPT in pure, dependency-free Python. | |
| This file is the complete algorithm. | |
| Everything else is just efficiency. | |
| @karpathy | |
| """ | |
| import os # os.path.exists | |
| import math # math.log, math.exp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import time | |
| def progress(iterable, length=33): | |
| count = avg = 0 | |
| total = len(iterable) | |
| then = time.time() | |
| for it in iter(iterable): | |
| yield it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; 8-bit Xor-Shift random number generator. | |
| ; Created by Patrik Rak in 2008 and revised in 2011/2012. | |
| ; See http://www.worldofspectrum.org/forums/showthread.php?t=23070 | |
| org 40000 | |
| call rnd ; BASIC driver | |
| ld c,a | |
| ld b,0 | |
| ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <strings.h> | |
| /* | |
| * Pearson hashing (from Wikipedia) | |
| * | |
| * Pearson hashing is a hash function designed for fast execution on processors with 8-bit registers. | |
| * Given an input consisting of any number of bytes, it produces as output a single byte that is strongly | |
| * dependent on every byte of the input. Its implementation requires only a few instructions, plus a |