Skip to content

Commit

Permalink
Merge branch 'master' into homophily
Browse files Browse the repository at this point in the history
  • Loading branch information
mufeili committed Mar 23, 2023
2 parents 1a80e18 + 097fd6d commit 84f64ba
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 79 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dgl_option(USE_HDFS "Build with HDFS support" OFF) # Set env HADOOP_HDFS_HOME if
dgl_option(REBUILD_LIBXSMM "Clean LIBXSMM build cache at every build" OFF) # Set env HADOOP_HDFS_HOME if needed
dgl_option(USE_EPOLL "Build with epoll for socket communicator" ON)
dgl_option(TP_BUILD_LIBUV "Build libuv together with tensorpipe (only impacts Linux)" ON)
dgl_option(BUILD_TORCH "Build the PyTorch plugin" OFF)
dgl_option(BUILD_SPARSE "Build DGL sparse library" ON)
dgl_option(TORCH_PYTHON_INTERPS "Python interpreter used to build tensoradapter and DGL sparse library" python3)

Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def is_authorized(name) {
'czkkkkkk',
'nv-dlasalle', 'yaox12', 'chang-l', 'Kh4L', 'VibhuJawa',
'kkranen',
'bgawrych', 'itaraban', 'daniil-sizov',
'VoVAllen',
]
return (name in devs)
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/scripts/build_dgl_asv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pip install -r /asv/torch_gpu_pip.txt
# 'CUDA_TOOLKIT_ROOT_DIR' is always required for sparse build as torch1.13.1+cu116 is installed.
CMAKE_VARS="-DUSE_OPENMP=ON -DBUILD_TORCH=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda"
if [[ $DEVICE == "gpu" ]]; then
CMAKE_VARS="-DUSE_CUDA=ON -DUSE_NCCL=ON $CMAKE_VARS"
fi
arch=`uname -m`
if [[ $arch == *"x86"* ]]; then
CMAKE_VARS="-DUSE_AVX=ON $CMAKE_VARS"
CMAKE_VARS="-DUSE_CUDA=ON $CMAKE_VARS"
fi
mkdir -p build
pushd build
Expand Down
7 changes: 2 additions & 5 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ set(BUILD_CPP_TEST OFF)
# Whether to enable OpenMP.
set(USE_OPENMP ON)

# Whether to enable Intel's avx optimized kernel.
set(USE_AVX ON)

# Whether to build PyTorch plugins.
set(BUILD_TORCH ON)

# Whether to enable CUDA kernels compiled with TVM.
set(USE_TVM OFF)

