Agent skill
pytorch-geometric
Library for Graph Neural Networks (GNNs). Covers MessagePassing layers, modular aggregation schemes, and handling large graphs via mini-batching with disjoint graph representation. (pyg, messagepassing, gnn, gcn, gat, edge_index, knn_graph, global_mean_pool)
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/pytorch-geometric
SKILL.md
Overview
PyTorch Geometric (PyG) is built on top of PyTorch to simplify the implementation of Graph Neural Networks. It treats graphs as Data objects containing node features and edge indices, and provides a powerful MessagePassing base class for custom layer development.
When to Use
Use PyG for data that is naturally represented as a graph, such as social networks, molecular structures, or point clouds. Use it when you need to perform node classification, edge prediction, or graph-level regression.
Decision Tree
- Do you have a list of small graphs?
- USE:
torch_geometric.loader.DataLoaderto create a single giant disjoint graph.
- USE:
- Do you need to pool node features into a graph-level feature?
- USE:
global_mean_poolorglobal_max_poolusing thebatchvector.
- USE:
- Are you building a custom convolution?
- INHERIT: From
torch_geometric.nn.MessagePassing.
- INHERIT: From
Workflows
-
Defining a Custom GNN Layer
- Inherit from
torch_geometric.nn.MessagePassing. - Set the aggregation scheme (
aggr='add','mean', or'max') in__init__. - Implement the forward pass using
self.propagate(). - Define the
message()function to compute the transformation for each edge. - Optionally define the
update()function to transform aggregated results.
- Inherit from
-
Mini-batching Large Graphs
- Use
torch_geometric.loader.DataLoaderinstead of the standard PyTorch version. - PyG automatically creates a single giant disjoint graph from a list of small graphs.
- The
batchvector in the resultingDataobject tracks which original graph each node belongs to. - Use global pooling (e.g.,
global_mean_pool) to aggregate node features into graph-level representations.
- Use
-
Constructing Graphs from Point Clouds
- Represent point clouds as node features in a tensor
[N, F]. - Apply
knn_graph()to dynamically compute anedge_indexbased on spatial proximity. - Pass the results into an
EdgeConvorDynamicEdgeConvlayer for feature extraction.
- Represent point clouds as node features in a tensor
Non-Obvious Insights
- Auto-Indexing: The
_iand_jnotation inMessagePassingmethods automatically handles indexing into source and destination nodes during propagation without manual slice logic. - Disjoint Representation: PyG batches multiple graphs by stacking them into a single block-diagonal adjacency matrix. This allows standard sparse matrix operations to process multiple graphs in parallel without zero-padding.
- Modular Aggregation: Aggregation is a first-class principle in PyG; users can swap simple sum/mean with advanced learnable schemes like
SoftmaxAggregationby simply changing theaggrparameter.
Evidence
- "PyG provides the MessagePassing base class, which helps in creating such kinds of message passing graph neural networks by automatically taking care of message propagation." (https://pytorch-geometric.readthedocs.io/en/latest/tutorial/create_gnn.html)
- "Tensors passed to propagate() can be mapped to the respective nodes i and j by appending _i or _j to the variable name." (https://pytorch-geometric.readthedocs.io/en/latest/tutorial/create_gnn.html)
Scripts
scripts/pytorch-geometric_tool.py: Template for a custom GNN layer and graph data loader.scripts/pytorch-geometric_tool.js: Node.js script to run PyG training experiments.
Dependencies
- torch
- torch-geometric
- torch-scatter / torch-sparse (optional but recommended)
References
- PyTorch Geometric Reference
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
prompt-engineering
Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.
adk-rag-agent
Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.
headless-cli-agents
Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.
notion-knowledge-capture
Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
gh-fix-ci
Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.
Didn't find tool you were looking for?