Warmcat homepage andy@warmcat.com
libwebsockets
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1747629362, "reponame":"libclamma", "desc":"Modernized llama2.c inference engine", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://warmcat.com/repo/libclamma", "f":3, "items": [ {"schema":"libjg2-1", "cid":"6c67a1d0da92e46505cadd9413fb86f1", "commit": {"type":"commit", "time": 1691260891, "time_ofs": 0, "oid_tree": { "oid": "ca989a11fa58ea7a4e4ce74a26098786dc9d6e86", "alias": []}, "oid":{ "oid": "0447b06e7c30a12ff37d4e34d700065405025439", "alias": []}, "msg": "simplify rope", "sig_commit": { "git_time": { "time": 1691260891, "offset": 0 }, "name": "Andrej Karpathy", "email": "andrej.karpathy@gmail.com", "md5": "d06a9cdc46d537f09ccc4bd6b822dd78" }, "sig_author": { "git_time": { "time": 1691260891, "offset": 0 }, "name": "Andrej Karpathy", "email": "andrej.karpathy@gmail.com", "md5": "d06a9cdc46d537f09ccc4bd6b822dd78" }}, "body": "simplify rope\n" , "diff": "diff --git a/run.c b/run.c\nindex 2f29f35..22f3fa5 100644\n--- a/run.c\n+++ b/run.c\n@@ -232,24 +232,18 @@ void transformer(int token, int pos, Config* p, RunState* s, TransformerWeights*\n matmul(s-\u003ek, s-\u003exb, w-\u003ewk + l*dim*dim, dim, dim);\n matmul(s-\u003ev, s-\u003exb, w-\u003ewv + l*dim*dim, dim, dim);\n \n- // apply RoPE rotation to the q and k vectors for each head\n- for (int h \u003d 0; h \u003c p-\u003en_heads; h++) {\n- // get the q and k vectors for this head\n- float* q \u003d s-\u003eq + h * head_size;\n- float* k \u003d s-\u003ek + h * head_size;\n- // rotate q and k by the freq_cis_real and freq_cis_imag\n- for (int i \u003d 0; i \u003c head_size; i+\u003d2) {\n- float q0 \u003d q[i];\n- float q1 \u003d q[i+1];\n- float k0 \u003d k[i];\n- float k1 \u003d k[i+1];\n- float fcr \u003d freq_cis_real_row[i/2];\n- float fci \u003d freq_cis_imag_row[i/2];\n- q[i] \u003d q0 * fcr - q1 * fci;\n- q[i+1] \u003d q0 * fci + q1 * fcr;\n- k[i] \u003d k0 * fcr - k1 * fci;\n- k[i+1] \u003d k0 * fci + k1 * fcr;\n- }\n+ // RoPE relative positional encoding: complex-valued rotate q and k by freq_cis in each head\n+ for (int i \u003d 0; i \u003c dim; i+\u003d2) {\n+ float q0 \u003d s-\u003eq[i];\n+ float q1 \u003d s-\u003eq[i+1];\n+ float k0 \u003d s-\u003ek[i];\n+ float k1 \u003d s-\u003ek[i+1];\n+ float fcr \u003d freq_cis_real_row[(i % head_size) / 2];\n+ float fci \u003d freq_cis_imag_row[(i % head_size) / 2];\n+ s-\u003eq[i] \u003d q0 * fcr - q1 * fci;\n+ s-\u003eq[i+1] \u003d q0 * fci + q1 * fcr;\n+ s-\u003ek[i] \u003d k0 * fcr - k1 * fci;\n+ s-\u003ek[i+1] \u003d k0 * fci + k1 * fcr;\n }\n \n // save key,value at this time step (pos) to our kv cache\n","s":{"c":1747629362,"u": 1480}} ],"g": 2166,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}