# Graph Structure Attention

> Build graph-derived sparse attention masks for Graphically Structured Diffusion Model style recovery experiments and checks.

- Skill: `yzj623/graph-structure-attention` (Agent Skill)
- Install (CLI): `npx get-skill add yzj623/graph-structure-attention`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yzj623/graph-structure-attention/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: yzj623 (https://skillmd.com/u/yzj623)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/yzj623/graph-structure-attention

---


# Graph Structure Attention

Use this skill when a task gives a graphical model or factor graph and you need the GSDM-style attention contract: one token per variable, self-attention on every token, symmetrized variable dependencies, and optional factor-clique attention.

Do not use this skill to learn graph structure from data. The paper assumes a supplied graphical-model sketch and uses it to constrain a diffusion denoiser.

## Inputs

- `nodes`: ordered variable ids.
- `edges`: directed or undirected pairs of variable ids.
- `factors`: optional lists of node ids that share an undirected factor.
- Optional BCMF dimensions `m`, `n`, and `k` for the paper's matrix-factorization graph.

## Outputs

- Dense boolean mask `mask`.
- Packed sparse representation with `attendable_indices` and `valid_indices_mask`.
- Node metadata and simple mask statistics.

## Workflow

1. Build or receive an ordered node list.
2. Add self-edges for all nodes.
3. Add graph edges in both directions.
4. For each factor scope, add all pairwise co-scope edges.
5. Pack each row of the mask to a fixed-width attendable-index array.
6. Use `scripts/graph_attention.py` for deterministic construction and validation.

## CLI

```bash
python scripts/graph_attention.py --bcmf 2 2 2 --output /tmp/gsdm_graph.json
```

## Validation

```bash
python -m pytest tests
```

The tests verify BCMF node counts, expected local dependencies, absence of unrelated edges, and round-trip reconstruction from packed sparse indices.

## Limitations

The skill validates the structural mask only. It does not implement transformer layers or train a diffusion model.

