Efficient physics-informed neural networks using hash encoding

Xinquan Huang, Tariq Alkhalifah · DOI

This paper, titled "Efficient physics-informed neural networks using hash encoding," presents a significant performance boost for Physics-Informed Neural Networks (PINNs) by borrowing a clever trick from the world of 3D computer vision.

TL;DR

By integrating multi-resolution hash encoding—a technique popularized by NVIDIA’s Instant-NGP—researchers have achieved a ~10x speedup in training Physics-Informed Neural Networks (PINNs). To make this work, they swapped standard automatic differentiation for finite-difference methods to handle the "jagged" derivatives inherent in hash-based representations, allowing PINNs to solve complex PDEs in seconds rather than minutes or hours.

What Problem Does This Paper Address?

PINNs are a powerful tool for solving Partial Differential Equations (PDEs) because they represent solutions as continuous functions rather than discrete grids. However, they have a notorious "speed limit."

Standard PINNs suffer from spectral bias: neural networks are naturally "lazy" and prefer learning low-frequency, smooth components of a function before tackling high-frequency details. Furthermore, raw coordinate inputs ($x, y, t$) provide a very small "imprint" on the network, forcing it to spend thousands of epochs searching a high-dimensional parameter space to find the right "shape" for the solution. This makes them significantly slower than traditional numerical solvers for many engineering applications.

Methods

The authors propose a two-pronged architectural shift:

  1. Multi-resolution Hash Encoding: Instead of feeding raw coordinates into the network, the input is passed through a hierarchy of hash tables. These tables store trainable feature vectors at different spatial resolutions. When a coordinate is queried, the system looks up the surrounding "voxel" corners, interpolates the values, and passes this "locally-aware" vector to a small MLP. This allows the network to "see" local features immediately.
  2. Finite-Difference (FD) Derivatives: Standard PINNs rely on Automatic Differentiation (AD) to calculate the derivatives required by the PDE loss. However, because hash encoding uses linear interpolation between grid points, its derivatives are discontinuous (step-like). AD struggles with these "jagged" gradients. The authors propose using Finite-Difference calculations instead. FD is more robust to these point-induced discontinuities and, for higher-order derivatives, can actually be more computationally efficient.

Datasets

The method was evaluated on three classic PDE benchmarks used to simulate physical phenomena:

  • Burgers Equation: Models 1D viscous fluid flow and shock waves.
  • Helmholtz Equation: Models 2D wave propagation, common in seismology and acoustics.
  • Navier-Stokes Equation: The "gold standard" for 2D incompressible fluid dynamics (modeling momentum and mass conservation).

Reference "ground truth" solutions were generated using traditional numerical methods to verify the PINN's accuracy.

Key Insights and Ideas

  • Representation Matters: The "Aha!" moment is that the bottleneck in PINNs isn't just the optimizer or the depth of the network—it's how the network "perceives" space. Hash encoding acts as a powerful pre-conditioner for the loss landscape.
  • The AD vs. FD Trade-off: While AD is usually the pride and joy of deep learning, this paper shows it can be a liability when using grid-based encodings. Switching to FD isn't just a workaround; it’s a necessity for stability in this architecture.
  • Efficiency without Bloat: The authors achieved these speedups while keeping the total number of trainable parameters roughly equivalent to a vanilla PINN, proving the gains come from the efficiency of the representation rather than just throwing more hardware at the problem.

Key Results

The proposed "Hash-PINN" outperformed the vanilla implementation across the board:

  • Burgers Equation: Reached target accuracy in under 2,500 epochs, whereas the vanilla PINN required nearly 20,000.
  • Navier-Stokes: The Hash-PINN hit the target accuracy in 2,270 epochs. Remarkably, the vanilla PINN failed to reach that same accuracy level even after 50,000 epochs.
  • Wall-clock Time: On an NVIDIA A100 GPU, the Helmholtz equation was solved in 21 seconds with hash encoding, compared to 155 seconds for the standard approach—a nearly 7.5x improvement in total cost, with some cases showing up to a 24x reduction in training effort.

Limitations and Future Work

  • Hyperparameter Tuning: The performance is sensitive to the hash table size, the number of resolution levels, and the choice of the "finest" and "coarsest" grid resolutions. Finding the "sweet spot" for a new PDE remains a manual task.
  • FD Approximation: Finite-difference is an approximation. While it is more stable for hash encodings, it may introduce its own numerical errors if the step size ($\Delta x$) isn't carefully chosen relative to the grid resolution.
  • Higher-Order Interpolation: The authors suggest that future work could explore higher-order interpolation (like cubic splines) for the hash vectors, which might smooth out the derivatives enough to make Automatic Differentiation viable again.

Summary updated

BibTeX
@article{huang2024efficient,
  author = {Xinquan Huang and Tariq Alkhalifah},
  title = {{Efficient physics-informed neural networks using hash encoding}},
  journal = {Journal of Computational Physics},
  year = {2024},
  doi = {10.1016/j.jcp.2024.112760},
}

Loading related content...

Figure