End-to-End Generative Advertising
📝 Before You Continue: Read 8.1 first for semantic IDs / Enc-Dec / RL alignment, and 8.2 for hard-constraint retrieval — the advertising scenario stacks both sets of technical challenges on top of each other, and additionally carries economic constraints.
8.1 and 8.2 solved the performance bottlenecks of cascaded systems with end-to-end generative architectures. But online advertising faces more complex constraints: the system must optimize user experience while balancing platform revenue and advertiser interests, satisfying the economic constraints of the auction mechanism. The traditional advertising system's multi-stage architecture of "retrieval → ranking → creative selection → auction → slot allocation" fragments objectives and struggles to adapt to fast-changing markets.
End-to-end generative advertising must break through three core challenges: how to deeply integrate the auction mechanism into the generation process, how to guarantee advertisers' Incentive Compatibility (IC), and how to efficiently model user intent in ultra-long heterogeneous sequences. This section covers two industrial solutions: EGA unifies the auction mechanism with the generative model, embedding IC/IR constraints through a two-tier design of token-level bidding and POI-level payment; GPR achieves unified multi-scenario modeling over ultra-long heterogeneous sequences in the WeChat ecosystem through a heterogeneous hierarchical decoder and pre-training.
After reading this chapter, you will be able to:
- Explain the triple constraints of the advertising scenario relative to recommendation/search (IC/IR, POI + creative joint generation, decoupling of allocation and payment)
- Describe EGA's dual-modality semantic IDs, probability-decomposed generation, and token-level auction mechanism
- Explain how ex-post regret and Lagrangian optimization approximately guarantee incentive compatibility
- Outline GPR's four token types, RQ-Kmeans+, heterogeneous hierarchical decoder, and value-guided Trie Beam Search
- Complete 5 tiered practice problems consolidating bid aggregation, the payment network, and hierarchical policy optimization
8.3.0 The Triple Constraints of Ad Generation
Consider a scenario to understand how advertising fundamentally differs from recommendation and search: a user scrolls a local-life platform feed, and the system must insert one ad at slot 3. The candidates are nearby restaurants, gyms, and beauty salons; each merchant submits a different bid and has several creative images. A single forward pass must make four decisions — which merchant to show (POI), which creative to use, how to compute payment, and how to guarantee fairness. This reveals a triple set of constraints:
Constraint one: Incentive Compatibility (IC) and Individual Rationality (IR). Advertisers are independent players who adjust bids according to the rules. IC requires truthful bidding to be the optimal strategy: for true valuation and reported bid , utility is maximized when :
Utility is (click value minus payment). IR requires payment not to exceed the bid, . Note that the traditional GSP auction, which charges "the next position's price," does not satisfy IC in the multi-slot setting (only VCG does, but it is hard to deploy in engineering practice), and it assumes ads are independent and cannot handle position externalities.
Constraint two: joint generation of POI and creative. One POI (restaurant) can have multiple creative images, and different users prefer different creatives. The system must jointly decide "which POI to show" and "which creative to use" — the POI determines the content subject, and the creative optimizes the presentation.
Constraint three: decoupling allocation and payment. Directly using bids as weights on generation probability causes a "winner's curse": the highest-bidding ad pays according to its own bid, so advertisers tend to under-bid. EGA resolves this conflict by separating allocation (bids guide generation probability) and payment (an independent network learns the IC payment function) into two modules.
💡 Key Insight: The end-to-end difficulty of advertising is that the generative model must "incidentally" satisfy an economic mechanism — this affects not just the objective function but also requires architecturally decoupling "allocation" from "payment" before IC/IR can be guaranteed mathematically.
8.3.1 EGA: Unifying Auction and Generation
Dual-Modality Semantic IDs and Probability Decomposition
EGA uses RQ-VAE to discretize continuous representations of POIs and creatives into multi-layer semantic IDs (two independent semantic spaces). The raw POI representation includes category, geolocation, statistical features, and text description; the creative representation includes visual features, OCR copy, and creative type. With residual quantization layers and codebook size , each POI is encoded into 3 tokens:
Creatives likewise yield . The user's interaction history is represented as a sequence of (POI, creative) pairs.
Probability decomposition strategy. The intuitive idea is to concatenate the 6 tokens of the POI and creative and generate autoregressively, but EGA found this causes POI-creative mismatches ("Restaurant A's POI + Gym B's creative"). So it decomposes:
Intuition: the POI decides "what to show," the creative decides "how to present it." First generate the POI from interests, then choose the creative based on the POI's characteristics and user preferences.
Encoder-Decoder with Dual Decoders
EGA uses the classic Enc-Dec but with two decoders generating the POI and creative respectively. The encoder processes the historical sequence mixing ads and organic content (each item labeled type∈{ad, organic}), outputting . The POI decoder autoregressively generates the 3-layer semantic ID; the creative decoder generates the creative ID conditioned on the generated POI tokens — its input contains the POI token sequence, letting the model choose a matching creative based on POI semantics.
MTP module. A standard decoder predicts only the next token at each step; EGA uses MTP (Multi-Token Prediction) to jointly supervise both decoders at each step, letting them share underlying representations, accelerating convergence and improving consistency:
Permutation-Aware Reward Model: Handling Position Externalities
The pre-trained model doesn't know "which ad is better." Auction-based fine-tuning needs a reward model, and the advertising scenario must handle position externalities — ads are not independent: position effects (CTR at slot 1 is far higher than slot 5), adjacency effects (two adjacent restaurant ads suppress each other), and contrast effects (a low-quality ad following a high-quality one sees CTR drop). Mathematically:
Traditional point-wise models (DeepFM, Wide&Deep) cannot model sequence-level dependencies. EGA uses a permutation-aware design, using Self-Attention to let every ad "see" the other ads in the sequence:
Three independent towers predict POI-CTR / Creative-CTR / CVR respectively, with the composite reward:
Analysis: The permutation-aware reward model is EGA's key difference from OneRec's P-Score — it models "sequence-level position externalities" into the reward rather than making point-wise predictions. The costs are Self-Attention's in sequence length and training an additional three-tower reward model.
Token-Level Bidding: Max Aggregation
A generative framework outputs token sequences, and the token-ad relationship is many-to-many (one ad is encoded into multiple tokens; one token may correspond to multiple ads), so traditional item-level bidding doesn't apply. EGA uses a two-tier design:
Token-level bid aggregation (max). For the ad set corresponding to layer- token , bids are aggregated with the maximum:
Why max rather than avg? If a token corresponds to a high-bidding ad, generating it carries high commercial value and its probability should be boosted; avg would be diluted by low bids. Based on this, the allocation probability is defined as:
- : the bid influence weight. degenerates to pure interest-based recommendation; becomes pure bid-based ranking.
- : the ratio of ads to organic content. Larger gives higher generation probability to organic content (bid 0).
POI-Level Payment Network: Learning IC-Compliant Payments
Paying directly by generation probability is problematic: the probability is non-differentiable and hard to keep IC. EGA decouples allocation from payment: allocation is bid-guided, while payment uses an independent neural network to learn an IC payment function. The payment network's inputs include the POI sequence representation, a self-excluding bid matrix (depending only on others' bids and one's own allocation — the key to IC), and the expected value (allocation probability × pCTR). A Sigmoid outputs the payment rate:
The Sigmoid guarantees , thereby satisfying IR .
Ex-post regret constraint. Borrowing from mechanism design, IC violations are quantified: for advertiser , truthful-bidding utility is , and the maximum gain from misreporting is the regret:
When , truthful bidding is optimal. In practice, candidate bids are sampled to approximate this. EGA solves the constrained optimization (maximize revenue, regret constrained near 0) with a Lagrangian dual:
Alternating updates: fix and optimize the payment network; fix the network and update . For advertisers with high regret, increases, forcing the loss to focus more on reducing their regret.
Two-Stage Joint Training
Stage one, interest-based pre-training: ignore bids, train the NTP+MTP joint loss on exposure sequences, obtaining the base generative model .
Stage two, auction-based post-training: introduce bids, the reward model, and the payment network, alternating among three sub-tasks: (1) the reward model trains multi-task BCE on real feedback and is frozen as the evaluator; (2) Policy Gradient — non-autoregressive policy gradient with marginal-contribution reward and loss ; (3) the payment network minimizes ex-post regret via the Lagrangian.
Analysis: EGA's core value is turning the "auction mechanism" from an external rule into a differentiable internal part of the generative model — token-level bidding guides allocation, and the POI-level payment network guarantees IC. Compared with OneRec, the differences are the introduction of bid signals, IC constraints, and permutation awareness. Limitations: RQ-VAE and Enc-Dec target a single scenario and struggle to unify across scenarios; a standard Transformer's input is limited and struggles with sequences of tens of thousands; Beam Search generates many invalid candidates, adding latency. These gave rise to GPR.
8.3.2 GPR: Pre-training-Driven Ad Generation
EGA emphasizes "auction-driven"; GPR (Generative Pre-trained Recommender) adopts a "pre-train + fine-tune" paradigm — first learning general interest representations on massive unsupervised data, then aligning with business objectives through value-aware fine-tuning and RL. It tackles cross-scenario, ultra-long-sequence, and 100ms real-time challenges in the WeChat ecosystem (Channels/Moments/Official Accounts/Mini Programs).
Unified Input Representation: Four Token Types
GPR encodes the user's complete behavioral journey as a mixed sequence of four token types:
- U-Token (User) — static attributes and long-term preferences (demographics, spending power, interest tags)
- O-Token (Organic) — browsed organic content (short-video RQ-VAE semantic IDs, article text representations, multimodal representations of friends' updates)
- E-Token (Environment) — immediate environment (time, geolocation, device, scene identifier)
- I-Token (Item) — interacted ad items (RQ-VAE semantic IDs, including POI + creative)
This representation provides: scene unification (content from different scenes shares one token system), temporal coherence (a cross-scene timeline), and rich context (each I-Token is surrounded by O/E-Tokens providing context).
RQ-Kmeans+: Solving Codebook Collapse
When quantizing O/I-Tokens, traditional RQ-VAE faces codebook collapse: with randomly initialized codebooks, some codes are never activated, and utilization is only 60–70%. RQ-Kmeans+ combines RQ-Kmeans's high-quality initialization with RQ-VAE's end-to-end optimization:
Step 1 RQ-Kmeans builds initial codebooks by running K-means on residuals (guaranteeing every code is assigned at least some samples, avoiding dead codes). Step 2 Use these as RQ-VAE initial weights, add a residual connection on the encoder side (with learnable ), then train end-to-end with the standard RQ-VAE loss. Result: codebook utilization rises from 65% to 92%, and reconstruction error drops 15%.
Heterogeneous Hierarchical Decoder (HHD)
EGA's Enc-Dec tightly couples the encoder and decoder, and sequences of tens of thousands hit memory/compute bottlenecks. GPR proposes the HHD (Heterogeneous Hierarchical Decoder), decoupling into three layers to achieve "understand first, then reason, then generate":
Layer one, HSD (Sequence-wise Decoder) — intent understanding. Uses an improved HSTU architecture with three designs:
- Hybrid Attention Mask — bidirectional attention within the U/O/E-Token (Prompt) region for full interaction; causal attention within the I-Token (Target) region to guarantee autoregression; Targets can attend to the full Prompt.
- Token-Aware Normalization — the four token types U/O/E/I have vastly different distributions, so each gets an independent LayerNorm and FFN, projecting into its own semantic subspace.
- MoR (Mixture-of-Recursions) — the same layer recursively calls itself times (with learnable weights ), increasing reasoning depth without adding parameters, akin to "multiple rounds of thinking."
HSD outputs intent embeddings .
Layer two, PTD (Token-wise Decoder) — reasoning and generation. Designed as a "Thinking-Refining-Generation" three-stage process:
- Thinking: generates Thinking Tokens (learnable query vectors extract key signals from the intent embeddings via Cross-Attention, filtering out irrelevancies).
- Refining: drawing on Self-Reflection, Gaussian noise is added to the Thinking Tokens and a conditional denoising Transformer iteratively refines them (similar to Stable Diffusion), improving complex-user generation quality by 2–3%.
- Generation: autoregressively generates the target ad's semantic IDs (3 RQ layers) from the refined representation.
Layer three, HTE (Token-wise Evaluator) — value evaluation. Outputs a value estimate at every token-generation layer, , with the final ad value . HTE is used both for Beam Search pruning and as the Critic in Policy Optimization.
Value-Guided Trie Beam Search
EGA's standard Beam Search generates many invalid candidates (exhausted budgets, targeting mismatches, geo restrictions). GPR proposes Value-Guided Trie-based Beam Search, integrating value estimation and constraint filtering into decoding:
Trie tree constraints. Filter a valid ad subset by user profile and ad-targeting constraints (age/targeting/budget/geo), and build a Trie prefix tree from each ad's 3-layer semantic IDs. When decoding layer , sampling comes only from the Trie's current node's children rather than the full codebook (), shrinking the search space from to .
Value-based dynamic beam width. Standard Beam Search uses a fixed beam width ; GPR adjusts it dynamically based on HTE values:
Branches with value far above the mean get wider beams to explore more; low-value branches shrink early. Actual results: inference latency dropped from 150ms to 80ms (down 47%), the valid-candidate share rose from 40% to 95%, and Top-1 accuracy improved 3.2%.
Left: the Trie prefix tree filters a valid ad subset by user profile and targeting constraints; decoding expands only on legal child nodes, shrinking the search space from to . Right: each layer dynamically adjusts beam width by HTE value estimates — high-value branches are retained, low-value ones pruned.
The interactive demo below lets you feel the Beam Search decoding of generative retrieval: starting from the root, each layer branches among (Trie-constrained) candidate tokens; branches with high HTE values are retained and low-value ones pruned, ultimately outputting a valid ad semantic ID sequence. Click "Next" to watch the layer-by-layer expansion.
Note the "pruning" at each step: candidates that fail the Trie constraints (e.g., geo mismatch) or have too-low HTE values are dropped early in generation. This is exactly how GPR turns "legality" and "value" into hard decoding constraints and cuts latency nearly in half.
Multi-Stage Training Strategy
Stage one, MTP pre-training: massive WeChat all-scene behavior logs (Channels/Moments/Official Accounts/ads), with objective — hundreds of millions of users, hundreds of billions of interactions, up to 8B parameters.
Stage two, value-aware fine-tuning: freeze HSD/PTD, train only the HTE multi-task towers on real feedback (BCE loss), introducing click/conversion business supervision.
Stage three, HEPO (Hierarchy Enhanced Policy Optimization): policy gradients at both token level and item level simultaneously. Token-level advantage (variance far smaller than item level); item-level reward ; hierarchical aggregation . The loss:
Benefits: low variance (small token space), fine-grained control (locating which token layer causes low value), and fast convergence (dense token-level gradient signals).
Design Trade-offs
GPR fully launched on WeChat Channels ads. Compared with the cascaded system: GMV and CTCVR improved, inference latency dropped from 200ms+ to 80ms, and the model count went from 5 independent models down to 1. The trade-offs:
- Architectural complexity vs. scene generality: HHD's three layers + Thinking-Refining-Generation take more than 2× EGA's code volume, but buy cross-scene unification (Channels/Moments/Official Accounts share one model).
- Pre-training cost vs. zero-shot transfer: pre-training consumes thousands of GPU cards for weeks, but launching a new scene requires only light fine-tuning.
- End-to-end optimization vs. interpretability: the black box makes anomalies hard to localize, partially mitigated by visualizing Thinking Tokens and HTE's layered value outputs.
⚠️ Common Mistakes in 8.3
| # | Mistake | Example | Why It's Wrong | Fix |
|---|---|---|---|---|
| 1 | Ignoring advertising's economic constraints | "Ads just optimize CTR too" | Advertisers game their bids; IC/IR needed | Use a payment network + ex-post regret to preserve IC |
| 2 | Concatenated generation of POI and creative | "Autoregress over the 6 tokens together" | Easily generates POI-creative mismatches | Probability decomposition: POI first, then creative |
| 3 | Avg aggregation for token bids | "Take the ad set's average bid" | High-bid signals get diluted by low bids | Use max aggregation to highlight high-value tokens |
| 4 | Paying directly by generation probability | "p_i ∝ z(a_i^j)" | Non-differentiable and hard to keep IC | Decouple allocation/payment; independent payment network |
| 5 | All RQ-VAE causing codebook collapse | "Randomly initialized codebook, end-to-end" | Dead codes leave utilization at only 65% | RQ-Kmeans+ first for high-quality initialization |
| 6 | Unconstrained Beam Search | "Decode over the full codebook W^3" | Generates many invalid candidates, adding latency | Trie constraints + HTE value-guided pruning |
Chapter Summary
📌 Key Takeaways
| Concept | Key Points | Why It Matters |
|---|---|---|
| Triple constraints | IC/IR, POI + creative joint generation, allocation-payment decoupling | Economic challenges unique to advertising vs. recommendation/search |
| EGA | Dual decoders + token-level max bidding + POI-level payment network | Deep unification of auction mechanism and generative model |
| ex-post regret + Lagrangian | Sampling approximates regret; dual updates of λ | Approximately guarantees IC while balancing revenue |
| Permutation-aware reward | Self-Attention models position externalities | Ads are not independent; point-wise estimation fails |
| GPR | Four token types + RQ-Kmeans+ + HHD + value-guided Trie Beam Search | Unified ad generation across scenes and ultra-long sequences |
| HEPO | Token-level + item-level hierarchical policy gradients | Low variance, fine-grained control, fast convergence |
❓ FAQ
Q1: Why does EGA's token bidding use max rather than avg?
A: One semantic token may correspond to multiple ads. If one of them bids high, generating that token carries high commercial value and its probability should be boosted. Avg dilutes the high-bid signal with the low-bid ads in the same group; max highlights the value peak.
Q2: Why must allocation and payment be decoupled?
A: If you pay directly by generation probability, the probability is non-differentiable and the "winner's curse" pushes advertisers to under-bid. Decoupled, allocation uses bid-guided generation (differentiable Softmax) and payment uses an independent network learning the IC function (Sigmoid preserves IR) — only then can IC be approximately guaranteed with mathematical constraints.
Q3: What makes GPR's Trie Beam Search better than standard Beam Search?
A: Standard Beam Search expands over the full codebook , generating many invalid candidates (exhausted budgets/targeting mismatches/geo restrictions) requiring post-processing. The Trie pre-filters valid ads by constraints so decoding walks only legal branches early; then the beam width is dynamically adjusted by HTE values, cutting latency 47% and raising the valid-candidate share to 95%.
🔗 Connections to Later Chapters
- 8.1 (end-to-end generative recommendation) provides the semantic ID / Enc-Dec / RL alignment foundations for EGA and GPR.
- 8.2 (end-to-end generative search) covers hard-constraint retrieval (KHQE, constrained Beam Search), carried forward in GPR's Trie-constrained decoding.
- 6.x (generative foundations) covers RQ-VAE quantization, appearing here in two forms: EGA's RQ-VAE and GPR's RQ-Kmeans+.
- 9.1–9.3 (generative thinking/reasoning) further discuss how "reasoning steps" like Thinking Tokens improve generation quality, complementing GPR's PTD Thinking-Refining stage.
Practice Problems
Work through all problems in order — they get progressively harder. Each has a complete solution you can reveal after trying it yourself.
Problem 8.3.1 — Token-Level Bid Aggregation 🟢 Easy
A semantic token corresponds to 3 ads with bids . Find (a) the token bid under max aggregation; (b) the result under avg aggregation; (c) why is max more reasonable?
💡 Solution (click to reveal)
Approach: Apply the aggregation formula directly.
- (a) .
- (b) avg = .
- (c) This token contains a high-bidding ad (), so generating it has high commercial value; max concentrates probability mass on this value peak, while avg is diluted by , weakening the high-bid signal — exactly max's design motivation.
Key points:
- Max highlights value peaks; avg smooths away extremes.
- Bid aggregation in generative advertising is fundamentally a strategy for handling the "many-to-many" mapping.
Problem 8.3.2 — Payment Rate and the IR Constraint 🟢 Easy
An advertiser reports bid , and the payment network outputs payment rate . Compute the actual payment , and determine whether the individual rationality (IR) constraint holds.
💡 Solution (click to reveal)
Approach: .
. Since the Sigmoid guarantees , we have — the IR constraint holds.
Key points:
- The payment rate naturally falls in [0,1] via Sigmoid, so holds automatically.
- IR is the basic precondition for advertisers to participate in the auction (they never pay more than their bid).
Problem 8.3.3 — ex-post regret intuition 🟡 Medium
Advertiser has true valuation . With truthful bidding , the payment is and pCTR=0.5, so utility . If they misreport , the new payment is with pCTR unchanged, giving utility . Compute the ex-post regret , and state whether this mechanism approximately satisfies IC.
💡 Solution (click to reveal)
Approach: regret = maximum gain from misreporting − truthful utility.
.
The mechanism does not satisfy IC: the advertiser obtained higher utility by misreporting (shading down the bid) (4 > 3), yielding positive regret. EGA's goal is precisely to press toward 0 via Lagrangian optimization — in this example, the payment network must be adjusted so that truthful bidding becomes the optimal strategy.
Key points:
- is the criterion for IC to hold.
- Positive regret means the mechanism can be gamed; the payment network must learn to correct it.
Problem 8.3.4 — Value-Guided Beam Width 🔴 Hard
At Beam Search layer , a token has value ; the mean value across all current branches is ; the temperature is ; the base beam width is and the minimum beam width is . Compute this branch's next-layer beam width . If another branch has (below the mean), what is its beam width?
💡 Solution (click to reveal)
Approach: Apply the value-based dynamic adjustment formula.
Branch 1 ():
Branch 2 ():
Answer: The high-value branch's beam width expands to about 21.7 (exploring more), and the low-value branch shrinks to about 6.77 (but still keeps , so it isn't abandoned entirely).
Key points:
- Higher value means wider beams, achieving "explore deep on high value, retract early on low value."
- guarantees even low-value branches retain a little exploration, avoiding premature misses.
🏆 Challenge: Arguing the Case for End-to-End Advertising
A local-life platform's ad system is currently a five-stage cascade of "retrieval → ranking → creative → auction → allocation," training a separate model for each of three scenes: video, feed, and search. Write roughly 170 words arguing, when introducing a GPR-style end-to-end generative architecture: (1) how the four token types unify the three scenes; (2) versus EGA, which two designs give GPR its breakthroughs on ultra-long sequences and inference efficiency; (3) what new risks to watch for?
💡 Hint
(1) The four token types (U/O/E/I) represent the content and ads of video, feed, and search in one semantic system, forming a coherent cross-scene behavioral timeline that breaks data silos and model fragmentation. (2) Ultra-long sequences rely on HSD's Hybrid Mask + MoR recursive reasoning and Q-Former-style compression; inference efficiency relies on value-guided Trie Beam Search filtering invalid candidates early in decoding, cutting latency nearly in half. (3) New risks: HHD's architecture and the Thinking-Refining paradigm take 2×+ EGA's code volume with high training cost; the end-to-end black box offers poor interpretability, making bad cases hard to localize (mitigated by visualizing Thinking Tokens and HTE's layered value outputs).