Skip to content

Filtering-First Constrained Decoding for Generative Recommendation

THE ARGUMENT

The gain from filtering first comes entirely from how sparse the valid tokens are; the claim that results barely change was only tested on MovieLens-1M, so measure your own catalog's sparsity and compare the returned lists separately before switching.

On this page

Most people assume a storefront must score all 18,432 possible next tokens before it can drop the empty ones, but that order burns nearly all of its work on codes that name no product [1].

Where the default intuition goes wrong

Say you run a storefront: a customer opens the app, and your team has a few milliseconds to place a handful of items on the home screen; the system builds each item's short code one digit at a time, and only a full code points to something actually on sale. The catch is that the codes you can spell vastly outnumber the products on the shelf, so most spellings land on nothing. The default intuition is plain: score every possible next token, then delete the ones that map to no item, and never ask whether the order could be flipped. That is wrong. The paper calls the useful fraction the valid candidate density, which is simply the share of all scored tokens that can still extend a live prefix; on its industrial search data, that density is 14.29 percent at step 2 and falls to 0.05 percent by step 5 [1]. Numbers this small mean scoring first throws away 85.7 to 99.95 percent of its projection arithmetic, its logit materialization, and its masking on tokens that were never valid [1].

So the waste is set by the catalog, not by how well the model was trained: a perfectly trained model still cannot make valid tokens appear where the shelf has none. Most people expect a better model to shrink the bill; it doesn't. The only lever that moves this number is the order itself, and the paper measures the catalog first, then scores only what is left. The saving is real, but it is a saving of arithmetic, not of answers.

There is a catch, though. The two orders are not mathematically equivalent. Decoding keeps many partial prefixes alive at once, a scheme called beam search: at each step it retains several promising half-built codes and expands them, and each prefix admits a different number of valid next tokens. Filtering first shrinks the pool each prefix is normalized over, so the same candidates can rank differently, and the final items can change [1]. Locking every step to the catalog this way is what constrained decoding means. Saving work and returning the same answer are two separate claims, and each needs its own test.

Look at the bill first. Then look at the system. The bill is small only when the catalog is sparse.

What ZeroGR actually built, and its three parts

Here is the idea in plain words. Each item gets a semantic ID, or SID: a fixed-length code whose early tokens are shared by related products, so a full code, and only a full code, points to one catalog item; the paper's example has headphones and a headset sharing the prefix (3, 5) and splitting into (3, 5, 1) and (3, 5, 4) [1]. The catalog is turned offline into a step-sliced filtering index: the map from a prefix to its valid next tokens is split by decoding step, so step 5 of Search is stored and queried independently of step 2, and Watch with 3 steps keeps 3 such maps [1]. A step with many valid tokens uses a dense map, a table whose columns are every token the model could emit at that step; a step with few uses a sparse map, a packed list of only the valid tokens, where an entry's position doubles as its successor state [1]. That last trick is where the memory goes: the final step stores just the last token, with no successor state and no item ID, because a full code already names its item.

Saving memory is only half of it. The paper itself flags a counterintuitive fact: computing fewer logits does not automatically cut latency, because a GPU (the graphics chip that does the math) likes one regular, dense matrix multiply, while scoring only scattered valid tokens is irregular work whose memory reads can be slower than the full multiply [1]. Two pieces fix that. Shared-slot execution gives every prefix a fixed row of slots that filtering, scoring, and selection all read and write in place, so no stage has to count another stage's candidates first. Hybrid projection picks, per step, between scoring all tokens and scoring only the valid ones; warm-up requests measure both at each model update and lock in the faster choice until the next update [1]. GPU index memory, by the way, is the same die that must also hold the model weights and attention caches; every extra field per entry is space a larger batch cannot use.

The testbed is one NVIDIA GeForce RTX 4090 D GPU with 24 GB of memory and two Intel Xeon Gold 5520+ CPUs, plus a second machine with a data-center GPU [1]. Four baselines: Unconstrained applies no catalog check at all and serves only as a speed reference; CPU trie is the team's previously deployed decoder, a prefix tree held in host memory (a prefix tree hangs every valid code off its shared prefixes, so walking it tells you the legal next tokens); FlashTrie packs that tree into a succinct bit-vector in GPU memory; STATIC flattens it into a sparse GPU index [1]. Those three score first; only ZeroGR filters first. Beam width, the number of half-built codes kept at each step, is 128; request batches run from 1 to 32; hidden size is 4,096 with FP32 or 1,024 with FP16, the two numeric precisions [1].

Name the datasets, because the reader should be able to ask which N. Search comes from an industrial generative search service and holds nearly one billion distinct five-token codes, each step projecting onto one 18,432-token output head whose tokens occupy disjoint bands of 8,192, 4,096, 2,048, 2,048, and 2,048 entries [1]. An output head is the layer that assigns a raw score, a logit, to every token the model could emit at that step. Watch holds roughly 4.17 billion three-token codes with an 8,192-token head at every step [1]. Synthetic-7 has seven-token codes, fixes the catalog at 2 to the 30th power, and varies the vocabulary size V [1]. Put together, they span valid tokens from extremely sparse to almost dense, which is exactly the axis the speedup depends on.

The numbers, one table and two lists you can recheck

Put the hardest numbers on the table, so a reader can check them against the paper; every figure below comes from its end-to-end, memory, and rebuild sections, with units and conditions copied as reported [1]. Recall@K here asks whether a wanted item appears among the top K returned; K is the cutoff count, and the paper tried 1, 10, 50, and 128 [1]. Two lists then pick out the facts most easily skipped.

