Skip to main content
QUICK REVIEW

[Paper Review] Auto-Vectorizing TensorFlow Graphs: Jacobians, Auto-Batching And Beyond

Ashish Agarwal, Igor Ganichev|arXiv (Cornell University)|Mar 8, 2019
Scientific Computing and Data ManagementDecision Sciences18 references6 citations
TL;DR

This paper introduces a static loop vectorization optimization for TensorFlow's high-level dataflow IR, enabling efficient auto-batching, per-example gradients, and Jacobian computation through a new symbolic parallel-for abstraction. The approach achieves up to 60x speedup on GPU over TensorFlow's native loop implementation and over 38x over DyNet's dynamic batching, especially for large batch sizes and high-dimensional outputs.

ABSTRACT

We propose a static loop vectorization optimization on top of high level dataflow IR used by frameworks like TensorFlow. A new statically vectorized parallel-for abstraction is provided on top of TensorFlow, and used for applications ranging from auto-batching and per-example gradients, to jacobian computation, optimized map functions and input pipeline optimization. We report huge speedups compared to both loop based implementations, as well as run-time batching adopted by the DyNet framework.

Motivation & Objective

  • To address the performance bottleneck of loop-based implementations in TensorFlow for operations like auto-batching, per-example gradients, and Jacobian computation.
  • To reduce runtime overheads associated with dynamic batching in frameworks like DyNet by enabling static, compile-time vectorization.
  • To improve hardware utilization and enable efficient execution of nested and dynamic control flow patterns in machine learning models.
  • To provide a general-purpose, reusable abstraction for vectorizing arbitrary loops in TensorFlow's high-level IR.
  • To extend TensorFlow's capabilities to natively support efficient computation of Jacobians and Hessians, which are currently poorly optimized or unsupported.

Proposed method

  • Introduces a new static vectorized parallel-for (pfor) abstraction that operates on TensorFlow's high-level dataflow IR during graph construction.
  • Applies static loop vectorization by fusing loop bodies into vectorized operations, eliminating loops for embarrassingly parallel computations.
  • Uses symbolic tensors to represent the output of vectorized loop iterations, enabling optimization across nested control flow and dynamic shapes.
  • Applies the pfor abstraction to auto-batch models by wrapping forward passes in a loop over batch elements, then vectorizing the entire loop.
  • Computes per-example gradients by vectorizing both forward and backward passes within a single pfor construct.
  • Enables Jacobian computation by vectorizing gradient computation across each output element, treating each as an independent scalar computation.

Experimental results

Research questions

  • RQ1Can static loop vectorization in TensorFlow's high-level IR significantly outperform dynamic loop-based implementations for auto-batching and gradient computation?
  • RQ2To what extent can pfor-based vectorization improve performance for Jacobian computation, especially for non-scalar outputs and complex models like RNNs?
  • RQ3How does the performance of pfor compare to run-time batching in DyNet, particularly under varying batch sizes and output dimensions?
  • RQ4What are the performance bottlenecks in pfor's current implementation, especially for variable-length sequences or nested loops?
  • RQ5Can pfor enable previously infeasible or inefficient operations like hessian computation or input pipeline optimization through vectorized control flow?

Key findings

  • The pfor-based implementation achieves up to 60x speedup over TensorFlow's native tf.while_loop for Jacobian computation at high output sizes (128), especially on VGG16 and LSTM models.
  • For per-example gradients on LSTM, pfor outperforms tf.while_loop by a factor of 38 at a batch size of 256, demonstrating superior GPU utilization.
  • On MNIST, pfor shows consistent throughput improvements over tf.while_loop, with significant gains at larger batch sizes due to better vectorization and memory access patterns.
  • The performance gap between pfor and tf.while_loop widens with increasing output dimensionality, indicating strong scalability of the vectorization approach.
  • LSTM models show lower relative speedups due to variable sequence lengths and residual overheads in vectorizing tf.while_loop, suggesting room for optimization in handling dynamic shapes.
  • The method enables previously unsupported operations such as Jacobians of dynamic RNNs and Hessians of non-scalar outputs, opening new research avenues.

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.