Hidden Density Bias in Graph-Building GFlowNets

Generative flow networks (GFlowNets) are samplers that build an object step by step, for example a graph built one edge at a time, and are trained so that each finished object is drawn with probability proportional to a reward. The most common training rule, trajectory balance, compares two quantities along a whole construction path. The first is a learned normalizer $Z$ times the forward step probabilities. The second is the reward times the probabilities of taking the object apart. This note argues that the standard way of setting up graph-building GFlowNets quietly assumes the target graphs are dense, meaning their edge count grows with the square of the node count. That assumption is the same one graph-limit theory had to abandon to say anything useful about real, sparse networks. Because of it, a GFlowNet policy trained on 20-node graphs cannot be trusted at 200 nodes, even when its neural network accepts graphs of any size.

The proposal is to locate the dense assumption in three specific places. These are the softmax that pits one "stop" action against roughly $N^2$ "add edge" actions, the scalar normalizer $Z$ relearned at every size, and the undirected credit spread across trajectories whose length grows with the edge count. We then re-parameterize each so that the quantities the network must output stay bounded as graphs grow with linear edge counts. The test is concrete: train on small graphs, then sample at four to twenty times the size without retraining, on a reward family where the exact target distribution is known at every size.

Core Claim

Existing graph GFlowNets, such as DAG-GFlowNet, which samples Bayesian-network structures edge by edge with a fixed node set, and CPDAG-GFN, which samples equivalence classes with a relational graph network, are each trained at a single size. CPDAG-GFN copes with overly dense samples through a post-hoc filter that prunes infrequent edges. We claim the excess density is structural rather than incidental, and it is easiest to see in the stop decision. Suppose a policy scores the stop action $s$ and each of the $M$ addable edges $e_i$ with locally computed logits. Then

$$P(\text{stop}) = \frac{e^{s}}{e^{s} + \sum_{i=1}^{M} e^{e_i}}, \qquad M = \Theta(N^2),$$

where $N$ is the node count. With logits that do not depend on size, the stop probability falls like $1/N^2$, so trajectories run longer and the sampled graphs get denser as $N$ grows. Under the true target for a sparse reward, the expected number of remaining edges is $O(N)$. A correct policy must therefore shift every edge logit by roughly $-\log N$, and a size-agnostic network trained on a narrow band of sizes has no reason to extrapolate that shift.

The normalizer has the same problem. For rewards built from local terms on sparse graphs, $\log Z$ grows linearly in $N$, like a free energy, whereas a single learned scalar has no size dependence at all. Our claim is that factorizing the policy and parameterizing the normalizer so that every output is intensive (per node or per edge, not per graph) makes trajectory-balance-trained policies transfer across sizes while still sampling in proportion to reward. We also claim that each of the three fixes is necessary.

Research Program

The method has three pieces, each borrowed from an existing line of work and adapted.

The first is a factorized action head. Each step first makes a binary continue-or-stop decision computed from pooled intensive features, such as current mean degree and a mean-pooled embedding. If the step continues, it picks an edge by choosing a source node and then a target among that node's candidates. Under this factorization, no single softmax ever has a size-dependent number of competitors against a fixed stop logit.

The second piece is message passing whose aggregation is normalized by $\sqrt{|E|}$ rather than by $N$, where $|E|$ is the edge count. This rule comes from Modeling Sparse Graph Sequences and Signals Using Generalized Graphons, which shows that sparse-graph eigenvalues scale with $\sqrt{|E|}$ and that dividing by $N$ makes filter coefficients explode on Cora. The theoretical justification comes from Le & Jegelka's graphop analysis, which bounds transfer error of message-passing networks across sparse graphs by $O(n^{-1/2})$, and from the bofop analysis, which proves universal approximation and vanishing generalization gaps for such networks. Neither of those works addresses sampling. We use their results as a reason to expect the policy's local outputs to converge as $N$ grows, and we measure whether the error in the sampled distribution decays at their rate or at the faster $O(n^{-1})$ rate they observe empirically.

The third piece is an extensive normalizer, $\log Z(N) = N\phi_\theta + \psi_\theta \log N + \kappa_\theta$, fit jointly across a range of training sizes. In conditional settings, $\phi_\theta$ is produced by a pooled network over the conditioning input. We train this with the trajectory balance loss divided by trajectory length, and separately with subtrajectory balance. Subtrajectory balance enforces the balance condition on every segment of a path and was reported to reduce variance on long sequences. Since sparse trajectories have length $O(N)$, it is the natural choice at large sizes.

The analysis half of the program has two parts. First, we derive the calibrated stop probability exactly in a reward family where everything is computable. Second, we show empirically, by sweeping $N$, that the naive parameterization's edge density grows with $N$ while the factorized one's stays fixed.

