Papers
Topics
Authors
Recent
Search
2000 character limit reached

Fast Graph Decoder (FGD)

Updated 23 February 2026
  • The paper converts full softmax computation into a fast Euclidean nearest neighbor search via an inner-product-preserving transformation, reducing complexity from O(|V|) to O(log|V|).
  • FGD is a graph-based algorithm that constructs a small-world index over transformed word embeddings to efficiently retrieve top-K tokens during decoding.
  • FGD achieves significant runtime improvements in neural machine translation and language modeling with provable guarantees and minimal impact on precision.

The Fast Graph Decoder (FGD) is a graph-based algorithmic framework for accelerating one of the bottlenecks in neural sequence decoding: the softmax over large vocabularies in neural LLMs (NLMs). FGD navigates a specially constructed small-world nearest-neighbor graph over transformed word embeddings to efficiently retrieve the top-KK most likely output tokens for a given context. It achieves substantial speedups versus conventional full softmax computation, with negligible impact on accuracy, through a mathematically principled reduction of the top-KK inner product search to efficient graph-based Euclidean nearest neighbor search. FGD demonstrates strong empirical and theoretical performance, including orders-of-magnitude latency reductions in neural machine translation (NMT) and language modeling tasks, while providing provable approximation guarantees (Zhang et al., 2018).

1. Motivation and Problem Setting

Conventional beam-search decoding in NLMs requires evaluating a full softmax over vocabulary VV (size V|V|) for each extension of a partial hypothesis. Given context hRDh \in \mathbb{R}^D, the unnormalized logit for candidate word ii is si=hei+bis_i = h^\top e_i + b_i, with eie_i and bib_i the decoder output embedding and bias, respectively. The full softmax cost is O(DV)O(D |V|) per context, which becomes prohibitive for vocabularies in the tens or hundreds of thousands.

Crucially, only the top-KK0 hypotheses are needed at each step of beam search, with KK1. FGD directly capitalizes on this by seeking a sublinear-in-KK2 algorithm to find the indices KK3, rather than computing all KK4 softmax scores (Zhang et al., 2018).

2. Inner-Product to Nearest-Neighbor Formulation

FGD employs an inner-product-preserving transformation (IPPT) to recast the top-KK5 logit search as an equivalent nearest-neighbor search in Euclidean space. For each vocabulary item KK6 with KK7 and KK8, define

KK9

and

VV0

Similarly, the context is lifted to VV1. Then, the original logit VV2 is shown to be

VV3

This reduces the argmax over logits to a nearest-neighbor minimization with respect to Euclidean distance, i.e., finding the VV4 vocabulary indices with smallest VV5 [(Zhang et al., 2018), Lemma 3.1].

3. Graph Index Construction

The FGD index is a navigable small-world graph (typically HNSW) constructed offline from the set VV6 over the vocabulary. Each node corresponds to a transformed embedding; local edges connect to VV7 nearest neighbors by Euclidean distance, and additional long-range shortcuts ensure a logarithmic diameter.

Graph construction is VV8, performed once per vocabulary. The resulting graph supports fast nearest-neighbor search via greedy and beam exploration, facilitating rapid top-VV9 retrieval during inference (Zhang et al., 2018).

4. Fast Graph Decoder Algorithm

FGD operates in two phases:

  • Offline phase (FGD-P): Transform all embeddings and biases to V|V|0, construct the small-world graph V|V|1.
  • Online phase (FGD-I): For context V|V|2, lift to V|V|3, then run graph search (e.g., HNSW beam search with parameter V|V|4) to find V|V|5 nearest neighbors to V|V|6 in V|V|7. The corresponding indices yield the top-V|V|8 logits. These can be renormalized for a top-V|V|9 approximate softmax.

The per-context online runtime is hRDh \in \mathbb{R}^D0 when hRDh \in \mathbb{R}^D1 is well-formed and hRDh \in \mathbb{R}^D2, a dramatic reduction from linear softmax (Zhang et al., 2018).

Pseudocode Outline

si=hei+bis_i = h^\top e_i + b_i9

5. Theoretical Guarantees

The IPPT ensures the top-hRDh \in \mathbb{R}^D3 by logit are exactly the nearest neighbors in the transformed space (Theorem 3.2). For approximate search, the paper provides explicit error bounds on the relative deviation between FGD and the true full softmax probability for each target, as a function of the lowest logit recovered and the known lower bound for all scores. If precision@hRDh \in \mathbb{R}^D4=1 (all actual top-hRDh \in \mathbb{R}^D5 are found), the bound approaches zero as hRDh \in \mathbb{R}^D6.

This theoretical foundation guarantees that FGD is provably lossless when the graph search finds the exact nearest neighbors, and quantifies the degradation for approximate retrieval (Zhang et al., 2018).

6. Empirical Evaluation and Performance

Extensive experiments demonstrate that FGD achieves substantial speedups with minimal precision loss:

  • Neural Machine Translation (IWSLT’14 DehRDh \in \mathbb{R}^D7En, hRDh \in \mathbb{R}^D8k, hRDh \in \mathbb{R}^D9): With ii0, FGD yields a per-step softmax time of 0.43 ms (14ii1 faster than full softmax), with BLEU within ii2 points.
  • Language Modeling (WikiText-2, ii3 up to 80k): FGD achieves ii4--ii5 speedup at ii6k, with top-10 precision exceeding 0.95 for ii7.

The following table summarizes key results:

Task Full Softmax Time FGD Time (ii8=50) BLEU (NMT) Top-10 Precision
NMT (IWSLT’14) 6.30 ms 0.43 ms 29.06 --
LLM ii9 si=hei+bis_i = h^\top e_i + b_i0 -- >0.95

A trade-off exists between si=hei+bis_i = h^\top e_i + b_i1 (search effort) and recall: larger si=hei+bis_i = h^\top e_i + b_i2 increases both recall and latency.

7. Discussion, Limitations, and Extensions

FGD delivers a scalable solution for top-si=hei+bis_i = h^\top e_i + b_i3 selection in vocabulary-intensive NLM applications, offering order-of-magnitude runtime improvements with controlled:

  • Memory overhead for the graph index
  • Offline construction cost (minutes for si=hei+bis_i = h^\top e_i + b_i4 on the order of si=hei+bis_i = h^\top e_i + b_i5k)
  • Heuristic search (no absolute guarantee of full recall from HNSW, though empirical precision is si=hei+bis_i = h^\top e_i + b_i6 at si=hei+bis_i = h^\top e_i + b_i7 for typical settings)
  • Tuning parameter si=hei+bis_i = h^\top e_i + b_i8 mediates the speed-accuracy tradeoff

Possible directions include support for online/streaming vocabulary updates, adaptation to alternative vector metrics (e.g., cosine distance), and integration into GPU-accelerated search pipelines. The FGD methodology underpins advancements in fast beam search for NMT, language modeling, and other large-vocabulary inference contexts (Zhang et al., 2018).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Fast Graph Decoder (FGD).