Skip to main content
QUICK REVIEW

[Paper Review] Automatic Full Compilation of Julia Programs and ML Models to Cloud TPUs

Keno Fischer, Elliot Saba|arXiv (Cornell University)|Oct 23, 2018
Distributed and Parallel Computing SystemsComputer Science4 references9 citations
TL;DR

This paper presents a compiler-based method to automatically offload full Julia programs—including neural network models like VGG19 and their gradients—to Google Cloud TPUs via the XLA compiler. By leveraging Julia’s static analysis and type inference, the approach compiles entire forward and backward passes into a single fused TPU kernel, achieving a 227x speedup (0.23s vs. 52.4s) on a 100-image batch, with less than 1000 lines of code and no changes to the Julia compiler or core packages.

ABSTRACT

Google's Cloud TPUs are a promising new hardware architecture for machine learning workloads. They have powered many of Google's milestone machine learning achievements in recent years. Google has now made TPUs available for general use on their cloud platform and as of very recently has opened them up further to allow use by non-TensorFlow frontends. We describe a method and implementation for offloading suitable sections of Julia programs to TPUs via this new API and the Google XLA compiler. Our method is able to completely fuse the forward pass of a VGG19 model expressed as a Julia program into a single TPU executable to be offloaded to the device. Our method composes well with existing compiler-based automatic differentiation techniques on Julia code, and we are thus able to also automatically obtain the VGG19 backwards pass and similarly offload it to the TPU. Targeting TPUs using our compiler, we are able to evaluate the VGG19 forward pass on a batch of 100 images in 0.23s which compares favorably to the 52.4s required for the original model on the CPU. Our implementation is less than 1000 lines of Julia, with no TPU specific changes made to the core Julia compiler or any other Julia packages.

Motivation & Objective

  • To enable full automatic compilation of general Julia programs, including machine learning models, to Cloud TPUs without requiring changes to the Julia compiler or core packages.
  • To support end-to-end automatic differentiation of models via integration with Zygote.jl, enabling offloading of both forward and backward passes to TPUs.
  • To demonstrate that Julia’s high-level language features—such as multiple dispatch, higher-order functions, and generic programming—can be effectively compiled to TPU-executable XLA IR.
  • To enable efficient, fused execution of complex workloads (e.g., training loops) on TPUs by compiling entire program regions into a single kernel.
  • To provide a scalable, extensible, and user-friendly interface for compiling Julia code to TPUs, overcoming the limitations of tracing-based or framework-specific approaches.

Proposed method

  • The method compiles Julia code directly to XLA Intermediate Representation (IR) using the Julia compiler’s static analysis and type inference capabilities, avoiding runtime tracing.
  • It leverages Julia’s multiple dispatch and generic programming to express and optimize transformations from Julia IR to XLA IR, enabling type-generic compilation.
  • The approach fuses control flow constructs (e.g., loops, conditionals) into XLA operations by analyzing data dependencies and applying static optimizations before offloading.
  • It integrates with Zygote.jl’s source-to-source automatic differentiation to generate and offload both forward and backward passes as a single fused TPU kernel.
  • The implementation uses the XLA compiler’s general-purpose IR to target TPUs, enabling support for non-TensorFlow workloads and non-ML applications dominated by linear algebra.
  • It employs infeed/outfeed operations to manage data transfers between CPU and TPU, and supports SoA-to-AoS transformations via StructsOfArrays to handle XLA’s type constraints.

Experimental results

Research questions

  • RQ1Can full Julia programs, including control flow and high-level abstractions, be automatically compiled to TPU-executable XLA kernels without runtime tracing?
  • RQ2To what extent can Julia’s multiple dispatch and generic programming features be leveraged to generate efficient, type-specific XLA kernels?
  • RQ3Can the combination of Julia’s compiler infrastructure and Zygote’s automatic differentiation enable end-to-end offloading of both forward and backward passes of a deep learning model to TPUs?
  • RQ4How does the performance of a fully offloaded VGG19 model compare to CPU execution, and what is the achievable speedup on a Cloud TPU?
  • RQ5What are the key limitations in debuggability, type inference, and distributed execution when compiling general Julia code to TPUs via XLA?

Key findings

  • The method successfully compiles the full forward pass of a VGG19 model into a single fused TPU kernel, achieving a 227x speedup over CPU execution (0.23s vs. 52.4s for a batch of 100 images).
  • The approach supports end-to-end offloading of both forward and backward passes, including the training loop, by leveraging Zygote.jl’s automatic differentiation and XLA’s fusion capabilities.
  • The implementation is less than 1000 lines of Julia code and requires no modifications to the core Julia compiler or external packages.
  • The method achieves stable performance measurements, with TPU compute time (FluXLA TPU) being significantly more consistent than total wall-clock time.
  • The approach is generalizable to non-ML Julia code as long as the workloads are dominated by linear algebra operations, suggesting broader applicability beyond deep learning.
  • The current implementation faces challenges in debuggability of type inference failures and limited support for XLA’s distributed primitives, which are identified as key areas for future improvement.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.