skills/torchdrug/references/models_architectures.md
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.
Documented graph neural networks include:
models.GCNmodels.GATmodels.GINmodels.MPNNmodels.NFPmodels.RGCNmodels.ChebNetmodels.SchNetmodels.GearNetTheir 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.
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.
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.
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.
Documented classes and aliases include:
models.ESM (EvolutionaryScaleModeling)models.ProteinCNNmodels.ProteinResNetmodels.ProteinLSTMmodels.ProteinBERTThe 0.2.1 ESM constructor is:
model = models.ESM(
path="~/model-weights/esm/",
model="ESM-1b",
readout="mean",
)
The release notes add ESM-2 support, but checkpoint names and availability
should be verified against the API/source before use. 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.
Embedding models:
models.TransEmodels.DistMultmodels.ComplExmodels.SimplEmodels.RotatENeural reasoning models:
models.NeuralLP (alias of NeuralLogicProgramming)models.KBGATThe 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.
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.
GraphAF uses two flow models:
models.GraphAF(..., use_edge=False, ...)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.
The official pretraining tutorial documents:
models.InfoGraph wrapped by tasks.Unsupervisedtasks.AttributeMaskingOther 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.