Downloads · 30 days
211
50% of all-time downloads
DMIRLAB/CDFM
CDFM is a machine learning model from DMIRLAB. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
<p align="center" <a href="https://arxiv.org/abs/2607.11508"<img src="https://img.shields.io/badge/arXiv-2607.11508-b31b1b.svg" alt="arXiv"</a <a href="https://huggingface.co/DMIRLAB/CDFM"<img src="https://img.shields…
Downloads · 30 days
211
50% of all-time downloads
All-time downloads
419
Public
Parameters
9.7M
38.7 MB on disk
Likes
13
Public
Click a slice to open those files.
.safetensors38.7 MB · 100%
From the Hugging Face model README
Causal Discovery Foundation Model (CDFM) is a pretrained foundation model for zero-shot causal discovery. Given purely observational data X (N, D), it predicts the causal graph G (D, D) in a single forward pass.
CDFM reframes causal discovery as a unified, general-purpose framework for zero-shot structural inference. By pretraining on a massive, highly diverse space of synthetic structural causal models, CDFM successfully internalizes complex statistical asymmetries.
<p align="center"> <img src="https://raw.githubusercontent.com/DMIRLAB-Group/CDFM/refs/heads/main/docs/figures/benchmark_overview.png" width="85%" style="display: block; margin: auto;" alt="CDFM benchmark overview"> </p>model.predict(data) call.pip install cdfm-base
Requirements: torch>=2.0, numpy>=1.20, safetensors, networkx, huggingface_hub.
The simplest way to use CDFM is to load the model and pass your observational data directly. By default, CDFM automatically calibrates the threshold for edge prediction.
from cdfm import CDFM
from cdfm.utils import evaluate_graph, edge_auroc
import numpy as np
# Load from HuggingFace Hub
model = CDFM.from_pretrained("DMIRLAB/CDFM")
# Load a simple 4-variable nonlinear example (RFF mechanisms)
data = np.loadtxt("tests/data/simple/data.csv", delimiter=",")
gt = np.loadtxt("tests/data/simple/adjacency.csv", delimiter=",").astype(np.int32)
# 1. Standard Prediction (Auto-calibrated threshold)
result = model.predict(data)
# 2. Manual Threshold Control
result_manual = model.predict(data, threshold=0.5)
print(result.adjacency) # (D, D) binary causal graph
metrics = evaluate_graph(result.adjacency, gt)
auc = edge_auroc(result.logits, gt)
print(f"F1={metrics['f1']:.4f} SHD={metrics['shd']} AUC={auc:.4f}")
# → F1=1.0000 SHD=0 AUC=1.0000
CDFM has a built-in imputation head trained with quantile loss. Call model.imputation(data) to fill missing values automatically:
from cdfm import CDFM
import numpy as np
model = CDFM.from_pretrained("DMIRLAB/CDFM")
# Load data and create missing values (seed for reproducibility)
rng = np.random.default_rng(42)
data = np.loadtxt("tests/data/simple/data.csv", delimiter=",")
data_with_nan = data.copy()
data_with_nan[rng.random(data.shape) < 0.2] = np.nan
# CDFM imputation — auto-detects NaN
imputed = model.imputation(data_with_nan)
# Compare with mean imputation
mean_imp = data_with_nan.copy()
for j in range(data.shape[1]):
col = data_with_nan[~np.isnan(data_with_nan[:, j]), j]
mean_imp[np.isnan(mean_imp[:, j]), j] = col.mean()
missing = np.isnan(data_with_nan)
mae_cdfm = np.abs(imputed[missing] - data[missing]).mean()
mae_mean = np.abs(mean_imp[missing] - data[missing]).mean()
print(f"CDFM MAE: {mae_cdfm:.4f} | Mean MAE: {mae_mean:.4f}")
# → CDFM MAE: 0.3719 | Mean MAE: 0.7817
CDFM Classclass CDFM:
@classmethod
def from_pretrained(
cls,
pretrained_model_name_or_path: str = "DMIRLAB/CDFM", # HF Hub or local path
device: str = "auto", # auto / cpu / cuda:N
threshold: float | None = None, # None = auto-calibrate
) -> "CDFM"
def predict(
self,
data: np.ndarray, # (N, D) float32
threshold: float | None = None, # Probability threshold
standardize: bool = True, # Apply z-score standardization
missing_mask: np.ndarray | None = None,
) -> CDFMResult
CDFMResult Object@dataclass
class CDFMResult:
logits: np.ndarray # (D, D) raw edge scores
probabilities: np.ndarray # (D, D) sigmoid(logits)
adjacency: np.ndarray | None # (D, D) binary graph
threshold: float | None # Threshold value used
runtime_sec: float # Wall-clock time
This project is licensed under Apache 2.0.
If you use CDFM in your research, please cite:
@article{qiao2026cdfm,
title = {{CDFM}: Towards a General-Purpose Causal Discovery Foundation Model},
author = {Jie Qiao and Ruichu Cai and Zijian Li and Weilin Chen and
Pengfei Hua and Boyan Xu and Zhengming Chen and Zhifeng Hao and
Peng Cui},
journal = {arXiv preprint arXiv:2607.11508},
year = {2026},
}