Search

Search papers and lessons

Instant neural graphics primitives with a multiresolution hash encoding

Thomas Müller, Alex Evans, Christoph Schied et al. · 2022

Instant NGP speeds up small neural networks for graphics by giving them a multiresolution hash table of trainable features, so training takes seconds on one GPU.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • Calculus
  • Neural network basics
  • Linear algebra
  • Algorithms
  • ReadReady to readNot yet

TL;DR

Many graphics tasks fit a function with a small neural network: a 3D point goes in, a colour or a distance comes out. Such networks are slow to train when they are big enough to be accurate. This paper puts a multiresolution hash table of trainable feature vectors in front of a tiny network. The table holds the detail, the network stays small, and the whole system trains in seconds on one GPU. The paper reports that HD scenes can be rendered at about 60 frames per second.

Builds on: NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis, Feedforward Neural Network, Hash Table, Linear Interpolation, Positional Encoding · Leads to: later real-time neural rendering systems (no lesson node yet)

Why it mattered

Neural radiance fields (NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis) had made it possible to store a scene in a network, but training took hours and rendering was slow. This paper cut training from hours to seconds and showed that the same encoding works on four different tasks: 2D gigapixel images, signed distance functions of 3D shapes, neural radiance caching inside a path tracer, and NeRF itself. The authors release the source code of the encoding and of the graphics primitives, plus PyTorch bindings.

The problem

A neural graphics primitive is a function, usually a small multilayer perceptron, that maps low-dimensional coordinates to appearance or geometry. Two properties are needed at once: the function must capture sharp, local detail, and it must be cheap to train and to evaluate.

Two earlier routes each gave up one of these:

  1. A pure network with a frequency encoding. The input is passed through sine and cosine waves at doubling frequencies (the Positional Encoding idea). This is simple, but the network must be large to resolve fine detail, so training is slow.
  2. A dense grid of trainable features. Each grid point stores a feature vector, and the network reads an interpolated value. This is fast to fit but wasteful. The paper's example is a 128 by 128 by 128 grid of 16-dimensional features, which has 33.6 million trainable parameters. Only 53,807 of its cells (2.57 percent) touch the visible surface, so most of the memory describes empty space.

Sparse structures such as octrees fix the waste, but they must be built or pruned during training. That needs task-specific data-structure maintenance during training, which the paper wants to avoid.

The paper asks for an encoding that is adaptive without any structural updates, has constant cost per lookup, and maps well to parallel hardware.

How it works

Take one input point x in a 2D or 3D space that has been rescaled into the unit cube. The encoding runs the following steps. Each step is shown with symbols; the Linear Interpolation and Hash Table ideas are used in steps 3 and 4.

  1. Choose the levels. The encoding has L = 16 levels. Level l has a grid resolution N_l, and the resolutions grow geometrically from a coarsest value N_min to a finest value N_max. Table 1 of the paper uses N_min = 16 and N_max between 512 and 524,288, depending on the task.
  2. Find the surrounding cell at each level. At level l, multiply x by N_l and take the integer corners below and above it. In 2D those are 4 corners, in 3D they are 8. Each corner is a grid vertex with integer coordinates.
  3. Turn each corner into a table index. If the full grid at this level has no more than T entries, each corner gets its own slot, so there is no collision. If it has more, the corner's integer coordinates are hashed to a slot in a table of T entries. Every level has its own table of up to T feature vectors, each with F = 2 numbers.
  4. Read and blend. Look up the feature vector at each corner. Blend the corners by linear interpolation, weighted by how far x sits inside its cell, so the result changes smoothly as x moves.
  5. Concatenate and feed the network. The blended vectors from all 16 levels are joined into one long vector of length 16 times 2 = 32 (plus any extra inputs such as the view direction). A small MLP reads this vector and outputs the quantity the task needs.
  6. Train everything together. The loss is sent back through the MLP, then through the blend, then into the feature vectors at the corners that were read. Only those few vectors receive an update, so each training step touches very little memory.

A tiny check on step 3: with N_min = 16 and N_max = 512 at L = 16, the growth factor is 512 divided by 16, raised to the power 1 over 15, which is 32 to the power 1 over 15, or about 1.26. Level 1 then has resolution floor(16 times 1.26), which is 20, and the 1:1 rule holds at this level for any table of at least 21 cubed, or 9,261, entries.

024681012140100200300400500level lgrid resolution N_l
  • N_l = 16 * 2^(l/3)
The resolution of each level grows geometrically. With N_min = 16 and N_max = 512, the 16 levels run from 16 to 512 with a factor of about 1.26 between neighbours.

