Unverified Commit 3c8ac093 authored by Hongzhi (Steve), Chen's avatar Hongzhi (Steve), Chen Committed by GitHub
Browse files

[Misc] Rename number_of_edges and number_of_nodes to num_edges and num_nodes. (#5490)



* Other

* revert

---------
Co-authored-by: default avatarUbuntu <ubuntu@ip-172-31-28-63.ap-northeast-1.compute.internal>
parent 8f9f2e2a
...@@ -299,7 +299,7 @@ def track_acc(data): ...@@ -299,7 +299,7 @@ def track_acc(data):
g.ndata["type_id"] = g.ndata[dgl.NID] g.ndata["type_id"] = g.ndata[dgl.NID]
g.ndata["ntype"] = g.ndata[dgl.NTYPE] g.ndata["ntype"] = g.ndata[dgl.NTYPE]
node_ids = th.arange(g.number_of_nodes()) node_ids = th.arange(g.num_nodes())
# find out the target node ids # find out the target node ids
node_tids = g.ndata[dgl.NTYPE] node_tids = g.ndata[dgl.NTYPE]
loc = node_tids == category_id loc = node_tids == category_id
...@@ -330,7 +330,7 @@ def track_acc(data): ...@@ -330,7 +330,7 @@ def track_acc(data):
# None for one-hot feature, if not none, it should be the feature tensor. # None for one-hot feature, if not none, it should be the feature tensor.
embed_layer = RelGraphEmbedLayer( embed_layer = RelGraphEmbedLayer(
device, device,
g.number_of_nodes(), g.num_nodes(),
node_tids, node_tids,
num_of_ntype, num_of_ntype,
node_feats, node_feats,
...@@ -342,7 +342,7 @@ def track_acc(data): ...@@ -342,7 +342,7 @@ def track_acc(data):
# all model params are in device. # all model params are in device.
model = EntityClassify( model = EntityClassify(
device, device,
g.number_of_nodes(), g.num_nodes(),
n_hidden, n_hidden,
num_classes, num_classes,
num_rels, num_rels,
......
...@@ -53,14 +53,14 @@ class SAGE(nn.Module): ...@@ -53,14 +53,14 @@ class SAGE(nn.Module):
# TODO: can we standardize this? # TODO: can we standardize this?
for l, layer in enumerate(self.layers): for l, layer in enumerate(self.layers):
y = th.zeros( y = th.zeros(
g.number_of_nodes(), g.num_nodes(),
self.n_hidden if l != len(self.layers) - 1 else self.n_classes, self.n_hidden if l != len(self.layers) - 1 else self.n_classes,
) )
sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1) sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1)
dataloader = dgl.dataloading.DataLoader( dataloader = dgl.dataloading.DataLoader(
g, g,
th.arange(g.number_of_nodes()), th.arange(g.num_nodes()),
sampler, sampler,
batch_size=batch_size, batch_size=batch_size,
shuffle=True, shuffle=True,
......
...@@ -149,7 +149,7 @@ class SAGENet(nn.Module): ...@@ -149,7 +149,7 @@ class SAGENet(nn.Module):
def forward(self, blocks, h): def forward(self, blocks, h):
for layer, block in zip(self.convs, blocks): for layer, block in zip(self.convs, blocks):
h_dst = h[: block.number_of_nodes("DST/" + block.ntypes[0])] h_dst = h[: block.num_nodes("DST/" + block.ntypes[0])]
h = layer(block, (h, h_dst), block.edata["weights"]) h = layer(block, (h, h_dst), block.edata["weights"])
return h return h
...@@ -191,7 +191,7 @@ class ItemToItemScorer(nn.Module): ...@@ -191,7 +191,7 @@ class ItemToItemScorer(nn.Module):
def __init__(self, full_graph, ntype): def __init__(self, full_graph, ntype):
super().__init__() super().__init__()
n_nodes = full_graph.number_of_nodes(ntype) n_nodes = full_graph.num_nodes(ntype)
self.bias = nn.Parameter(torch.zeros(n_nodes)) self.bias = nn.Parameter(torch.zeros(n_nodes))
def _add_bias(self, edges): def _add_bias(self, edges):
...@@ -253,7 +253,7 @@ class ItemToItemBatchSampler(IterableDataset): ...@@ -253,7 +253,7 @@ class ItemToItemBatchSampler(IterableDataset):
def __iter__(self): def __iter__(self):
while True: while True:
heads = torch.randint( heads = torch.randint(
0, self.g.number_of_nodes(self.item_type), (self.batch_size,) 0, self.g.num_nodes(self.item_type), (self.batch_size,)
) )
tails = dgl.sampling.random_walk( tails = dgl.sampling.random_walk(
self.g, self.g,
...@@ -261,7 +261,7 @@ class ItemToItemBatchSampler(IterableDataset): ...@@ -261,7 +261,7 @@ class ItemToItemBatchSampler(IterableDataset):
metapath=[self.item_to_user_etype, self.user_to_item_etype], metapath=[self.item_to_user_etype, self.user_to_item_etype],
)[0][:, 2] )[0][:, 2]
neg_tails = torch.randint( neg_tails = torch.randint(
0, self.g.number_of_nodes(self.item_type), (self.batch_size,) 0, self.g.num_nodes(self.item_type), (self.batch_size,)
) )
mask = tails != -1 mask = tails != -1
...@@ -324,10 +324,10 @@ class NeighborSampler(object): ...@@ -324,10 +324,10 @@ class NeighborSampler(object):
# Create a graph with positive connections only and another graph with negative # Create a graph with positive connections only and another graph with negative
# connections only. # connections only.
pos_graph = dgl.graph( pos_graph = dgl.graph(
(heads, tails), num_nodes=self.g.number_of_nodes(self.item_type) (heads, tails), num_nodes=self.g.num_nodes(self.item_type)
) )
neg_graph = dgl.graph( neg_graph = dgl.graph(
(heads, neg_tails), num_nodes=self.g.number_of_nodes(self.item_type) (heads, neg_tails), num_nodes=self.g.num_nodes(self.item_type)
) )
pos_graph, neg_graph = dgl.compact_graphs([pos_graph, neg_graph]) pos_graph, neg_graph = dgl.compact_graphs([pos_graph, neg_graph])
seeds = pos_graph.ndata[dgl.NID] seeds = pos_graph.ndata[dgl.NID]
...@@ -459,7 +459,7 @@ def track_time(data): ...@@ -459,7 +459,7 @@ def track_time(data):
num_workers=num_workers, num_workers=num_workers,
) )
dataloader_test = DataLoader( dataloader_test = DataLoader(
torch.arange(g.number_of_nodes(item_ntype)), torch.arange(g.num_nodes(item_ntype)),
batch_size=batch_size, batch_size=batch_size,
collate_fn=collator.collate_test, collate_fn=collator.collate_test,
num_workers=num_workers, num_workers=num_workers,
......
...@@ -321,7 +321,7 @@ def track_time(data): ...@@ -321,7 +321,7 @@ def track_time(data):
if "feat" in hg.nodes[ntype].data if "feat" in hg.nodes[ntype].data
else None else None
) )
num_nodes[ntype] = hg.number_of_nodes(ntype) num_nodes[ntype] = hg.num_nodes(ntype)
embed_layer = RelGraphEmbed(hg, device, n_hidden, num_nodes, node_feats) embed_layer = RelGraphEmbed(hg, device, n_hidden, num_nodes, node_feats)
model = EntityClassify( model = EntityClassify(
......
...@@ -273,7 +273,7 @@ def track_time(data): ...@@ -273,7 +273,7 @@ def track_time(data):
g.ndata["type_id"] = g.ndata[dgl.NID] g.ndata["type_id"] = g.ndata[dgl.NID]
g.ndata["ntype"] = g.ndata[dgl.NTYPE] g.ndata["ntype"] = g.ndata[dgl.NTYPE]
node_ids = th.arange(g.number_of_nodes()) node_ids = th.arange(g.num_nodes())
# find out the target node ids # find out the target node ids
node_tids = g.ndata[dgl.NTYPE] node_tids = g.ndata[dgl.NTYPE]
loc = node_tids == category_id loc = node_tids == category_id
...@@ -297,7 +297,7 @@ def track_time(data): ...@@ -297,7 +297,7 @@ def track_time(data):
# #
embed_layer = RelGraphEmbedLayer( embed_layer = RelGraphEmbedLayer(
device, device,
g.number_of_nodes(), g.num_nodes(),
node_tids, node_tids,
num_of_ntype, num_of_ntype,
node_feats, node_feats,
...@@ -309,7 +309,7 @@ def track_time(data): ...@@ -309,7 +309,7 @@ def track_time(data):
# all model params are in device. # all model params are in device.
model = EntityClassify( model = EntityClassify(
device, device,
g.number_of_nodes(), g.num_nodes(),
n_hidden, n_hidden,
num_classes, num_classes,
num_rels, num_rels,
......
...@@ -120,7 +120,7 @@ def track_time(data, num_negs, batch_size): ...@@ -120,7 +120,7 @@ def track_time(data, num_negs, batch_size):
iter_start = 3 iter_start = 3
iter_count = 10 iter_count = 10
n_edges = g.number_of_edges() n_edges = g.num_edges()
train_seeds = np.arange(n_edges) train_seeds = np.arange(n_edges)
# Create PyTorch DataLoader for constructing blocks # Create PyTorch DataLoader for constructing blocks
......
...@@ -211,7 +211,7 @@ def run(proc_id, n_gpus, n_cpus, args, devices, dataset, split, queue=None): ...@@ -211,7 +211,7 @@ def run(proc_id, n_gpus, n_cpus, args, devices, dataset, split, queue=None):
# #
embed_layer = RelGraphEmbedLayer( embed_layer = RelGraphEmbedLayer(
dev_id, dev_id,
g.number_of_nodes(), g.num_nodes(),
node_tids, node_tids,
num_of_ntype, num_of_ntype,
node_feats, node_feats,
...@@ -223,7 +223,7 @@ def run(proc_id, n_gpus, n_cpus, args, devices, dataset, split, queue=None): ...@@ -223,7 +223,7 @@ def run(proc_id, n_gpus, n_cpus, args, devices, dataset, split, queue=None):
# all model params are in device. # all model params are in device.
model = EntityClassify( model = EntityClassify(
dev_id, dev_id,
g.number_of_nodes(), g.num_nodes(),
args.n_hidden, args.n_hidden,
num_classes, num_classes,
num_rels, num_rels,
...@@ -438,7 +438,7 @@ def track_time(data, dgl_sparse): ...@@ -438,7 +438,7 @@ def track_time(data, dgl_sparse):
node_feats = [] node_feats = []
for ntype in hg.ntypes: for ntype in hg.ntypes:
if len(hg.nodes[ntype].data) == 0 or args.node_feats is False: if len(hg.nodes[ntype].data) == 0 or args.node_feats is False:
node_feats.append(hg.number_of_nodes(ntype)) node_feats.append(hg.num_nodes(ntype))
else: else:
assert len(hg.nodes[ntype].data) == 1 assert len(hg.nodes[ntype].data) == 1
feat = hg.nodes[ntype].data.pop("feat") feat = hg.nodes[ntype].data.pop("feat")
...@@ -458,7 +458,7 @@ def track_time(data, dgl_sparse): ...@@ -458,7 +458,7 @@ def track_time(data, dgl_sparse):
g.edata["etype"].share_memory_() g.edata["etype"].share_memory_()
g.ndata["type_id"] = g.ndata[dgl.NID] g.ndata["type_id"] = g.ndata[dgl.NID]
g.ndata["type_id"].share_memory_() g.ndata["type_id"].share_memory_()
node_ids = th.arange(g.number_of_nodes()) node_ids = th.arange(g.num_nodes())
# find out the target node ids # find out the target node ids
node_tids = g.ndata[dgl.NTYPE] node_tids = g.ndata[dgl.NTYPE]
......
...@@ -208,11 +208,11 @@ def load_ogb_product(): ...@@ -208,11 +208,11 @@ def load_ogb_product():
splitted_idx["valid"], splitted_idx["valid"],
splitted_idx["test"], splitted_idx["test"],
) )
train_mask = torch.zeros((graph.number_of_nodes(),), dtype=torch.bool) train_mask = torch.zeros((graph.num_nodes(),), dtype=torch.bool)
train_mask[train_nid] = True train_mask[train_nid] = True
val_mask = torch.zeros((graph.number_of_nodes(),), dtype=torch.bool) val_mask = torch.zeros((graph.num_nodes(),), dtype=torch.bool)
val_mask[val_nid] = True val_mask[val_nid] = True
test_mask = torch.zeros((graph.number_of_nodes(),), dtype=torch.bool) test_mask = torch.zeros((graph.num_nodes(),), dtype=torch.bool)
test_mask[test_nid] = True test_mask[test_nid] = True
graph.ndata["train_mask"] = train_mask graph.ndata["train_mask"] = train_mask
graph.ndata["val_mask"] = val_mask graph.ndata["val_mask"] = val_mask
...@@ -241,11 +241,11 @@ def load_ogb_mag(): ...@@ -241,11 +241,11 @@ def load_ogb_mag():
hg = dgl.heterograph(subgs) hg = dgl.heterograph(subgs)
hg.nodes["paper"].data["feat"] = hg_orig.nodes["paper"].data["feat"] hg.nodes["paper"].data["feat"] = hg_orig.nodes["paper"].data["feat"]
hg.nodes["paper"].data["labels"] = labels["paper"].squeeze() hg.nodes["paper"].data["labels"] = labels["paper"].squeeze()
train_mask = torch.zeros((hg.number_of_nodes("paper"),), dtype=torch.bool) train_mask = torch.zeros((hg.num_nodes("paper"),), dtype=torch.bool)
train_mask[train_idx] = True train_mask[train_idx] = True
val_mask = torch.zeros((hg.number_of_nodes("paper"),), dtype=torch.bool) val_mask = torch.zeros((hg.num_nodes("paper"),), dtype=torch.bool)
val_mask[val_idx] = True val_mask[val_idx] = True
test_mask = torch.zeros((hg.number_of_nodes("paper"),), dtype=torch.bool) test_mask = torch.zeros((hg.num_nodes("paper"),), dtype=torch.bool)
test_mask[test_idx] = True test_mask[test_idx] = True
hg.nodes["paper"].data["train_mask"] = train_mask hg.nodes["paper"].data["train_mask"] = train_mask
hg.nodes["paper"].data["val_mask"] = val_mask hg.nodes["paper"].data["val_mask"] = val_mask
...@@ -294,13 +294,13 @@ def load_nowplaying_rs(): ...@@ -294,13 +294,13 @@ def load_nowplaying_rs():
# Assign user and movie IDs and use them as features (to learn an individual trainable # Assign user and movie IDs and use them as features (to learn an individual trainable
# embedding for each entity) # embedding for each entity)
g.nodes[user_ntype].data["id"] = torch.arange(g.number_of_nodes(user_ntype)) g.nodes[user_ntype].data["id"] = torch.arange(g.num_nodes(user_ntype))
g.nodes[item_ntype].data["id"] = torch.arange(g.number_of_nodes(item_ntype)) g.nodes[item_ntype].data["id"] = torch.arange(g.num_nodes(item_ntype))
# Prepare torchtext dataset and vocabulary # Prepare torchtext dataset and vocabulary
fields = {} fields = {}
examples = [] examples = []
for i in range(g.number_of_nodes(item_ntype)): for i in range(g.num_nodes(item_ntype)):
example = torchtext.data.Example.fromlist([], []) example = torchtext.data.Example.fromlist([], [])
examples.append(example) examples.append(example)
textset = torchtext.data.Dataset(examples, fields) textset = torchtext.data.Dataset(examples, fields)
......
...@@ -49,8 +49,8 @@ for k, v in ds_list.items(): ...@@ -49,8 +49,8 @@ for k, v in ds_list.items():
num_edges = [] num_edges = []
for i in range(len(ds)): for i in range(len(ds)):
g = extract_graph(ds[i]) g = extract_graph(ds[i])
num_nodes.append(g.number_of_nodes()) num_nodes.append(g.num_nodes())
num_edges.append(g.number_of_edges()) num_edges.append(g.num_edges())
gg = extract_graph(ds[0]) gg = extract_graph(ds[0])
dd = { dd = {
......
...@@ -97,7 +97,7 @@ sampling APIs to support mini-batch training (see `Distributed sampling`_). ...@@ -97,7 +97,7 @@ sampling APIs to support mini-batch training (see `Distributed sampling`_).
.. code:: python .. code:: python
print(g.number_of_nodes()) print(g.num_nodes())
Access node/edge data Access node/edge data
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
...@@ -132,7 +132,7 @@ in the cluster even if the :class:`~dgl.distributed.DistTensor` object disappear ...@@ -132,7 +132,7 @@ in the cluster even if the :class:`~dgl.distributed.DistTensor` object disappear
.. code:: python .. code:: python
tensor = dgl.distributed.DistTensor((g.number_of_nodes(), 10), th.float32, name='test') tensor = dgl.distributed.DistTensor((g.num_nodes(), 10), th.float32, name='test')
.. note:: .. note::
...@@ -183,7 +183,7 @@ node embeddings. Creating distributed embeddings is very similar to creating dis ...@@ -183,7 +183,7 @@ node embeddings. Creating distributed embeddings is very similar to creating dis
arr = th.zeros(shape, dtype=dtype) arr = th.zeros(shape, dtype=dtype)
arr.uniform_(-1, 1) arr.uniform_(-1, 1)
return arr return arr
emb = dgl.distributed.DistEmbedding(g.number_of_nodes(), 10, init_func=initializer) emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer)
Internally, distributed embeddings are built on top of distributed tensors, Internally, distributed embeddings are built on top of distributed tensors,
and, thus, has very similar behaviors to distributed tensors. For example, when and, thus, has very similar behaviors to distributed tensors. For example, when
......
...@@ -179,7 +179,7 @@ and store it as node data of :math:`T0`. ...@@ -179,7 +179,7 @@ and store it as node data of :math:`T0`.
.. code:: python .. code:: python
g.nodes['T0'].data['feat1'] = dgl.distributed.DistTensor( g.nodes['T0'].data['feat1'] = dgl.distributed.DistTensor(
(g.number_of_nodes('T0'), 1), th.float32, 'feat1', (g.num_nodes('T0'), 1), th.float32, 'feat1',
part_policy=g.get_node_partition_policy('T0')) part_policy=g.get_node_partition_policy('T0'))
The partition policies used for creating distributed tensors and embeddings are The partition policies used for creating distributed tensors and embeddings are
......
...@@ -73,7 +73,7 @@ and removing them. ...@@ -73,7 +73,7 @@ and removing them.
.. code:: python .. code:: python
n_edges = g.number_of_edges() n_edges = g.num_edges()
sampler = dgl.dataloading.as_edge_prediction_sampler( sampler = dgl.dataloading.as_edge_prediction_sampler(
sampler, exclude='reverse_id', reverse_eids=torch.cat([ sampler, exclude='reverse_id', reverse_eids=torch.cat([
torch.arange(n_edges // 2, n_edges), torch.arange(0, n_edges // 2)])) torch.arange(n_edges // 2, n_edges), torch.arange(0, n_edges // 2)]))
......
...@@ -68,13 +68,13 @@ on how messages are aggregated and combined as well. ...@@ -68,13 +68,13 @@ on how messages are aggregated and combined as well.
""" """
# Compute representations layer by layer # Compute representations layer by layer
for l, layer in enumerate([self.conv1, self.conv2]): for l, layer in enumerate([self.conv1, self.conv2]):
y = torch.zeros(g.number_of_nodes(), y = torch.zeros(g.num_nodes(),
self.hidden_features self.hidden_features
if l != self.n_layers - 1 if l != self.n_layers - 1
else self.out_features) else self.out_features)
sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1) sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1)
dataloader = dgl.dataloading.NodeDataLoader( dataloader = dgl.dataloading.NodeDataLoader(
g, torch.arange(g.number_of_nodes()), sampler, g, torch.arange(g.num_nodes()), sampler,
batch_size=batch_size, batch_size=batch_size,
shuffle=True, shuffle=True,
drop_last=False) drop_last=False)
......
...@@ -84,7 +84,7 @@ MFGs. ...@@ -84,7 +84,7 @@ MFGs.
:attr:`block.dstnodes <dgl.DGLGraph.dstnodes>` for features on output nodes, :attr:`block.dstnodes <dgl.DGLGraph.dstnodes>` for features on output nodes,
if the original graph has multiple node types. if the original graph has multiple node types.
- Replace - Replace
:meth:`g.number_of_nodes <dgl.DGLGraph.number_of_nodes>` with either :meth:`g.num_nodes <dgl.DGLGraph.num_nodes>` with either
:meth:`block.number_of_src_nodes <dgl.DGLGraph.number_of_src_nodes>` or :meth:`block.number_of_src_nodes <dgl.DGLGraph.number_of_src_nodes>` or
:meth:`block.number_of_dst_nodes <dgl.DGLGraph.number_of_dst_nodes>` for the number of :meth:`block.number_of_dst_nodes <dgl.DGLGraph.number_of_dst_nodes>` for the number of
input nodes or output nodes respectively. input nodes or output nodes respectively.
......
...@@ -74,7 +74,7 @@ DGL分布式模块的初始化 ...@@ -74,7 +74,7 @@ DGL分布式模块的初始化
.. code:: python .. code:: python
print(g.number_of_nodes()) print(g.num_nodes())
访问节点/边数据 访问节点/边数据
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
...@@ -107,7 +107,7 @@ DGL为分布式张量提供了类似于单机普通张量的接口,以访问 ...@@ -107,7 +107,7 @@ DGL为分布式张量提供了类似于单机普通张量的接口,以访问
.. code:: python .. code:: python
tensor = dgl.distributed.DistTensor((g.number_of_nodes(), 10), th.float32, name='test') tensor = dgl.distributed.DistTensor((g.num_nodes(), 10), th.float32, name='test')
**Note**: :class:`~dgl.distributed.DistTensor` 的创建是一个同步操作。所有训练器都必须调用创建, **Note**: :class:`~dgl.distributed.DistTensor` 的创建是一个同步操作。所有训练器都必须调用创建,
并且只有当所有训练器都调用它时,此创建过程才能成功。 并且只有当所有训练器都调用它时,此创建过程才能成功。
...@@ -147,7 +147,7 @@ DGL提供 :class:`~dgl.distributed.DistEmbedding` 以支持需要节点嵌入的 ...@@ -147,7 +147,7 @@ DGL提供 :class:`~dgl.distributed.DistEmbedding` 以支持需要节点嵌入的
arr = th.zeros(shape, dtype=dtype) arr = th.zeros(shape, dtype=dtype)
arr.uniform_(-1, 1) arr.uniform_(-1, 1)
return arr return arr
emb = dgl.distributed.DistEmbedding(g.number_of_nodes(), 10, init_func=initializer) emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer)
在内部,分布式嵌入建立在分布式张量之上,因此,其行为与分布式张量非常相似。 在内部,分布式嵌入建立在分布式张量之上,因此,其行为与分布式张量非常相似。
例如,创建嵌入时,DGL会将它们分片并存储在集群中的所有计算机上。(分布式嵌入)可以通过名称唯一标识。 例如,创建嵌入时,DGL会将它们分片并存储在集群中的所有计算机上。(分布式嵌入)可以通过名称唯一标识。
......
...@@ -321,7 +321,7 @@ DGL确保块的输出节点将始终出现在输入节点中。如下代码所 ...@@ -321,7 +321,7 @@ DGL确保块的输出节点将始终出现在输入节点中。如下代码所
src = src[mask] src = src[mask]
dst = dst[mask] dst = dst[mask]
# 返回一个与初始图有相同节点的边界 # 返回一个与初始图有相同节点的边界
frontier = dgl.graph((src, dst), num_nodes=g.number_of_nodes()) frontier = dgl.graph((src, dst), num_nodes=g.num_nodes())
return frontier return frontier
def __len__(self): def __len__(self):
...@@ -376,7 +376,7 @@ DGL确保块的输出节点将始终出现在输入节点中。如下代码所 ...@@ -376,7 +376,7 @@ DGL确保块的输出节点将始终出现在输入节点中。如下代码所
new_edges_masks = {} new_edges_masks = {}
# 遍历所有边的类型 # 遍历所有边的类型
for etype in sg.canonical_etypes: for etype in sg.canonical_etypes:
edge_mask = torch.zeros(sg.number_of_edges(etype)) edge_mask = torch.zeros(sg.num_edges(etype))
edge_mask.bernoulli_(self.p) edge_mask.bernoulli_(self.p)
new_edges_masks[etype] = edge_mask.bool() new_edges_masks[etype] = edge_mask.bool()
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
.. code:: python .. code:: python
n_edges = g.number_of_edges() n_edges = g.num_edges()
dataloader = dgl.dataloading.EdgeDataLoader( dataloader = dgl.dataloading.EdgeDataLoader(
g, train_eid_dict, sampler, g, train_eid_dict, sampler,
......
...@@ -51,13 +51,13 @@ ...@@ -51,13 +51,13 @@
""" 用该模块进行离线推断 """ """ 用该模块进行离线推断 """
# 逐层计算表示 # 逐层计算表示
for l, layer in enumerate([self.conv1, self.conv2]): for l, layer in enumerate([self.conv1, self.conv2]):
y = torch.zeros(g.number_of_nodes(), y = torch.zeros(g.num_nodes(),
self.hidden_features self.hidden_features
if l != self.n_layers - 1 if l != self.n_layers - 1
else self.out_features) else self.out_features)
sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1) sampler = dgl.dataloading.MultiLayerFullNeighborSampler(1)
dataloader = dgl.dataloading.NodeDataLoader( dataloader = dgl.dataloading.NodeDataLoader(
g, torch.arange(g.number_of_nodes()), sampler, g, torch.arange(g.num_nodes()), sampler,
batch_size=batch_size, batch_size=batch_size,
shuffle=True, shuffle=True,
drop_last=False) drop_last=False)
......
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
:attr:`block.srcnodes <dgl.DGLGraph.srcnodes>`;对于输出节点特征,将 :attr:`block.srcnodes <dgl.DGLGraph.srcnodes>`;对于输出节点特征,将
:attr:`g.nodes <dgl.DGLGraph.nodes>` 替换为 :attr:`g.nodes <dgl.DGLGraph.nodes>` 替换为
:attr:`block.dstnodes <dgl.DGLGraph.dstnodes>`。 :attr:`block.dstnodes <dgl.DGLGraph.dstnodes>`。
- 对于输入节点数量,将 :meth:`g.number_of_nodes <dgl.DGLGraph.number_of_nodes>` 替换为 - 对于输入节点数量,将 :meth:`g.num_nodes <dgl.DGLGraph.num_nodes>` 替换为
:meth:`block.number_of_src_nodes <dgl.DGLGraph.number_of_src_nodes>` ; :meth:`block.number_of_src_nodes <dgl.DGLGraph.number_of_src_nodes>` ;
对于输出节点数量,将 :meth:`g.number_of_nodes <dgl.DGLGraph.number_of_nodes>` 替换为 对于输出节点数量,将 :meth:`g.num_nodes <dgl.DGLGraph.num_nodes>` 替换为
:meth:`block.number_of_dst_nodes <dgl.DGLGraph.number_of_dst_nodes>` 。 :meth:`block.number_of_dst_nodes <dgl.DGLGraph.number_of_dst_nodes>` 。
异构图上的模型定制 异构图上的模型定制
......
...@@ -55,7 +55,7 @@ DistGraph 생성 ...@@ -55,7 +55,7 @@ DistGraph 생성
.. code:: python .. code:: python
print(g.number_of_nodes()) print(g.num_nodes())
노드/에지 데이터 접근 노드/에지 데이터 접근
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
...@@ -76,7 +76,7 @@ DistGraph 생성 ...@@ -76,7 +76,7 @@ DistGraph 생성
.. code:: python .. code:: python
tensor = dgl.distributed.DistTensor((g.number_of_nodes(), 10), th.float32, name='test') tensor = dgl.distributed.DistTensor((g.num_nodes(), 10), th.float32, name='test')
**Note**: :class:`~dgl.distributed.DistTensor` 생성은 동기화 수행이다. 모든 트레이너들은 생성을 실행해야하고, 모든 트레이너가 이를 호출한 경우에만 생성이 완료된다. **Note**: :class:`~dgl.distributed.DistTensor` 생성은 동기화 수행이다. 모든 트레이너들은 생성을 실행해야하고, 모든 트레이너가 이를 호출한 경우에만 생성이 완료된다.
...@@ -109,7 +109,7 @@ DGL은 노드 임베딩들을 필요로 하는 변환 모델(transductive models ...@@ -109,7 +109,7 @@ DGL은 노드 임베딩들을 필요로 하는 변환 모델(transductive models
arr = th.zeros(shape, dtype=dtype) arr = th.zeros(shape, dtype=dtype)
arr.uniform_(-1, 1) arr.uniform_(-1, 1)
return arr return arr
emb = dgl.distributed.DistEmbedding(g.number_of_nodes(), 10, init_func=initializer) emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer)
내부적으로는 분산 임배딩은 분산 텐서를 사용해서 만들어진다. 따라서, 분산 텐서와 비슷하게 동작한다. 예를 들어, 임베딩이 만들어지면, 그것들은 클러스터의 여러 머신들에 나눠져서(shard) 저장된다. 이는 이름을 통해서 고유하게 식별될 수 있다. 내부적으로는 분산 임배딩은 분산 텐서를 사용해서 만들어진다. 따라서, 분산 텐서와 비슷하게 동작한다. 예를 들어, 임베딩이 만들어지면, 그것들은 클러스터의 여러 머신들에 나눠져서(shard) 저장된다. 이는 이름을 통해서 고유하게 식별될 수 있다.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment