본문으로 건너뛰기
Skillpedia
머신러닝51k · #3584

torch-geometric

하는 일

이 도구는 연결 관계를 나타내는 그래프 신경망 모델을 만드는 데 도움을 줍니다. 항목 사이의 관계가 중요한 데이터, 예를 들어 소셜 네트워크나 추천 시스템 분석에 쓰입니다.

사용하는 경우

  • ✓PyTorch 그래프 신경망으로 작업할 때.
  • ✓노드, 링크 또는 그래프 전체를 분류하고 싶을 때.
  • ✓GCN, GAT, GraphSAGE 같은 모델을 사용하는 경우.

스킬 링크

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/torch-geometric/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/torch-geometric/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“PyTorch Geometric으로 그래프에서 노드 분류 모델을 학습시키려면 어떻게 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

바로 쓸 수 있는 구성 요소(레이어)와 그래프를 표현하는 데이터 구조를 제공합니다. 그래프 데이터를 어떻게 정리할지 정하고, 레이어를 사용해 이 정보를 처리합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

PyTorch Geometric (PyG)

PyG is the standard library for Graph Neural Networks built on PyTorch. It provides data structures for graphs, 60+ GNN layer implementations, scalable mini-batch training, and support for heterogeneous graphs.

Installation

Reviewed released torch-geometric 2.8.0.post1 (2026-10-01); CPU examples tested with Python 3.13 / PyTorch 2.14.1. Rolling latest docs identify 2.9.0; check the installed release before adopting new APIs. PyG 2.8 requires PyTorch 2.9+; its original release table covers 2.9–2.12. Our 2.14.1 core tests do not establish every extension/backend combination.

# Install the PyTorch build for your platform from https://pytorch.org/get-started/locally/
uv pip install torch==2.14.1
uv pip install torch-geometric==2.8.0.post1
python -c "import torch, torch_geometric; print(torch.__version__, torch.version.cuda, torch_geometric.__version__)"

Basic tensor-based layers need no extensions. Neighbor sampling requires pyg-lib or torch-sparse; spatial k-NN operators require pyg-lib in 2.8. torch-cluster and torch-spline-conv are deprecated and ignored. Inspect the wheel index for your exact Python/OS/Torch/CUDA tuple. Never install wheels for a different Torch release merely because core imports succeed. The tested macOS ARM CPU extension is below; choose a different matching wheel for other platforms, and verify its operators:

uv pip install --only-binary=:all: "pyg-lib==0.9.0+pt214" \
  -f https://data.pyg.org/whl/torch-2.14.0+cpu.html

Conda packages are no longer provided for Torch >2.5. See installation and 2.8 release changes. Optional sampling/GPU/distributed/download examples below are illustrative unless covered by the CPU checks in review notes.

Core Concepts

Graph Data: Data and HeteroData

A graph lives in a Data object. The key attributes:

from torch_geometric.data import Data

data = Data(
    x=node_features,          # [num_nodes, num_node_features]
    edge_index=edge_index,     # [2, num_edges] — COO format, dtype=torch.long
    edge_attr=edge_features,   # [num_edges, num_edge_features]
    y=labels,                  # node-level [num_nodes, *] or graph-level [1, *]
    pos=positions,             # [num_nodes, num_dimensions] (for point clouds/spatial)
)

edge_index format is critical: it's a [2, num_edges] tensor where edge_index[0] = source nodes, edge_index[1] = target nodes. It is NOT a list of tuples. If you have edge pairs as rows, transpose and call .contiguous():

# If edges are [[src1, dst1], [src2, dst2], ...] — transpose first:
edge_index = edge_pairs.t().contiguous()

For undirected graphs, include both directions: edge (0,1) needs both [0,1] and [1,0] in edge_index.

If node features are absent, set data.num_nodes explicitly from the node table. Inferring it from edge_index.max() + 1 misses isolated nodes, which can corrupt batching offsets and outputs. Check data.validate(raise_on_error=True) after construction, including an edge-free or isolated-node case.

For heterogeneous graphs, use HeteroData — see the Heterogeneous Graphs section below.

Datasets

PyG bundles many standard datasets that auto-download and preprocess:

from torch_geometric.datasets import Planetoid, TUDataset

# Single-graph node classification (Cora, Citeseer, Pubmed)
dataset = Planetoid(root='./data/Cora', name='Cora', split='public')
data = dataset[0]  # single graph with train/val/test masks

# Multi-graph classification (ENZYMES, MUTAG, IMDB-BINARY, etc.)
dataset = TUDataset(root='./data/TU', name='ENZYMES')
# dataset[0], dataset[1], ... are individual graphs

Common datasets by task:

  • Node classification: Planetoid (Cora/Citeseer/Pubmed), OGB (ogbn-arxiv, ogbn-products, ogbn-mag)
  • Graph classification: TUDataset (MUTAG, ENZYMES, PROTEINS, IMDB-BINARY), OGB (ogbg-molhiv)
  • Link prediction: OGB (ogbl-collab, ogbl-citation2)
  • Molecular: QM7b, QM9, MoleculeNet
  • Point cloud/mesh: ShapeNet, ModelNet(name="10" or "40"), FAUST (manual download)

…

자주 묻는 질문

데이터 과학에서 그래프란 무엇인가요?

연결 관계를 나타내는 구조입니다. '노드'(항목)와 '엣지'(항목 사이의 연결)로 이루어집니다.

그래프 신경망(GNN)이란 무엇인가요?

그래프 모양의 데이터에서 학습하는 인공지능의 한 종류로, 항목들 사이의 관계를 이해합니다.

`Data`와 `HeteroData`의 차이는 무엇인가요?

`Data`는 모든 노드와 엣지가 같은 종류인 단순한 그래프를 위한 것입니다. `HeteroData`는 서로 다른 종류의 노드와 엣지가 있는 더 복잡한 그래프를 위한 것입니다.

상세 정보

작성자의 원본 설명

Supports PyTorch Geometric (PyG) graph neural networks — node/link/graph classification, message passing (GCN, GAT, GraphSAGE, GIN), heterogeneous graphs, neighbor sampling, and custom datasets. Use when working with torch_geometric, not for general NetworkX analytics or non-graph PyTorch models.

repo: K-Dense-AI/scientific-agent-skills

인기도

GitHub 스타
51k
순위
#3584
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