Cortex is an ongoing project that aims at building a compiler and runtime infrastructure that efficiently compiles ML applications with irregular and dynamic control flow and even irregular data structure accesses. To begin with, we have built a framework that can handle models with recursive data structure traversals, as shown in the figure below. For this case, we are able to completely disentangle the recursive traversal from the tensor computations and partially evaluate the former allowing us to offload the entire tensor computation to the accelerator (currently we support CPUs and GPUs) at once. This means that we can generate highly optimized implementations we avoid the costs of frequent communication between the accelerator and the host CPU.