-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark of calling the Dex diagonal convolution from Jax.
Add a baseline for it of doing the same thing in Jax (as best I can navigate the convolution docs). Also adjust the continuous.py script to build and install Dex with the FFI library by default, so that both the executable and the Python bindings are accessible.
- Loading branch information
Showing
5 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import jax | ||
import dex | ||
from dex.interop import jax as djax | ||
import numpy as np | ||
|
||
import time | ||
import timeit | ||
|
||
def bench_python(f, loops=None): | ||
"""Return average runtime of `f` in seconds and number of iterations used.""" | ||
if loops is None: | ||
f() | ||
s = time.perf_counter() | ||
f() | ||
e = time.perf_counter() | ||
duration = e - s | ||
loops = max(4, int(2 / duration)) # aim for 2s | ||
return (timeit.timeit(f, number=loops, globals=globals()) / loops, loops) | ||
|
||
|
||
def main(): | ||
with open('benchmarks/conv.dx', 'r') as f: | ||
m = dex.Module(f.read()) | ||
dex_conv = djax.primitive(m.conv_spec) | ||
shp = (int(m.n), int(m.width), int(m.side), int(m.side)) | ||
xs = jax.random.normal(jax.random.PRNGKey(1), shp, dtype=jax.numpy.float32) | ||
filter_size = int(m.filter_size) | ||
msg = ("TODO Make dex.interop.primitive return Jax Device Arrays, " | ||
"and change this assert to a block_until_ready() call.") | ||
assert isinstance(dex_conv(xs, filter_size), np.ndarray), msg | ||
time_s, loops = bench_python(lambda : dex_conv(xs, filter_size)) | ||
print(f"> Run time: {time_s} s \t(based on {loops} runs)") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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