System or metricOn SearchOn WatchWhat to watch
ZeroGR, all decoding steps, batch 32FP32 9.68 ms; FP16 1.88 msFP16 0.93 to 1.07 ms on the data-center GPUAbsolute time, model inference excluded
Speedup over Unconstrained9.1 times with FP16 at batch 32FP32 1.21 to 1.43; FP16 0.91 to 1.82Below 1 means slower
Speedup over CPU trieGap nears two orders of magnitude at large batchesUp to 205 timesHost lookup grows with beam count
GPU index sizeSID table 27.52 GB; STATIC 20.78 GB; ZeroGR 8.51 GBSID table 114.44 GB; STATIC 34.07 GB; ZeroGR 8.70 GBThe 4090 D has only 24 GB
Index rebuild0.914 s, 0.36 percent of STATIC0.144 GB/s within a 60 s windowWhether it fits the update window
  • Start with sparsity. On the industrial search data, the valid candidate density is 14.29 percent at step 2 and 0.05 percent at step 5, so scoring first wastes 85.7 to 99.95 percent of its projection and masking work [1].
  • Then ask whether results changed. On the public MovieLens-1M dataset, the two orders return lists that overlap by 99.90 percent on average, with 99.85, 99.85, 99.90, and 99.90 percent overlap at cutoffs K of 1, 10, 50, and 128, and their Recall@K bars sit almost level [1].
  • Then look at memory. The 4090 D has 24 GB; STATIC's index takes most of it on Search and does not fit at all on Watch, while ZeroGR's index fits both, running 59.1 percent smaller than STATIC on Search and 74.5 percent smaller on Watch [1].

The table reads smoothly, yet one thing is easy to miss: the speedup is not a constant. It moves with the dataset, the precision, and the batch size, so what a reader should plug in is their own catalog's sparsity, not a copied peak.

  • On Search at batch 32 with FP16, ZeroGR finishes all five decoding steps in 1.88 ms, 9.1 times faster than Unconstrained, which applies no constraint at all [1].
  • On Watch every token is valid at step 1 and about 90 percent remain valid at step 2, so the constraint removes little work; ZeroGR still beats CPU trie by up to 205 times, yet against Unconstrained it slips to 0.91 times with FP16 at large batches, that is, slightly slower [1].
  • On Synthetic-7, raising V from 2,048 to 16,384 keeps ZeroGR's batch-32 latency between 3.1 and 4.5 ms and lifts its speedup over Unconstrained to 19.5 times, because steps 2 through 6 admit only four valid tokens each [1].

One more comparison matters most, and it sits in Table 1. At step 2 of Search with FP32 and batch 1, full projection computes 2,359,296 logits in 507.8 microseconds; a naive selective version computes just 71,189 logits but takes 2,594.9 microseconds, because it packs candidates into a compact list and builds a temporary matrix; ZeroGR computes the same 71,189 logits in 305.1 microseconds, 8.5 times faster than the naive version [1]. Fewer logits are only the premise; the execution model is what turns them into lower latency.

Read that again. Fewer is not faster. Right order, right index, right slots: all three, or no win.

What your team should measure before switching

If your team wants to try this order in a live service, do not rewrite the decoder first; measure three things, and you skip most of the dead ends.

  • First, measure your own sparsity. The paper's valid candidate density of 14.29 percent at step 2 and 0.05 percent at step 5 came from an industrial search catalog [1]. If your catalog looks like Watch, with every token valid at step 1 and about 90 percent at step 2, there is little work to remove, so do not budget for 9.9 times [1].
  • Second, test quality on its own. The 99.90 percent overlap was measured on MovieLens-1M; the Search, Watch, and Synthetic-7 sections report latency, not recommendation quality [1]. The two orders are not equivalent, so compare the returned lists on your own model before you copy 'almost identical' into an acceptance checklist.
  • Third, budget the rebuild alongside the update window: every model update rebuilds the index from the refreshed catalog, and on Search, ZeroGR does it in 0.914 s, 0.36 percent of STATIC's time, needing only 0.144 GB/s of host-to-GPU bandwidth inside a 60 s window [1]. H2D, the link that carries data from host memory into the GPU, is shared with live requests, so confirm that transfer will not compete with serving.

One more caveat: the paper's speedup covers filtering, scoring, and candidate selection together, and it explicitly excludes model inference time [1]. Whether your end-to-end latency drops depends on how much of it is inference; do not book a three-stage saving as a whole-request saving.

When this order stops working

Say the boundary out loud: every gain here comes from valid tokens being sparse. Watch is the counterexample, since every token is valid at step 1 and about 90 percent remain valid at step 2, the constraint removes almost no projection work, and ZeroGR falls to 0.91 times against Unconstrained with FP16 at large batches, that is, slower than applying no constraint at all [1]. The paper's own reading is that full projection is already cheap there, so the lookup cost of filtering first shows through [1]. The denser your catalog, the less this order pays; that premise is exactly where it breaks down, so don't copy it blindly.

The second limit is quality. Filtering first and scoring first are not mathematically equivalent, and the 'nearly identical' evidence rests on MovieLens-1M, where overlap is 99.90 percent and Recall@K is nearly level at every cutoff [1]. The end-to-end runs on Search, Watch, and Synthetic-7 measure latency and explicitly exclude model inference; they do not report a quality comparison of the two orders on those same requests [1]. Here is my judgment, not the paper's claim: treating 9.9 times as a guarantee that results stay unchanged mixes up what two different experiments actually measured. If a small ranking shift costs you revenue, verify it yourself.

The limit in one line: this order only holds when valid tokens are sparse, and it breaks down once a catalog grows dense enough that almost any code spells a real item [1]. The line worth screenshotting is this: every millisecond you save was saved by your catalog, not by a smarter decoder; don't credit the model for the order's work.

References

  1. ZeroGR: Filtering-First Constrained Decoding for Generative Recommendation

Sign in to Padda

A code in your inbox. No password to remember.

Connecting to sign-in…