The diagram below shows the flow for one input point.

flowchart LR
  A["Input point x"] --> B["For each of 16 levels: find 2^d surrounding corners"]
  B --> C["Hash corner coordinates to a slot in that level's table"]
  C --> D["Read feature vectors at corners"]
  D --> E["Blend by linear interpolation"]
  E --> F["Concatenate all 16 levels"]
  F --> G["Small MLP outputs colour or distance"]

The math

The encoding is defined by a few formulas, one per step above.

Level resolutions (step 1). Let N_min and N_max be the coarsest and finest resolutions. Then

Nl:=⌊Nmin⁡ b l⌋,b:=exp⁡ ⁣(ln⁡Nmax⁡−ln⁡Nmin⁡L−1).N_l := \left\lfloor N_{\min}\, b^{\,l} \right\rfloor, \qquad b := \exp\!\left(\frac{\ln N_{\max} - \ln N_{\min}}{L - 1}\right).

The paper's tasks have growth factors b between 1.26 and 2. Because L is large, b is small, so each level adds only a modest amount of detail.

Cell corners (step 2). For a point x in the unit cube, define

⌊xl⌋:=⌊x⋅Nl⌋,⌈xl⌉:=⌈x⋅Nl⌉.\lfloor \mathbf{x}_l \rfloor := \lfloor \mathbf{x} \cdot N_l \rfloor, \qquad \lceil \mathbf{x}_l \rceil := \lceil \mathbf{x} \cdot N_l \rceil.

These two integer vectors span a cell with 2 to the power d corners, where d is the number of dimensions.

Index (step 3). If (N_l + 1) to the power d is at most T, the level is dense and each corner maps to its own slot. Otherwise the corner coordinates x (here integers) are hashed by

h(x)=(⨁i=1dxi πi) mod T,h(\mathbf{x}) = \left( \bigoplus_{i=1}^{d} x_i \, \pi_i \right) \bmod T,

where the circled plus is a bitwise exclusive-or, and the primes are pi_1 = 1, pi_2 = 2,654,435,761, pi_3 = 805,459,861. Using 1 for the first dimension keeps neighbouring points in the same memory region, which helps the GPU cache.

Blend (step 4). With weights w_l = x_l minus the floor of x_l, the interpolated feature at level l is the d-linear blend of the 2 to the power d corner features. In 2D with corner values c00, c10, c01, c11 and weights (w_x, w_y),

f=(1−wy)[(1−wx) c00+wx c10]+wy[(1−wx) c01+wx c11].f = (1 - w_y)\big[(1 - w_x)\,c_{00} + w_x\,c_{10}\big] + w_y\big[(1 - w_x)\,c_{01} + w_x\,c_{11}\big].

Concatenate and train (steps 5 and 6). The encoded input is y = concatenation of the 16 level outputs, a vector of length L times F, plus auxiliary inputs. The network m(y; Phi) has weights Phi. The encoding has parameters theta, with at most T times L times F entries. In the paper's setting that is T times 32. Training minimises the loss with Adam, using beta_1 = 0.9, beta_2 = 0.99 and epsilon = 10 to the power minus 15. A weak L2 penalty of 10 to the power minus 6 is applied to the network weights, not to the table.

Memory with half precision. Entries are stored at 2 bytes each, with a full-precision master copy kept for updates. For T = 2 to the power 24, the table alone is 2 to the power 24 times 32 entries at 2 bytes, which is 1 GiB. This is our arithmetic from the paper's parameter bound and storage choice; the paper does not state this total.

Results

The paper reports results on four tasks. The numbers below come from the paper's text and tables.

Gigapixel images. On the Tokyo panorama, the ACORN baseline reached 38.59 dB after 36.9 hours of training. With a similar parameter count (T = 2 to the power 24), the hash encoding matched that 38.59 dB in about 2.5 minutes and peaked at 41.9 dB after 4 minutes. PSNR (peak signal-to-noise ratio) is measured in decibels; higher is better.

Signed distance functions. The paper compares with NGLOD, a strong octree-based baseline. At a similar parameter count, the hash encoding reaches similar intersection-over-union, but its surfaces show a grainy microstructure from hash collisions. The paper calls this the salient artifact of its encoding, caused by collisions the MLP cannot fully compensate for, and suggests filtering lookups or adding a smoothness prior as future fixes.

Neural radiance caching. Inside a path tracer, the cache's frame rate at 1920 by 1080 went from 147 to 133 frames per second with the hash encoding, a cost of about 0.7 ms that includes both training and inference. The sharper reconstruction is visible in the paper's Figure 9.

