Welcome to MATXScript’s documentation!¶
Introduction¶
MATXScript(Matx) is a high-performance, extensible Python AOT compiler that compiles Python class/function to C++ without any runtime overhead. Typical speedups over Python are on the order of 10-100x. Matx supports pmap which can lead to speedups many times higher still.
Currently matx is widely used in Bytedance. Including:
Unify the training and inference for deep learning.
Accelerate some offline MapReduce tasks.
Provide flexibility for some C++ engines, etc.
A Quick Example¶
import matx
import timeit
def fib(n: int) -> int:
if n <= 1:
return n
else:
return fib(n - 1) + fib(n - 2)
if __name__ == '__main__':
fib_script = matx.script(fib)
# test on Macbook with m1 chip
print(f'Python execution time: {timeit.timeit(lambda: fib(30), number=10)}s') # 1.59s
print(f'Matx execution time: {timeit.timeit(lambda: fib_script(30), number=10)}s') # 0.03s