Attention-Based Pretraining for Unsupervised Amortized Causal Discovery

Naiyu Yin, Tian Gao, Yue YuNeurIPS 2026

TL;DR

Finding cause-and-effect relationships from raw observational data usually requires solving a painfully slow, from-scratch optimization problem for every single dataset you encounter. Attention-DAG (ADAG) flips the script: by pre-training a linear transformer across multiple datasets without any ground-truth graph labels, it learns to predict causal graphs in a single, sub-millisecond forward pass. Even cooler? Under the hood, the transformer's attention layers aren't just memorizing patterns—they actually learn to execute an iterative mathematical optimization algorithm on the fly.

What Problem Does This Paper Address?

Science and engineering are driven by causality: knowing whether $A$ causes $B$, rather than just watching them correlate. We typically represent these relationships as Directed Acyclic Graphs (DAGs)—networks of arrows with no feedback loops—backed by Structural Equation Models (SEMs) that describe the math of how parent nodes influence child nodes.

Inferring a DAG from observational data is notoriously hard. The number of possible graphs explodes super-exponentially as you add variables, and enforcing the "no loops" (acyclicity) rule makes continuous optimization highly non-convex. Traditional methods treat every new dataset as an isolated puzzle, running expensive iterative solvers from scratch—and falling apart when sample sizes are small.

Recent amortized methods try to bypass test-time optimization by pre-training neural networks to predict DAGs directly from data. However, existing amortized models require supervised training, meaning you have to feed them ground-truth causal graphs. ADAG tackles the missing piece: unsupervised amortized causal discovery—learning to map raw data directly to causal graphs and SEM parameters simultaneously, with zero ground-truth DAGs required during training.

Methods

ADAG Training and Zero-Shot Inference Architecture

Figure 1: The schematic of the proposed training and inference procedures for unsupervised DAG learning. Given data from multiple domains, we begin by training a nonlinear mapping from data to the corresponding hidden DAG. The trained model is then capable of zero-shot DAG inference, allowing it to predict SEM parameters when given data from new test domains.

ADAG shifts the heavy computational lifting to a one-time, multi-domain pre-training phase:

  • Variables as Tokens: Given $n$ observations across $d$ variables in a domain, ADAG treats each variable as a token of length $n$ (a vector of all its observed samples).
  • Linear Attention Stack: These $d$ tokens pass through $L$ layers of linear attention (attention without the softmax activation), ending in a kernel block that outputs a $d \times d$ weighted adjacency matrix representing both the graph edges and the SEM parameters.
  • Standard Unsupervised Loss, Novel Target: Rather than comparing outputs to ground-truth graphs, ADAG plugs its predicted adjacency matrix back into the SEM to reconstruct the input data. It minimizes reconstruction error alongside a standard continuous acyclicity penalty (from NOTEARS) using an augmented Lagrangian solver.
  • Nonlinear Extension: For nonlinear SEMs, ADAG uses a per-variable attention stack to predict the first-layer weights of Multi-Layer Perceptrons (MLPs) that model each variable's causal parents, while sharing deeper MLP layers across domains.

Once pre-trained across $M$ domains, ADAG performs zero-shot inference: feed it a brand-new dataset, and a single forward pass spits out the causal graph.

Datasets

No new datasets are introduced, though the authors construct controlled multi-domain synthetic suites alongside standard benchmarks:

  • Synthetic Benchmarks: Data generated from Erdős–Rényi (ER), Scale-Free (Barabási–Albert), and Stochastic Block Model graphs ($d \in \{5, 10, 20, 50\}$) under both linear and 2-layer MLP SEMs, across three structural priors (Heterogeneous shared DAGs, Order-consistent DAGs, and General random DAGs).
  • Realistic Benchmarks: Sachs (a classic real-world protein-signaling dataset with $d=11$ variables and 853 observations) and Sergio (a semi-synthetic single-cell gene regulatory network simulator, evaluated on 10-variable subgraphs).

Key Insights and Ideas

Optimization Trajectories: Traditional Solvers vs. ADAG Layers