NeRF on the eight synthetic scenes. Table 2 reports the average PSNR over Mic, Ficus, Chair, Hotdog, Materials, Drums, Ship and Lego:

MethodTraining timeAverage PSNR (dB)
Ours: Hash1 s21.202
Ours: Hash15 s31.407
Ours: Hash1 min32.635
Ours: Hash5 min33.176
mip-NeRFabout hours33.090
NSVFabout hours31.739
NeRFabout hours31.005
Ours: Frequency5 min30.056

Two points matter. First, the hash method passes the original NeRF's average after about 15 seconds of training, and passes mip-NeRF's average (33.090) after 5 minutes. Second, the frequency-encoding version with a larger MLP, which the authors built as a control, needs about 5 minutes to approach NeRF's quality. The paper attributes the 20 to 60 times improvement over the hash-free version to the hash encoding and the smaller MLP, which separates the encoding's contribution from the code's. The limits are also clear: on the Materials scene, which has complex view-dependent reflections, mip-NeRF and NSVF are better, and the authors attribute this to the much smaller MLP that makes the speedup possible.

Reading guide

The paper's sections map to the prerequisites as follows.

  1. Section 1, Introduction and Section 2, Background: read with Positional Encoding (the sine and cosine formula) and Volume Rendering (what a NeRF's samples compute). The "parametric encodings" paragraph assumes you know what a feature grid is.
  2. Section 3, Multiresolution Hash Encoding: the core. Read with Hash Table, Hash Function and Linear Interpolation beside you. Figure 3 is the best single picture of the steps above.
  3. Section 4, Implementation: uses Rectified Linear Unit (ReLU), Glorot initialisation, Adam Optimizer and half-precision storage. Read it for the speed claims, not for the mechanism.
  4. Section 5, Experiments: 5.1 gigapixel, 5.2 SDFs, 5.3 radiance caching, 5.4 NeRF. The NeRF part assumes NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis and Spherical Harmonics for the view direction. Table 2 is the main quantitative result.
  5. Section 6, Discussion and Appendices A to E: the design alternatives (smoothstep interpolation, hash function choices, occupancy grids). Appendix E is needed only if you implement the NeRF pipeline.

Check yourself

QuestionWhy does the multiresolution hash table not need pruning or splitting during training, unlike octrees?Show answer

Each level has a fixed-size array of T feature vectors whose slots are chosen by a hash function of the corner coordinates. Nothing about the layout depends on the data, so no structure has to be built, updated or pruned. Sparse detail is handled because colliding gradients average, and the most important samples dominate that average, so the table fills the regions that matter.

QuestionAt a level with N_l = 20 in 3D, is the dense rule satisfied for a table with T = 2 to the power 14 entries? Show the arithmetic.Show answer

Compute (N_l + 1) cubed = 21 cubed = 9,261. Since 9,261 is less than 2 to the power 14 = 16,384, the rule (N_l + 1) to the power d at most T holds. Every corner gets its own slot, so this level has no collisions.

QuestionA 2D point has blend weights w_x = 0.5 and w_y = 0.5 and corner values c00 = 0, c10 = 4, c01 = 0, c11 = 8. What feature does step 4 give?Show answer

Use the formula: (1 - 0.5)[(1 - 0.5)(0) + 0.5(4)] + 0.5[(1 - 0.5)(0) + 0.5(8)] = 0.5[2] + 0.5[4] = 1 + 2 = 3.

QuestionWhy does the paper use the bitwise exclusive-or in its hash, and why does it set the first prime to 1?Show answer

The exclusive-or of per-dimension products scrambles the bits so that neighbouring cells in different dimensions land in unrelated slots, decorrelating the dimensions. Setting the first prime to 1 keeps the first dimension's index nearly sequential, which gives better cache coherence on the GPU, and the other two dimensions still provide enough scrambling.

QuestionApplied scenario: a team wants to fit a single 3D shape as a signed distance function on a laptop GPU. The paper's SDF results show a grainy surface. Which setting would you change first, and what do you lose?Show answer

Changing the table size T trades memory and speed for quality, and the paper's Figure 4 shows quality rising with T, but the graininess is a collision artifact that the paper says does not disappear with longer training. A reasonable first step is to accept the artifact for a fast prototype, or to filter lookups or add smoothness, which the paper leaves as future work. The option that removes the artifact is a collision-free structure such as the octree of NGLOD, which the paper notes is tailored to the reference shape and needs data-structure maintenance.

Sources

Read the full paper

Thomas Müller, Alex Evans, Christoph Schied et al., 2022. arXiv:2201.05989