arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.32602

Trajectory Matching: Discrete Flow Matching with Structured Actions

Niklas Kemper, Marten Lienen, David Lüdke, Stephan Günnemann

ABSTRACT

The natural units of structured discrete generation are often not independent single-component edits but richer actions: attaching a fragment to a molecule, inserting a node together with an incident edge, or growing a hierarchy by adding a child. Yet most existing discrete flow matching methods (DFM) are restricted to independent component-wise edits over fixed-size states. This restriction stems from endpoint conditioning: endpoints fix the source and target during training but not the action sequence between them, making tractable conditional rates hard to define for complex actions that cannot be factorized component-wise. We propose trajectory matching, which conditions the flow on a full sequence of actions connecting the endpoints. This yields principled, simulation-free training targets for user-defined action spaces, including actions that change state size, modify multiple components, or depend on earlier actions. We prove that the resulting objective recovers the marginal flow and that trajectory matching strictly subsumes factorized DFM, while additionally capturing actions with prerequisite structure such as hierarchy growth or fragment-based molecule generation. Empirically, on tree and molecular graph generation, trajectory matching with domain-aligned actions matches or surpasses factorized DFM baselines (lifting MOSES validity from 92.8% to 99.2%) and transfers without retraining to substructure extension and linking. Trajectory matching enlarges the design space of discrete flow matching by turning the action vocabulary into a modeling choice. An interactive explanation of trajectory matching is available at https://niklaskemper.com/blog/trajectory-matching/.

1 INTRODUCTION

Many structured generation problems are most naturally expressed in terms of actions that reflect the structure of the domain rather than the structure of the representation. In molecular graph generation, for example, the natural actions are not single-component edits but operations like attaching a fragment to a partial structure or inserting an atom together with a bond. Such actions can change the size of the state, modify several components at once, and depend on one another—an atom can only be attached to atoms that have already been inserted. The value of such structured actions is well established in autoregressive models: fragment-based molecule generation (Jin et al., 2019), grammar-based code generation (Yin & Neubig, 2017), and insertion-based graph models (You et al., 2018) all exploit domain-aligned actions to achieve strong empirical performance.

However, existing discrete flow matching (DFM) (Campbell et al., 2024; Gat et al., 2024) and related non-autoregressive methods such as discrete diffusion (Austin et al., 2021) cannot easily express such actions. The reason is structural: DFM prescribes a conditional flow between sampled endpoints, and the corresponding rate must be tractable for training. To achieve this over combinatorially large state spaces, existing methods factorize the rate across components. This commits the model to fixed-size states, single-component edits, and independence between actions. Recent extensions (Havasi et al., 2025; Deutschmann et al., 2026; Lüdke et al., 2026) lift the fixed-size constraint by supporting insertions and deletions in specific domains, but they do so by mapping these operations into augmented state spaces where they again reduce to factorized single-component edits. Actions that modify multiple components or depend on one another therefore remain out of reach.

We address this gap with trajectory matching: rather than conditioning on endpoints alone, we condition on a full trajectory of actions connecting them. A trajectory specifies which actions are applied and in what order, leaving the conditional flow to determine only when each action is taken. This makes the conditional rate straightforward to define for general action spaces, including actions that change state size, modify multiple components, or depend on one another. The resulting training objective is still simulation-free and provably recovers the marginal data-generating flow. To make training efficient, we require an efficiently sampleable distribution over trajectories connecting the endpoints. We give explicit constructions for several settings, including actions with hierarchical dependencies. Our framework also recovers standard factorized DFM as the special case of independent component-wise actions with uniformly sampled orderings, placing factorized updates and actions with prerequisites within a common framework.

Empirically, we show that domain-aligned action spaces translate into concrete gains on tree and molecular graph generation. On tree generation, child-attachment actions yield 100% validity by construction across sampling budgets, while a factorized baseline collapses below 10% at 10 Euler steps. On molecular graphs, we demonstrate the flexibility of trajectory matching across four action spaces, ranging from factorized bond edits, which match existing DFM baselines, to fragment-based insertions, which lift MOSES validity from 92.8% to 99.2%. Additionally, a single variable-size insertion model transfers zero-shot to substructure extension and linking, substantially outperforming a factorized baseline that requires task-specific adaptation.

Our core contributions are:

• Trajectory matching. A discrete flow matching framework over user-defined action spaces, including size-changing, multi-component, and dependent actions, obtained by conditioning training on full action trajectories rather than endpoints. The objective recovers the marginal flow (Thm. 3.2); a Rao-Blackwellized variant reduces gradient variance (Prop. B.3).

• A unifying framework. Trajectory matching subsumes factorized DFM (Thm. 4.4) while extending to partial-order action systems, capturing hierarchy growth and fragment-based molecule construction.

• Empirical gains on structured generation. On tree and molecular graph generation, trajectory matching with domain-aligned action spaces yields concrete gains over factorized DFM baselines: 100% validity by construction on trees, MOSES validity from 92.8% to 99.2% on molecules, and zero-shot transfer to substructure extension and linking.

References (47)