Figure 2: Comparison of Optimization Trajectories for DAG Learning. For Quasi-Newton and Newton-Raphson approaches, we visualize the intermediate weighted adjacency matrices. For our ADAG approach, we decode and visualize the attention obtained by Eq. (4).
  • Attention is Secretly a Fixed-Point Solver: The authors prove mathematically that passing representations through consecutive linear-attention layers is equivalent to running a contractive fixed-point iteration ($A_{(l+1)} = g(A_{(l)})$). Pre-training across multiple domains forces the transformer to discover its own optimization algorithm. Early layers produce dense, cyclic graphs that later layers locally prune into sparse, valid DAGs—internalizing the acyclicity constraint without needing test-time Lagrangians.
  • Graph-Theoretic Local Reasoning: Expanding the layer update math reveals terms like $A^2$, $AA^\top$, and $A^2A^\top$. Intuitively, each layer refines edge weights by inspecting paths of length 2 (grandchildren) and common-children structures!
  • Out-of-Distribution Generalization: Because ADAG learns local edge-pruning rules rather than memorizing whole graphs, a model trained strictly on sparse synthetic linear-Gaussian data generalizes zero-shot to denser graphs, non-Gaussian noise, nonlinear mechanisms, and real biological data.
  • Data-Scarce Regularization: Multi-domain pre-training captures low-dimensional structural invariants across tasks, acting as a natural prior that keeps estimates sharp even with tiny sample sizes ($n=25$).

Key Results

Inference Speed vs. One-Time Pre-Training Cost

Figure 4: Efficiency: wall-clock time (log scale) averaged over all graph and data types. Solid lines: per-domain inference time; hollow markers with arrows: runs exceeding the 5-minute budget; dashed line: ADAG’s one-time pre-training cost, amortized over all subsequent zero-shot inferences.

ADAG outperforms seven state-of-the-art single-domain, multi-domain, and supervised amortized baselines (including NOTEARS, DAGMA, MultiDAG, and AVICI), measured by Structural Hamming Distance (SHD) (edge errors; lower is better):

  • Sub-Millisecond Speedups: While pre-training takes ~10 minutes ($d=5$) to ~3 hours ($d=50$), zero-shot inference takes under 1 millisecond ($0.3\text{ ms}$ on real datasets)—orders of magnitude faster than optimization baselines that take seconds to minutes per dataset.
  • Superior Accuracy: ADAG achieves the lowest SHD across all linear and nonlinear synthetic settings. On $d=5$ heterogeneous ER1 graphs, it hits an SHD of 0.027, nearly halving the runner-up MultiDAG (0.047). On nonlinear $d=50$ ER2 graphs, it reaches 27.5 SHD vs. 36.0 for NOTEARS-MLP and 50.7 for AVICI.
  • Small-Sample Resilience: With just $n=25$ samples on general $d=5$ graphs, ADAG achieves 0.164 SHD (when pre-trained at $n=100$ and resampled), compared to 0.785 for DAGMA and 5.100 for AVICI.
  • Synthetic-to-Real Transfer: Pre-trained only on synthetic linear SEMs, ADAG matches the best SHD on Sachs (13) while achieving the best F1 (0.385), and takes the top spot on Sergio (2.48 SHD vs. 3.40 for DAGMA) in $0.0003$ seconds.

Limitations and Future Work

  • Variable Scaling: Due to academic compute budgets during pre-training, experiments are capped at $d \le 50$ variables (with training complexity scaling as $\mathcal{O}(Mdn^2)$).
  • Future Directions: The authors note the architecture itself isn't fundamentally bottlenecked at $d=50$, suggesting Fourier-attention or divide-and-conquer graph partitioning strategies to scale pre-trained causal foundation models to much larger variable spaces.

Summary updated

Abstract

Directed Acyclic Graphs (DAGs) are foundational to many areas of AI research, providing a formal language for causal reasoning and model interpretability. However, learning DAGs remains challenging, due to super-exponential computational cost and diminished accuracy in small sample regimes. To address these challenges, we introduce Attention-DAG (ADAG), a novel linear transformer architecture for unsupervised amortized DAG learning. Unlike traditional unsupervised DAG learning methods which recover the graph structure from data of each individual domain, ADAG leverages the knowledge from multiple domains. It provides a nonlinear mapping from observational data of each domain to both the corresponding graph structure and the underlying parameters of Structural Equation Models (SEMs). This enables efficient zero-shot inference of causal structures in new domains with unseen SEM parameters. Remarkably, we demonstrate that for the DAG learning problem, attention acts as a fixed-point iterative scheme, so the training on multiple domains effectively discovers an efficient solver for the constraint optimization problem. Extensive evaluations on synthetic and realistic benchmarks demonstrate that ADAG significantly outperforms existing baselines in accuracy and efficiency, particularly when data is scarce. Our code accompanying this paper is provided at \url{https://github.com/fishmoon1234/Attention-Based-Causal-Discovery}.
BibTeX
@inproceedings{yin2026attention,
  author = {Naiyu Yin and Tian Gao and Yue Yu},
  title = {{Attention-Based Pretraining for Unsupervised Amortized Causal Discovery}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=IWyVTvkGab},
}
Figure