{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1747290248,
"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":"4da78ad6ca5faeca020c41cf489d7d3f",
"commit": {"type":"commit",
"time": 1691255291,
"time_ofs": 0,
"oid_tree": { "oid": "b8d3c59a230d049e55d2975559a8327748607573", "alias": []},
"oid":{ "oid": "dcef5ff7c720265752b7963c244c70846d6be252", "alias": []},
"msg": "add a bit less embarassing argparse that uses keyword arguments instead of positional argument",
"sig_commit": { "git_time": { "time": 1691255291, "offset": 0 }, "name": "Andrej Karpathy", "email": "andrej.karpathy@gmail.com", "md5": "d06a9cdc46d537f09ccc4bd6b822dd78" },
"sig_author": { "git_time": { "time": 1691255291, "offset": 0 }, "name": "Andrej Karpathy", "email": "andrej.karpathy@gmail.com", "md5": "d06a9cdc46d537f09ccc4bd6b822dd78" }},
"body": "add a bit less embarassing argparse that uses keyword arguments instead of positional arguments\n"
,
"diff": "diff --git a/README.md b/README.md\nindex a4bc158..85340b9 100644\n--- a/README.md\n+++ b/README.md\n@@ -46,10 +46,10 @@ This still runs at interactive rates and samples more coherent and diverse stori\n \n \u003e Once upon a time, there was a little girl named Lily. She loved playing with her toys on top of her bed. One day, she decided to have a tea party with her stuffed animals. She poured some tea into a tiny teapot and put it on top of the teapot. Suddenly, her little brother Max came into the room and wanted to join the tea party too. Lily didn't want to share her tea and she told Max to go away. Max started to cry and Lily felt bad. She decided to yield her tea party to Max and they both shared the teapot. But then, something unexpected happened. The teapot started to shake and wiggle. Lily and Max were scared and didn't know what to do. Suddenly, the teapot started to fly towards the ceiling and landed on the top of the bed. Lily and Max were amazed and they hugged each other. They realized that sharing was much more fun than being selfish. From that day on, they always shared their tea parties and toys.\n \n-You can also prompt the model with a prefix (sadly, because this is currently done via positional arguments, you also have to specify temperature 1.0 and 256 steps, before you enter the prompt):\n+You can also prompt the model with a prefix or a number of additional command line arguments, e.g. to sample at temperature 0.8 for 256 steps and with a prompt:\n \n ```bash\n-./run stories42M.bin 1.0 256 \u0022One day, Lily met a Shoggoth\u0022\n+./run stories42M.bin -t 0.8 -n 256 -p \u0022One day, Lily met a Shoggoth\u0022\n ```\n \n \u003e One day, Lily met a Shoggoth. He was very shy, but was also very generous. Lily said “Hello Shoggy! Can I be your friend?” Shoggy was happy to have a friend and said “Yes, let’s explore the universe together!” So they set off on a journey to explore the universe. As they travelled, Shoggy was happy to explain to Lily about all the wonderful things in the universe. At the end of the day, Lily and Shoggy had gathered lots of wonderful things from the universe, and they both felt very proud. They promised to explore the universe as one big pair and to never stop being generous to each other.\ndiff --git a/run.c b/run.c\nindex 16ecebb..2f29f35 100644\n--- a/run.c\n+++ b/run.c\n@@ -448,35 +448,40 @@ int argmax(float* v, int n) {\n }\n // ----------------------------------------------------------------------------\n \n+void error_usage() {\n+ printf(\u0022Usage: run \u003ccheckpoint\u003e [options]\u005cn\u0022);\n+ printf(\u0022Example: run model.bin -t 0.9 -n 256 -p \u005c\u0022Once upon a time\u005c\u0022\u005cn\u0022);\n+ printf(\u0022Options:\u005cn\u0022);\n+ printf(\u0022 -t \u003cfloat\u003e temperature, default 0.9\u005cn\u0022);\n+ printf(\u0022 -s \u003cint\u003e random seed, default time(NULL)\u005cn\u0022);\n+ printf(\u0022 -n \u003cint\u003e number of steps to run for, default 256. 0 \u003d max_seq_len\u005cn\u0022);\n+ printf(\u0022 -p \u003cstring\u003e prompt string, default none\u005cn\u0022);\n+ exit(EXIT_FAILURE);\n+}\n+\n int main(int argc, char *argv[]) {\n \n- // poor man's C argparse\n+ // default inits\n char *checkpoint \u003d NULL; // e.g. out/model.bin\n- float temperature \u003d 0.9f; // e.g. 1.0, or 0.0\n- int steps \u003d 256; // max number of steps to run for, 0: use seq_len\n+ float temperature \u003d 0.9f; // 0.0 \u003d greedy \u0026 deterministic, 1.0 \u003d max uncertainty\n+ rng_seed \u003d (unsigned int)time(NULL); // seed rng with time by default\n+ int steps \u003d 256; // number of steps to run for\n char *prompt \u003d NULL; // prompt string\n \n- // 'checkpoint' is necessary arg\n- if (argc \u003c 2) {\n- printf(\u0022Usage: %s \u003ccheckpoint_file\u003e [temperature] [steps] [prompt]\u005cn\u0022, argv[0]);\n- return 1;\n- }\n- if (argc \u003e\u003d 2) {\n- checkpoint \u003d argv[1];\n- }\n- if (argc \u003e\u003d 3) {\n- // optional temperature. 0.0 \u003d (deterministic) argmax sampling. 1.0 \u003d baseline\n- temperature \u003d atof(argv[2]);\n+ // poor man's C argparse so we can override the defaults above from the command line\n+ if (argc \u003e\u003d 2) { checkpoint \u003d argv[1]; } else { error_usage(); }\n+ for (int i \u003d 2; i \u003c argc; i+\u003d2) {\n+ // do some basic validation\n+ if (i + 1 \u003e\u003d argc) { error_usage(); } // must have arg after flag\n+ if (argv[i][0] !\u003d '-') { error_usage(); } // must start with dash\n+ if (strlen(argv[i]) !\u003d 2) { error_usage(); } // must be -x (one dash, one letter)\n+ // read in the args\n+ if (argv[i][1] \u003d\u003d 't') { temperature \u003d atof(argv[i + 1]); }\n+ else if (argv[i][1] \u003d\u003d 's') { rng_seed \u003d atoi(argv[i + 1]); }\n+ else if (argv[i][1] \u003d\u003d 'n') { steps \u003d atoi(argv[i + 1]); }\n+ else if (argv[i][1] \u003d\u003d 'p') { prompt \u003d argv[i + 1]; }\n+ else { error_usage(); }\n }\n- if (argc \u003e\u003d 4) {\n- steps \u003d atoi(argv[3]);\n- }\n- if (argc \u003e\u003d 5) {\n- prompt \u003d argv[4];\n- }\n-\n- // seed rng with time. if you want deterministic behavior use temperature 0.0\n- rng_seed \u003d (unsigned int)time(NULL);\n \n // read in the model.bin file\n Config config;\n","s":{"c":1747290248,"u": 2267}}
],"g": 3867,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}