187 Followers
40 Following
51 Posts
linguistics/bio/computers/history/SF/gamedev enjoyer. i share stuff here sometimes, almost all made with my wife. dev at SecureDNA. she/they 🏳️‍⚧️
website / bloghttps://vgel.me
pronounsshe/they

New blog post: making a transformer by hand, without training! Want to understand transformers and attention better? This post goes through assigning each weight for a GPT-2-like transformer to understand how they work.

Goes thru designing a simple tokenization scheme, embeddings, the qkv weights and attention head, and projecting that back to get 100% accuracy at predicting a simple sequence! It even has explainers for matrices and softmax if you're a little rusty :-)

https://vgel.me/posts/handmade-transformer

I made a transformer by hand (no training!)

To better understand how transformers work, I hand-assigned all the weights to predict a simple sequence.

i've also finished implementing strings and the compiler ended up as *exactly* 500 lines 🙂

time to write a literate programming environment to explain this whole thing, hopefully it won't take 20k words...

summing together the votes from birdsite and here, strings won 29 to 18 (out of 47 total votes). sorry mastodon! because i love you more i'll try to still add an addendum about how to add floats, as an exercise for the reader :-)
implications,,,

this is the same code as the donut sdf post (http://vgel.me/posts/donut) but ported to glsl and with the sampled normal replaced with an analytic one to save characters

twigl link: https://bit.ly/3IGn2sW

Signed distance functions in 46 lines of Python

A walkthrough of 46 lines of code that render a 3D ASCII donut using signed distance functions.

float z=-9.;vec2 F=FC.xy/r.xy-.5;for(int i=0;i++<30;){float X=F.x*cos(t)-z*sin(t),Z=F.x*sin(t)+z*cos(t),h=sqrt(X*X+F.y*F.y)-.2,d=sqrt(h*h+Z*Z)-.05;if(d<.01){vec3 n=normalize(vec3(X*h,F.y*h,Z*(h+.2)));o=vec4(.95,.5,mix(.8,.3,sign(n.z+.3)),1.)*vec4(.3+max(0.,n.y));break;}z+=d;}

// #sdf #rendering #glsl #donut

my singlepass c compiler (for a WIP blog post) is at 462 lines and I only have room for one of these, which would be more interesting?

(it already supports ints, pointers, arrays, if / while / do / for, functions, typedefs with the ~lexer hack~, and a few other things! goal is < 500 lines)

#blog #compiler

floats
60%
strings
40%
Poll ended at .

proposal for c 2.0:

int main() {
1 = 2;
if (1 == 2) return 1;
else if (*(&1) == 2) return 0;
else return 1;
}
// main() returns 0

12 cases now! (instead of sleeping... it's 5am, whoops) added pointers-to-stack, if, while, modulus and bitwise ops, multiple declarations (int x, *p, **pp), and fixed my busted stack frame implementation😅

335 lines of code so far! getting scared about writing this up...

4 cases! (I added declaration support). I also rewrote the stack from using the webassembly stack to an explicit stack to allow pointers to stack variables, but I didn't actually add pointers yet...