# Whether to enable fp16 to support mixed precision training.
set(USE_FP16 OFF)
# Whether to build DGL sparse library.
set(BUILD_SPARSE ON)
6 changes: 4 additions & 2 deletions dgl_sparse/src/sparse_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ std::shared_ptr<CSR> DiagToCSR(
const c10::TensorOptions& indices_options) {
int64_t nnz = std::min(diag->num_rows, diag->num_cols);
auto indptr = torch::full(diag->num_rows + 1, nnz, indices_options);
torch::arange_out(indptr, nnz + 1);
auto nnz_range = torch::arange(nnz + 1, indices_options);
indptr.index_put_({nnz_range}, nnz_range);
auto indices = torch::arange(nnz, indices_options);
return std::make_shared<CSR>(
CSR{diag->num_rows, diag->num_cols, indptr, indices,
Expand All @@ -125,7 +126,8 @@ std::shared_ptr<CSR> DiagToCSC(
const c10::TensorOptions& indices_options) {
int64_t nnz = std::min(diag->num_rows, diag->num_cols);
auto indptr = torch::full(diag->num_cols + 1, nnz, indices_options);
torch::arange_out(indptr, nnz + 1);
auto nnz_range = torch::arange(nnz + 1, indices_options);
indptr.index_put_({nnz_range}, nnz_range);
auto indices = torch::arange(nnz, indices_options);
return std::make_shared<CSR>(
CSR{diag->num_cols, diag->num_rows, indptr, indices,
Expand Down
1 change: 1 addition & 0 deletions docs/source/api/python/dgl.data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Datasets for graph classification/regression tasks
GINDataset
FakeNewsDataset
BA2MotifDataset
ZINCDataset

Dataset adapters
-------------------
Expand Down
16 changes: 8 additions & 8 deletions docs/source/guide_ko/message-api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _guide_ko-message-passing-api:

2.1 빌트인 함수 및 메지시 전달 API들
2.1 빌트인 함수 및 메시지 전달 API들
-----------------------------

:ref:`(English Version) <guide-message-passing-api>`
Expand All @@ -11,11 +11,11 @@ DGL에서 **메시지 함수** 는 한개의 인자 ``edges`` 를 갖는데, 이

**업데이트 함수** 는 위에서 언급한 ``nodes`` 를 한개의 인자로 갖는다. 이 함수는 ``축약 함수`` 의 집계 결과에 적용되는데, 보통은 마지막 스탭에서 노드의 원래 피처와 이 결과와 결합하고, 그 결과를 노드의 피처로 저장한다.

DGL은 일반적으로 사용되는 메시지 전달 함수들과 축약 함수들을 ``dgl.function`` 네임스패이스에 **빌트인** 으로 구현하고 있다. 일반적으로, **가능한 경우라면 항상** DLG의 빌드인 함수를 사용하는 것을 권장하는데, 그 이유는 이 함수들은 가장 최적화된 형태로 구현되어 있고, 차원 브로드케스팅을 자동으로 해주기 때문이다.
DGL은 일반적으로 사용되는 메시지 전달 함수들과 축약 함수들을 ``dgl.function`` 네임스패이스에 **빌트인** 으로 구현하고 있다. 일반적으로, **가능한 경우라면 항상** DLG의 빌트인 함수를 사용하는 것을 권장하는데, 그 이유는 이 함수들은 가장 최적화된 형태로 구현되어 있고, 차원 브로드캐스팅을 자동으로 해주기 때문이다.

만약 여러분의 메시지 전달 함수가 빌드인 함수로 구현이 불가능하다면, 사용자 정의 메시지/축소 함수를 직접 구현할 수 있다. 이를 **UDF** 라고 한다.
만약 여러분의 메시지 전달 함수가 빌트인 함수로 구현이 불가능하다면, 사용자 정의 메시지/축소 함수를 직접 구현할 수 있다. 이를 **UDF** 라고 한다.

빌트인 메시지 함수들은 단항(unary) 또는 이상(binary)이다. 단항의 경우 DGL은 ``copy`` 를 지원한다. 이항 함수로 DGL은 ``add`` , ``sub`` , ``mul`` , ``div`` , 그리고 ``dot`` 를 지원한다. 빌트인 메시지 함수의 이름 규칙은 다음과 같다. ``u`` 는 ``src`` 노드를, ``v`` 는 ``dst`` 노드를 그리고 ``e`` 는 ``edges`` 를 의미한다. 이 함수들에 대한 파라메터들은 관련된 노드와 에지의 입력과 출력 필드 이름을 지칭하는 문자열이다. 지원되는 빌트인 함수의 목록은 :ref:`api-built-in` 을 참고하자. 한가지 예를 들면, 소스 노드의 ``hu`` 피처와 목적지 노드의 ``hv`` 피처를 더해서 그 결과를 에지의 ``he`` 필드에 저장하는 것을 빌드인 함수 ``dgl.function.u_add_v('hu', 'hv', 'he')`` 를 사용해서 구현할 수 있다. 이와 동일한 기능을 하는 메시지 UDF는 다음과 같다.
빌트인 메시지 함수들은 단항(unary) 또는 이상(binary)이다. 단항의 경우 DGL은 ``copy`` 를 지원한다. 이항 함수로 DGL은 ``add`` , ``sub`` , ``mul`` , ``div`` , 그리고 ``dot`` 를 지원한다. 빌트인 메시지 함수의 이름 규칙은 다음과 같다. ``u`` 는 ``src`` 노드를, ``v`` 는 ``dst`` 노드를 그리고 ``e`` 는 ``edges`` 를 의미한다. 이 함수들에 대한 파라미터들은 관련된 노드와 에지의 입력과 출력 필드 이름을 지칭하는 문자열이다. 지원되는 빌트인 함수의 목록은 :ref:`api-built-in` 을 참고하자. 한가지 예를 들면, 소스 노드의 ``hu`` 피처와 목적지 노드의 ``hv`` 피처를 더해서 그 결과를 에지의 ``he`` 필드에 저장하는 것을 빌트인 함수 ``dgl.function.u_add_v('hu', 'hv', 'he')`` 를 사용해서 구현할 수 있다. 이와 동일한 기능을 하는 메시지 UDF는 다음과 같다.

.. code::
Expand All @@ -32,7 +32,7 @@ DGL은 일반적으로 사용되는 메시지 전달 함수들과 축약 함수
UDF의 고급 사용법을 더 알고 싶으면 :ref:`apiudf` 를 참고하자.

:meth:`~dgl.DGLGraph.apply_edges` 를 사용해서 메시지 전달 함수를 호출하지 않고 에지별 연산만 호출하는 것도 가능하다. :meth:`~dgl.DGLGraph.apply_edges` 는 파라메터로 메시지 함수를 받는데, 기본 설정으로는 모든 에지의 피쳐를 업데이트한다. 다음 예를 살펴보자.
:meth:`~dgl.DGLGraph.apply_edges` 를 사용해서 메시지 전달 함수를 호출하지 않고 에지별 연산만 호출하는 것도 가능하다. :meth:`~dgl.DGLGraph.apply_edges` 는 파라미터로 메시지 함수를 받는데, 기본 설정으로는 모든 에지의 피쳐를 업데이트한다. 다음 예를 살펴보자.

.. code::
Expand All @@ -41,7 +41,7 @@ UDF의 고급 사용법을 더 알고 싶으면 :ref:`apiudf` 를 참고하자.
메시지 전달을 위한 :meth:`~dgl.DGLGraph.update_all` 는 하이레벨 API로 메시지 생성, 메시지 병합 그리고 노드 업데이트를 단일 호출로 합쳤는데, 전반적으로 최적화할 여지가 남아있다.

:meth:`~dgl.DGLGraph.update_all` 의 파라메터들은 메시지 함수, 축약 함수, 그리고 업데이트 함수이다. :meth:`~dgl.DGLGraph.update_all` 를 호출할 때 업데이트 함수를 지정하지 않는 경우, 업데이트 함수는 ``update_all`` 밖에서 수행될 수 있다. DGL은 이 방법은 권장하는데, 그 이유는 업데이트 함수는 코드를 간결하게 만들기 위해서 보통은 순수 텐서 연산으로 구현되어 있기 때문이다. 예를 들면, 다음과 같다.
:meth:`~dgl.DGLGraph.update_all` 의 파라메터들은 메시지 함수, 축약 함수, 그리고 업데이트 함수이다. :meth:`~dgl.DGLGraph.update_all` 를 호출할 때 업데이트 함수를 지정하지 않는 경우, 업데이트 함수는 ``update_all`` 밖에서 수행될 수 있다. DGL은 이 방법을 권장하는데, 업데이트 함수는 코드를 간결하게 만들기 위해서 보통은 순수 텐서 연산으로 구현되어 있기 때문이다. 예를 들면, 다음과 같다.

.. code::
Expand All @@ -57,6 +57,6 @@ UDF의 고급 사용법을 더 알고 싶으면 :ref:`apiudf` 를 참고하자.

.. math:: {final\_ft}_i = 2 * \sum_{j\in\mathcal{N}(i)} ({ft}_j * a_{ij})

DGL의 빌트임 함수는 부동수수점 데이터 타입을 지원한다. 즉, 피쳐들은 반드시 ``half`` (``float16``), ``float``, 또는 ``double`` 텐서여야만 한다. ``float16`` 데이터 타입에 대한 지원은 기본 설정에서는 비활성화되어 있다. 그 이유는 이를 지원하기 위해서는 ``sm_53`` (Pascal, Volta, Turing, 그리고 Ampere 아키텍타)와 같은 최소한의 GPU 컴퓨팅 능력이 요구되기 때문이다.
DGL의 빌트인 함수는 부동소수점 데이터 타입을 지원한다. 즉, 피쳐들은 반드시 ``half`` (``float16``), ``float``, 또는 ``double`` 텐서여야만 한다. ``float16`` 데이터 타입에 대한 지원은 기본 설정에서는 비활성화되어 있다. 그 이유는 이를 지원하기 위해서는 ``sm_53`` (Pascal, Volta, Turing, 그리고 Ampere 아키텍타)와 같은 최소한의 GPU 컴퓨팅 능력이 요구되기 때문이다.

사용자는 DGL 소스 컴파일을 통해서 mixed precision training을 위해서 float16을 활성화시킬 수 있다. (자세한 내용은 :doc:`Mixed Precision Training <mixed_precision>` 튜터리얼 참고)
사용자는 DGL 소스 컴파일을 통해서 mixed precision training을 위해서 float16을 활성화시킬 수 있다. (자세한 내용은 :doc:`Mixed Precision Training <mixed_precision>` 튜토리얼 참고)
23 changes: 1 addition & 22 deletions docs/source/guide_ko/mixed_precision.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,7 @@

:ref:`(English Version) <guide-mixed_precision>`

DGL은 mixed precision 학습을 위해서 `PyTorch's automatic mixed precision package <https://pytorch.org/docs/stable/amp.html>`_ 와 호환된다. 따라서, 학습 시간 및 GPU 메모리 사용량을 절약할 수 있다. 이 기능을 활성화하기 위해서는, PyTorch 1.6+, python 3.7+을 설치하고, ``float16`` 데이터 타입 지원을 위해서 DGL을 소스 파일을 사용해서 빌드해야 한다. (이 기능은 아직 베타 단계이고, pre-built pip wheel 형태로 제공하지 않는다.)

설치
---------

우선 DGL 소스 코드를 GitHub에서 다운로드하고, ``USE_FP16=ON`` 플래그를 사용해서 shared library를 빌드한다.

.. code:: bash
git clone --recurse-submodules https://github.com/dmlc/dgl.git
cd dgl
mkdir build
cd build
cmake -DUSE_CUDA=ON -DUSE_FP16=ON ..
make -j
다음으로 Python 바인딩을 설치한다.

.. code:: bash
cd ../python
python setup.py install
DGL은 mixed precision 학습을 위해서 `PyTorch's automatic mixed precision package <https://pytorch.org/docs/stable/amp.html>`_ 와 호환된다. 따라서, 학습 시간 및 GPU 메모리 사용량을 절약할 수 있다.

Half precision을 사용한 메시지 전달
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/install/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ install the Python binding for DGL.
mkdir build
cd build
cmake -DUSE_OPENMP=off -DCMAKE_C_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' -DCMAKE_CXX_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' -DUSE_AVX=OFF -DUSE_LIBXSMM=OFF ..
cmake -DUSE_OPENMP=off -DCMAKE_C_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' -DCMAKE_CXX_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' -DUSE_LIBXSMM=OFF ..
make -j4
cd ../python
python setup.py install
Expand Down
6 changes: 3 additions & 3 deletions examples/pytorch/ogb/seal_ogbl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ def evaluate_mrr(pos_val_pred, neg_val_pred, pos_test_pred, neg_test_pred):

# reconstruct the graph for ogbl-collab data for validation edge augmentation and coalesce
if args.dataset == "ogbl-collab":
graph.edata.pop("year")
# float edata for to_simple transform
graph.edata["weight"] = graph.edata["weight"].to(torch.float)
if args.use_valedges_as_input:
val_edges = split_edge["valid"]["edge"]
row, col = val_edges.t()
# float edata for to_simple transform
graph.edata.pop("year")
graph.edata["weight"] = graph.edata["weight"].to(torch.float)
val_weights = torch.ones(size=(val_edges.size(0), 1))
graph.add_edges(
torch.cat([row, col]),
Expand Down
1 change: 1 addition & 0 deletions python/dgl/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .wiki_network import ChameleonDataset
from .wikics import WikiCSDataset
from .yelp import YelpDataset
from .zinc import ZINCDataset


def register_data_args(parser):
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/data/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CLUSTERDataset(DGLBuiltinDataset):
Number of classes for each node.
Examples
-------
--------
>>> from dgl.data import CLUSTERDataset
>>>
>>> trainset = CLUSTERDataset(mode='train')
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/data/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PATTERNDataset(DGLBuiltinDataset):
Number of classes for each node.
Examples
-------
--------
>>> from dgl.data import PATTERNDataset
>>> data = PATTERNDataset(mode='train')
>>> data.num_classes
Expand Down
139 changes: 139 additions & 0 deletions python/dgl/data/zinc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import os

from .dgl_dataset import DGLBuiltinDataset
from .utils import _get_dgl_url, load_graphs


class ZINCDataset(DGLBuiltinDataset):
r"""ZINC dataset for the graph regression task.
A subset (12K) of ZINC molecular graphs (250K) dataset is used to
regress a molecular property known as the constrained solubility.
For each molecular graph, the node features are the types of heavy
atoms, between which the edge features are the types of bonds.
Each graph contains 9-37 nodes and 16-84 edges.
Reference `<https://arxiv.org/pdf/2003.00982.pdf>`_
Statistics:
Train examples: 10,000
Valid examples: 1,000
Test examples: 1,000
Average number of nodes: 23.16
Average number of edges: 39.83
Number of atom types: 28
Number of bond types: 4
Parameters
----------
mode : str, optional
Should be chosen from ["train", "valid", "test"]
Default: "train".
raw_dir : str
Raw file directory to download/contains the input data directory.
Default: "~/.dgl/".
force_reload : bool
Whether to reload the dataset.
Default: False.
verbose : bool
Whether to print out progress information.
Default: False.
transform : callable, optional
A transform that takes in a :class:`~dgl.DGLGraph` object and returns
a transformed version. The :class:`~dgl.DGLGraph` object will be
transformed before every access.
Attributes
----------
num_atom_types : int
Number of atom types.
num_bond_types : int
Number of bond types.
Examples
---------
>>> from dgl.data import ZINCDataset
>>> training_set = ZINCDataset(mode="train")
>>> training_set.num_atom_types
28
>>> len(training_set)
10000
>>> graph, label = training_set[0]
>>> graph
Graph(num_nodes=29, num_edges=64,
ndata_schemes={'feat': Scheme(shape=(), dtype=torch.int64)}
edata_schemes={'feat': Scheme(shape=(), dtype=torch.int64)})
"""

def __init__(
self,
mode="train",
raw_dir=None,
force_reload=False,
verbose=False,
transform=None,
):
self._url = _get_dgl_url("dataset/ZINC12k.zip")
self.mode = mode

super(ZINCDataset, self).__init__(
name="zinc",
url=self._url,
raw_dir=raw_dir,
force_reload=force_reload,
verbose=verbose,
transform=transform,
)

def process(self):
self.load()

def has_cache(self):
graph_path = os.path.join(
self.save_path, "ZincDGL_{}.bin".format(self.mode)
)
return os.path.exists(graph_path)

def load(self):
graph_path = os.path.join(
self.save_path, "ZincDGL_{}.bin".format(self.mode)
)
self._graphs, self._labels = load_graphs(graph_path)

@property
def num_atom_types(self):
return 28

@property
def num_bond_types(self):
return 4

def __len__(self):
return len(self._graphs)

def __getitem__(self, idx):
r"""Get one example by index.
Parameters
----------
idx : int
The sample index.
Returns
-------
dgl.DGLGraph
Each graph contains:
- ``ndata['feat']``: Types of heavy atoms as node features
- ``edata['feat']``: Types of bonds as edge features
Tensor
Constrained solubility as graph label
"""
labels = self._labels["g_label"]
if self._transform is None:
return self._graphs[idx], labels[idx]
else:
return self._transform(self._graphs[idx]), labels[idx]
2 changes: 1 addition & 1 deletion script/build_dgl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ examples:
Start a CUDA build: bash $0 -g
Build incrementally: bash $0
Remove all intermediate output and restart a CPU only build: bash $0 -c -r
Build with extra cmake arguments: bash $0 -c -e '-DUSE_AVX=ON'
Build with extra cmake arguments: bash $0 -c -e '-DBUILD_TORCH=ON'
Build DGL. By default, build incrementally on top of the current state.
Expand Down
Loading

0 comments on commit 84f64ba

Please sign in to comment.