Skip to content

Commit 4430ead

Browse files
committed
update code base
1 parent 84e745a commit 4430ead

19 files changed

Lines changed: 4620 additions & 0 deletions

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Andrej
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# choose your compiler, e.g. gcc/clang
2+
# example override to clang: make run CC=clang
3+
CC = gcc
4+
5+
# the most basic way of building that is most likely to work on most systems
6+
.PHONY: runcc
7+
runcc: run.cc
8+
hipcc -o runcc run.cc -O2 --offload-arch=gfx908
9+
10+
.PHONY: clean
11+
clean:
12+
rm -f runcc

configurator.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Poor Man's Configurator. Probably a terrible idea. Example usage:
3+
$ python train.py config/override_file.py --batch_size=32
4+
this will first run config/override_file.py, then override batch_size to 32
5+
6+
The code in this file will be run as follows from e.g. train.py:
7+
>>> exec(open('configurator.py').read())
8+
9+
So it's not a Python module, it's just shuttling this code away from train.py
10+
The code in this script then overrides the globals()
11+
12+
I know people are not going to love this, I just really dislike configuration
13+
complexity and having to prepend config. to every single variable. If someone
14+
comes up with a better simple Python solution I am all ears.
15+
"""
16+
17+
import sys
18+
from ast import literal_eval
19+
20+
for arg in sys.argv[1:]:
21+
if '=' not in arg:
22+
# assume it's the name of a config file
23+
assert not arg.startswith('--')
24+
config_file = arg
25+
print(f"Overriding config with {config_file}:")
26+
with open(config_file) as f:
27+
print(f.read())
28+
exec(open(config_file).read())
29+
else:
30+
# assume it's a --key=value argument
31+
assert arg.startswith('--')
32+
key, val = arg.split('=')
33+
key = key[2:]
34+
if key in globals():
35+
try:
36+
# attempt to eval it it (e.g. if bool, number, or etc)
37+
attempt = literal_eval(val)
38+
except (SyntaxError, ValueError):
39+
# if that goes wrong, just use the string
40+
attempt = val
41+
# ensure the types match ok
42+
assert type(attempt) == type(globals()[key])
43+
# cross fingers
44+
print(f"Overriding: {key} = {attempt}")
45+
globals()[key] = attempt
46+
else:
47+
raise ValueError(f"Unknown config key: {key}")

0 commit comments

Comments
 (0)