The main testbed is the independent-edge sparse model. Each potential edge $e$ carries a weight $w_e = c\,u_e/N$, with $u_e$ random, and the reward is $R(G)=\prod_{e\in G} w_e$. For this family $\log Z = \sum_e \log(1+w_e)$ holds exactly and every edge marginal is known at any $N$. That is unusual among GFlowNet benchmarks, since the hypergrid and molecule tasks only allow exact evaluation at one fixed size. A second family adds local interactions, a degree prior and a triangle term, where exact answers exist only at small $N$. The application is Bayesian structure learning on sparse Erdős–Rényi graphs with expected degree 2 and on the Sachs data, where transfer serves as a warm start.

Baselines

The naive reference point is a trajectory-balance GFlowNet with a mean-aggregation graph network. It uses the usual single softmax over stop and edge actions and a scalar $\log Z$, and is trained on the same range of sizes and applied zero-shot at larger $N$. This is what a practitioner would do by default. It has the same architecture class, data, step count and hyperparameter search budget as our method, so any gap isolates the parameterization.

The strongest existing competitor is a GFlowNet trained directly at the target size. Concretely this is DAG-GFlowNet for structure learning, which reports Pearson $r>0.99$ against the exact posterior at $d=5$ and matches or beats the MCMC sampler Gadget and the variational method DiBS at $d=20$ and $50$. A plain trajectory-balance policy fills that role on the synthetic families. We give it the same total gradient steps that our method spends on small sizes. Beating it means matching its accuracy on edge marginals and $\log Z$ at zero target-size training steps, or reaching it in a small fraction of its steps.

On Sachs, the CPDAG-GFN result with its sparsity filter is the reference: AUROC 0.757 and 15.42 inferred edges against 17 true edges. A transferred model must match that AUROC without post-hoc pruning to count as a win.

Curriculum transfer is the closest analogue to our setup. For Sidon sets, a curriculum from $n=30$ to $n=80$ reached 77% catalogue coverage without seeing the $n=80$ catalogue, against 82–83% with behavioral-cloning initialization. We run a matched curriculum, with the same schedule and steps, on the naive parameterization. For the synthetic families there is no reported result found on Lacuna, so all numbers there are ours.

Ablations remove one ingredient at a time: the factorized stop head, the $\sqrt{|E|}$ normalization (replaced by $1/N$), and the extensive $\log Z$ (replaced by a scalar, or by a per-size scalar fit at test time). Each ablation shows which hidden dense assumption actually limits transfer.

Why not just…?

Why not just feed $\log N$ as an input feature to a standard policy? This is the most serious threat, because it gives the network what it needs to learn the $-\log N$ logit shift. However, the network has to extrapolate that shift beyond the sizes it was trained on, and nothing constrains it to be linear in $\log N$. Our factorization makes the correct dependence structural instead of learned. The "$\log N$ feature" variant is run as an additional baseline. If it matches our method at four to ten times the training size, the claim narrows to an explanation of why the feature works rather than a new parameterization, and we will report it that way.

Why not just add an edge-count penalty to the reward, or prune afterwards as CPDAG-GFN does? Both change the distribution being sampled. A penalty alters the target, and pruning, as the file notes for CPDAG-GFN, breaks the guarantee that samples are proportional to reward, because a pruned graph's score differs from the sampled one's. The independent-edge model makes this measurable: both fixes will show biased edge marginals relative to the exact answer, whereas our correction leaves the target untouched.

Why not just fine-tune at the target size, or run MCMC there? Fine-tuning is a genuine competitor whenever compute at the target size is cheap. We therefore report the number of fine-tuning steps needed to reach a fixed marginal error, starting from each initialization, so that transfer is judged as a warm start rather than only zero-shot. MCMC mixed slowly in the structure-learning comparisons of DAG-GFlowNet. In molecule generation, the original GFlowNet paper reports that the MCMC baseline MARS found fewer than 100 high-reward molecules while the GFlowNet found over 2,300. We include MC3 chains at matched wall-clock time as a reference rather than as the main competitor.

Proposed Experiments

All models train on graphs with 10 to 50 nodes and are evaluated at 100, 200 and 500 nodes. On the independent-edge model, the metrics are: mean absolute error of the edge marginals against the exact values; error of the predicted $\log Z$ per node against the exact value; the ratio of sampled to true edge density; and, at small $N$ where enumeration is feasible, the L1 distance over whole graphs.

The decisive check has two predicted outcomes. The naive policy's density ratio should grow with $N$, with roughly $\log N$ excess in edge logits. Our policy's ratio should stay near 1, with marginal error decaying in $N$ at an exponent we measure and compare against the graphop $n^{-1/2}$ bound.

On the interacting family, we compare degree and triangle statistics against long MCMC chains, and we track how well $\log Z$ estimated by importance weighting agrees with the transferred $\log Z(N)$. In structure learning, we train on sparse Erdős–Rényi graphs with 10 to 30 variables, with the normalizer conditioned on the data, and evaluate at 50 and 100 variables. The metrics are expected structural Hamming distance, AUROC, and steps-to-accuracy against DAG-GFlowNet trained from scratch, followed by the Sachs comparison above.

The proposal fails if any of the following holds: the ablation without the stop factorization transfers as well as the full model; the $\log N$-feature baseline matches the full model throughout; or marginal error at 500 nodes does not shrink relative to 100 nodes.