Skill Tracer
Skills › Scientific Agent Skills › torchdrug › models_architectures.md

models_architectures.md

225 lines · skills/torchdrug/references/models_architectures.md at 5f2bc03

Open on GitHub
1# Models and Architectures
2
3This is a selection guide for the
4[TorchDrug 0.2.1 model API](https://torchdrug.ai/docs/api/models.html). Verify
5constructor signatures on that page before generating code; similarly named
6models in other graph libraries are not API-compatible.
7

Models and Architectures

This is a selection guide for the TorchDrug 0.2.1 model API. Verify constructor signatures on that page before generating code; similarly named models in other graph libraries are not API-compatible.

Raw lines 1 to 7
8## Graph representation models
9
10Documented graph neural networks include:
12- `models.GCN`
13- `models.GAT`
14- `models.GIN`
15- `models.MPNN`
16- `models.NFP`
17- `models.RGCN`
18- `models.ChebNet`
19- `models.SchNet`
20- `models.GearNet`
22Their forward methods generally accept:
24```python
25output = model(graph, input, all_loss=None, metric=None)
26```
28Graph encoders return a dictionary containing node- and/or graph-level
29representations. Inspect the selected model's documented return fields.

Graph representation models

Documented graph neural networks include:

  • models.GCN
  • models.GAT
  • models.GIN
  • models.MPNN
  • models.NFP
  • models.RGCN
  • models.ChebNet
  • models.SchNet
  • models.GearNet

Their forward methods generally accept:

output = model(graph, input, all_loss=None, metric=None)

Graph encoders return a dictionary containing node- and/or graph-level representations. Inspect the selected model's documented return fields.

Raw lines 8 to 30
31### GIN for molecular properties
33The official property tutorial uses:
35```python
36model = models.GIN(
37 input_dim=dataset.node_feature_dim,
38 hidden_dims=[256, 256, 256, 256],
39 short_cut=True,
40 batch_norm=True,
41 concat_hidden=True,
43```
45The pretraining tutorial includes bond features:
47```python
48model = models.GIN(
49 input_dim=dataset.node_feature_dim,
50 hidden_dims=[300, 300, 300, 300, 300],
51 edge_input_dim=dataset.edge_feature_dim,
52 batch_norm=True,
53 readout="mean",
55```
57Use the exact feature configuration that produced
58`dataset.node_feature_dim` and `dataset.edge_feature_dim`.

GIN for molecular properties

The official property tutorial uses:

model = models.GIN(
    input_dim=dataset.node_feature_dim,
    hidden_dims=[256, 256, 256, 256],
    short_cut=True,
    batch_norm=True,
    concat_hidden=True,
)

The pretraining tutorial includes bond features:

model = models.GIN(
    input_dim=dataset.node_feature_dim,
    hidden_dims=[300, 300, 300, 300, 300],
    edge_input_dim=dataset.edge_feature_dim,
    batch_norm=True,
    readout="mean",
)

Use the exact feature configuration that produced dataset.node_feature_dim and dataset.edge_feature_dim.

Raw lines 31 to 59
60### RGCN for typed edges
62The official generation and retrosynthesis tutorials use `RGCN`:
64```python
65model = models.RGCN(
66 input_dim=dataset.node_feature_dim,
67 hidden_dims=[256, 256, 256, 256],
68 num_relation=dataset.num_bond_type,
69 batch_norm=False,
71```
73`num_relation` must match the graph relation vocabulary. For molecule graphs in
74these tutorials, it comes from `dataset.num_bond_type`.

RGCN for typed edges

The official generation and retrosynthesis tutorials use RGCN:

model = models.RGCN(
    input_dim=dataset.node_feature_dim,
    hidden_dims=[256, 256, 256, 256],
    num_relation=dataset.num_bond_type,
    batch_norm=False,
)

num_relation must match the graph relation vocabulary. For molecule graphs in these tutorials, it comes from dataset.num_bond_type.

Raw lines 60 to 75
76### 3D and protein structure models
78- `SchNet` requires a `node_position` graph attribute.
79- `GearNet` is the documented geometry-aware relational model for protein
80 structures.
82Use graph-construction layers to create required spatial and sequential edges;
83do not assume loading a PDB automatically creates every relation a structure
84model expects.

3D and protein structure models

  • SchNet requires a node_position graph attribute.
  • GearNet is the documented geometry-aware relational model for protein structures.

Use graph-construction layers to create required spatial and sequential edges; do not assume loading a PDB automatically creates every relation a structure model expects.

Raw lines 76 to 85
86## Protein sequence encoders
88Documented classes and aliases include:
90- `models.ESM` (`EvolutionaryScaleModeling`)
91- `models.ProteinCNN`
92- `models.ProteinResNet`
93- `models.ProteinLSTM`
94- `models.ProteinBERT`
96The 0.2.1 ESM constructor is:
98```python
99model = models.ESM(
100 path="~/model-weights/esm/",
101 model="ESM-1b",
102 readout="mean",
104```
106The released source supports `ESM-2-8M`, `ESM-2-35M`, `ESM-2-150M`,
107`ESM-2-650M`, `ESM-2-3B`, and `ESM-2-15B`. These use `fair-esm==2.0.0`;
108constructor calls download pretrained weights and remain illustrative here.
109Do not use the unsupported
110pattern `models.ESM(path="checkpoint-file.pt")`; `path` is the directory where
111TorchDrug stores model weights.
113Protein sequence encoders return residue and graph features. Respect the model's
114maximum input length and tokenization behavior.

Protein sequence encoders

Documented classes and aliases include:

  • models.ESM (EvolutionaryScaleModeling)
  • models.ProteinCNN
  • models.ProteinResNet
  • models.ProteinLSTM
  • models.ProteinBERT

The 0.2.1 ESM constructor is:

model = models.ESM(
    path="~/model-weights/esm/",
    model="ESM-1b",
    readout="mean",
)

The released source supports ESM-2-8M, ESM-2-35M, ESM-2-150M, ESM-2-650M, ESM-2-3B, and ESM-2-15B. These use fair-esm==2.0.0; constructor calls download pretrained weights and remain illustrative here. Do not use the unsupported pattern models.ESM(path="checkpoint-file.pt"); path is the directory where TorchDrug stores model weights.

Protein sequence encoders return residue and graph features. Respect the model's maximum input length and tokenization behavior.

Raw lines 86 to 115
116## Knowledge graph models
118Embedding models:
120- `models.TransE`
121- `models.DistMult`
122- `models.ComplEx`
123- `models.SimplE`
124- `models.RotatE`
126Neural reasoning models:
128- `models.NeuralLP` (alias of `NeuralLogicProgramming`)
129- `models.KBGAT`
131The official embedding tutorial uses:
133```python
134model = models.RotatE(
135 num_entity=dataset.num_entity,
136 num_relation=dataset.num_relation,
137 embedding_dim=2048,
138 max_score=9,
140```
142The official NeuralLP tutorial uses:
144```python
145model = models.NeuralLP(
146 num_relation=dataset.num_relation,
147 hidden_dim=128,
148 num_step=3,
149 num_lstm_layer=2,
151```
153Both are wrapped by `tasks.KnowledgeGraphCompletion`; model construction alone
154does not define negative sampling or evaluation.

Knowledge graph models

Embedding models:

  • models.TransE
  • models.DistMult
  • models.ComplEx
  • models.SimplE
  • models.RotatE

Neural reasoning models:

  • models.NeuralLP (alias of NeuralLogicProgramming)
  • models.KBGAT

The official embedding tutorial uses:

model = models.RotatE(
    num_entity=dataset.num_entity,
    num_relation=dataset.num_relation,
    embedding_dim=2048,
    max_score=9,
)

The official NeuralLP tutorial uses:

model = models.NeuralLP(
    num_relation=dataset.num_relation,
    hidden_dim=128,
    num_step=3,
    num_lstm_layer=2,
)

Both are wrapped by tasks.KnowledgeGraphCompletion; model construction alone does not define negative sampling or evaluation.

Raw lines 116 to 155
156## Generative and self-supervised models

Generative and self-supervised models

Raw lines 156 to 157
158### GCPN
160GCPN is exposed as a task rather than a `models.GCPN` class:
162```python
163task = tasks.GCPNGeneration(
164 model,
165 dataset.atom_types,
166 max_edge_unroll=12,
167 max_node=38,
168 criterion="nll",
170```
172The `model` argument is the graph representation model, normally `RGCN` in the
173official tutorial.

GCPN

GCPN is exposed as a task rather than a models.GCPN class:

task = tasks.GCPNGeneration(
    model,
    dataset.atom_types,
    max_edge_unroll=12,
    max_node=38,
    criterion="nll",
)

The model argument is the graph representation model, normally RGCN in the official tutorial.

Raw lines 158 to 174
175### GraphAF
177GraphAF uses two flow models:
179- node flow: `models.GraphAF(..., use_edge=False, ...)`
180- edge flow: `models.GraphAF(..., use_edge=True, ...)`
182Wrap both in:
184```python
185task = tasks.AutoregressiveGeneration(
186 node_flow,
187 edge_flow,
188 max_node=38,
189 max_edge_unroll=12,
190 criterion="nll",
192```
194`models.GraphAF` is an alias for `GraphAutoregressiveFlow`. It is not itself the
195training task.

GraphAF

GraphAF uses two flow models:

  • node flow: models.GraphAF(..., use_edge=False, ...)
  • edge flow: models.GraphAF(..., use_edge=True, ...)

Wrap both in:

task = tasks.AutoregressiveGeneration(
    node_flow,
    edge_flow,
    max_node=38,
    max_edge_unroll=12,
    criterion="nll",
)

models.GraphAF is an alias for GraphAutoregressiveFlow. It is not itself the training task.

Raw lines 175 to 196
197### Self-supervised encoders
199The official pretraining tutorial documents:
201- `models.InfoGraph` wrapped by `tasks.Unsupervised`
202- a base GNN wrapped directly by `tasks.AttributeMasking`
204Other API-documented self-supervised components include `MultiviewContrast`.
205Do not infer a task constructor from a paper name; check whether the component
206lives under `models` or `tasks`.

Self-supervised encoders

The official pretraining tutorial documents:

  • models.InfoGraph wrapped by tasks.Unsupervised
  • a base GNN wrapped directly by tasks.AttributeMasking

Other API-documented self-supervised components include MultiviewContrast. Do not infer a task constructor from a paper name; check whether the component lives under models or tasks.

Raw lines 197 to 207
208## Model selection checklist
2101. Identify the graph/data type.
2112. Check required graph attributes and relation counts.
2123. Build dimensions from the loaded dataset.
2134. Confirm whether the algorithm is a model or a task.
2145. Match checkpoint architecture and feature configuration exactly.
2156. Wrap the model in the task used by the official tutorial or API.
2167. Start with a small batch and one epoch before scaling.

Model selection checklist

  1. Identify the graph/data type.
  2. Check required graph attributes and relation counts.
  3. Build dimensions from the loaded dataset.
  4. Confirm whether the algorithm is a model or a task.
  5. Match checkpoint architecture and feature configuration exactly.
  6. Wrap the model in the task used by the official tutorial or API.
  7. Start with a small batch and one epoch before scaling.
Raw lines 208 to 217
218## Source links
220- [Model API](https://torchdrug.ai/docs/api/models.html)
221- [Task API](https://torchdrug.ai/docs/api/tasks.html)
222- [Property tutorial](https://torchdrug.ai/docs/tutorials/property_prediction.html)
223- [Pretraining tutorial](https://torchdrug.ai/docs/tutorials/pretrain.html)
224- [Generation tutorial](https://torchdrug.ai/docs/tutorials/generation.html)
225- [Reasoning tutorial](https://torchdrug.ai/docs/tutorials/reasoning.html)