dgl.distributed
DGL分布式模块包含用于支持在机器集群上进行分布式图神经网络训练和推理的类和函数。
这包括几个子模块:
分布式数据结构包括分布式图、分布式张量和分布式嵌入。
分布式采样。
在运行时分布式工作负载拆分。
图分区。
初始化
|
初始化DGL的分布式模块 |
分布式图
- class dgl.distributed.DistGraph(graph_name, gpb=None, part_config=None)[source]
用于访问分布式图的类。
该类提供了DGLGraph API的一个子集,用于在分布式GNN训练和推理中访问分区图数据。因此,其主要用例是与分布式采样API一起工作,以生成小批量数据并在小批量数据上执行前向和后向计算。
该类可以在两种模式下运行:独立模式和分布式模式。
当用户正常运行训练脚本时,
DistGraph
将处于独立模式。 在此模式下,输入数据必须由partition_graph()
构建,且只有一个分区。此模式 用于测试和调试目的。在此模式下,用户必须提供part_config
以便DistGraph
可以加载输入图。当用户使用分布式启动脚本运行训练脚本时,
DistGraph
将被设置为分布式模式。这用于实际的分布式训练。所有分区的数据都由DistGraph
服务器加载,这些服务器由DGL的启动脚本创建。DistGraph
与服务器连接以访问分区的图数据。
目前,
DistGraph
服务器和客户端在分布式模式下运行在同一组机器上。DistGraph
使用共享内存来访问本地机器上的分区数据。这为分布式训练提供了最佳性能。用户可能希望在独立的机器集上运行
DistGraph
服务器和客户端。 在这种情况下,用户可能希望通过在创建DistGraphServer
时传递disable_shared_mem=False
来禁用共享内存。当共享内存被禁用时, 用户必须传递一个分区书。- Parameters:
graph_name (str) – 图的名称。此名称必须与在
dgl.distributed.partition.partition_graph()
中用于分区图的名称相同。gpb (GraphPartitionBook, 可选) – 分区书对象。通常,用户不需要提供分区书。 此参数仅在用户希望在不同的机器上运行服务器进程和训练器进程时才需要。
part_config (str, optional) – 由
dgl.distributed.partition.partition_graph()
生成的分区配置文件的路径。它用于独立模式。
示例
示例展示了在独立模式下创建
DistGraph
的过程。>>> dgl.distributed.partition_graph(g, 'graph_name', 1, num_hops=1, part_method='metis', ... out_path='output/') >>> g = dgl.distributed.DistGraph('graph_name', part_config='output/graph_name.json')
该示例展示了在分布式模式下创建
DistGraph
的过程。>>> g = dgl.distributed.DistGraph('graph-name')
下面的代码展示了使用
DistGraph
进行小批量训练。>>> def sample(seeds): ... seeds = th.LongTensor(np.asarray(seeds)) ... frontier = dgl.distributed.sample_neighbors(g, seeds, 10) ... return dgl.to_block(frontier, seeds) >>> dataloader = dgl.distributed.DistDataLoader(dataset=nodes, batch_size=1000, ... collate_fn=sample, shuffle=True) >>> for block in dataloader: ... feat = g.ndata['features'][block.srcdata[dgl.NID]] ... labels = g.ndata['labels'][block.dstdata[dgl.NID]] ... pred = model(block, feat)
注意
DGL的分布式训练默认在同一组机器上运行服务器进程和训练器进程。如果用户需要在不同的机器组上运行它们,则需要手动设置服务器和训练器。该设置尚未完全测试。
- property device
获取此图形的设备上下文。
示例
以下示例使用PyTorch后端。
>>> g = dgl.heterograph({ ... ('user', 'plays', 'game'): ([0, 1, 1, 2], [0, 0, 2, 1]) ... }) >>> print(g.device) device(type='cpu') >>> g = g.to('cuda:0') >>> print(g.device) device(type='cuda', index=0)
- Return type:
设备上下文对象
- property edata
返回所有边的数据视图。
- Returns:
分布式图存储中的数据视图。
- Return type:
EdgeDataView
- edge_attr_schemes()[source]
返回边缘特征方案。
每个特征方案是一个命名的元组,用于存储边缘特征的形状和数据类型。
- Returns:
边缘特征列的模式。
- Return type:
dict 字符串到方案
示例
以下使用PyTorch后端。
>>> g.edge_attr_schemes() {'h': Scheme(shape=(4,), dtype=torch.float32)}
另请参阅
- property edges
返回一个边的视图
- property etypes
返回此图的边类型列表。
示例
>>> g = DistGraph("test") >>> g.etypes ['_E']
- find_edges(edges, etype=None)[source]
给定一个边ID数组,返回源节点和目标节点ID数组
s
和d
。s[i]
和d[i]
是边eid[i]
的源节点和目标节点ID。- Parameters:
edges (Int Tensor) –
- 每个元素都是一个ID。张量必须具有与图相同的设备类型
和ID数据类型。
etype (str or (str, str, str), optional) –
The type names of the edges. The allowed type name formats are:
(str, str, str)
for source node type, edge type and destination node type.or one
str
edge type name if the name can uniquely identify a triplet format in the graph.
Can be omitted if the graph has only one type of edges.
- Returns:
tensor – The source node ID array.
tensor – The destination node ID array.
- get_edge_partition_policy(etype)[source]
获取边类型的分区策略。
在创建新的分布式张量时,我们需要提供一个分区策略,该策略指示如何在机器集群中分发分布式张量的数据。当我们在集群中加载分布式图时,我们已经为每种节点类型和每种边类型预定义了分区策略。通过提供边类型,我们可以引用为该边类型预定义的分区策略。
- Parameters:
- Returns:
边缘类型的分区策略。
- Return type:
- get_node_partition_policy(ntype)[source]
获取节点类型的分区策略。
在创建新的分布式张量时,我们需要提供一个分区策略,该策略指示如何在机器集群中分发分布式张量的数据。当我们在集群中加载分布式图时,我们已经为每种节点类型和每种边类型预定义了分区策略。通过提供节点类型,我们可以引用为该节点类型预定义的分区策略。
- Parameters:
ntype (str) – 节点类型
- Returns:
节点类型的分区策略。
- Return type:
- property idtype
图索引的数据类型
- Returns:
th.int32/th.int64 或 tf.int32/tf.int64 等。
- Return type:
后端数据类型对象
另请参阅
long
,int
- in_degrees(v='__ALL__')[source]
返回给定节点的入度。
它计算入度。 目前还不支持异构图。
- Parameters:
v (node IDs) –
The node IDs. The allowed formats are:
int
: A single node.Int Tensor: Each element is a node ID. The tensor must have the same device type and ID data type as the graph’s.
iterable[int]: Each element is a node ID.
If not given, return the in-degrees of all the nodes.
- Returns:
The in-degree(s) of the node(s) in a Tensor. The i-th element is the in-degree of the i-th input node. If
v
is anint
, return anint
too.- Return type:
int or Tensor
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
查询所有节点。
>>> g.in_degrees() tensor([0, 2, 1, 1])
查询节点1和2。
>>> g.in_degrees(torch.tensor([1, 2])) tensor([2, 1])
另请参阅
- property local_partition
返回客户端的本地分区
DistGraph 提供了分布式图的全局视图。在内部,如果它与服务器位于同一位置,它可能包含图的一个分区。当服务器和客户端在不同的机器集上运行时,这将返回 None。
- Returns:
本地分区
- Return type:
- property ndata
返回所有节点的数据视图。
- Returns:
分布式图存储中的数据视图。
- Return type:
节点数据视图
- node_attr_schemes()[source]
返回节点特征方案。
每个特征方案是一个命名的元组,用于存储节点特征的形状和数据类型。
- Returns:
节点特征列的模式。
- Return type:
dict of str to schemes
示例
以下使用PyTorch后端。
>>> g.node_attr_schemes() {'h': Scheme(shape=(4,), dtype=torch.float32)}
另请参阅
- property nodes
返回一个节点视图
- property ntypes
返回此图的节点类型列表。
示例
>>> g = DistGraph("test") >>> g.ntypes ['_U']
- num_edges(etype=None)[source]
返回分布式图中的总边数。
- Parameters:
etype (str or (str, str, str), optional) –
The type name of the edges. The allowed type name formats are:
(str, str, str)
for source node type, edge type and destination node type.or one
str
edge type name if the name can uniquely identify a triplet format in the graph.
If not provided, return the total number of edges regardless of the types in the graph.
- Returns:
边的数量
- Return type:
示例
>>> g = dgl.distributed.DistGraph('ogb-product') >>> print(g.num_edges()) 123718280
- num_nodes(ntype=None)[source]
返回分布式图中节点的总数。
- Parameters:
ntype (str, optional) – The node type name. If given, it returns the number of nodes of the type. If not given (default), it returns the total number of nodes of all types.
- Returns:
节点数量
- Return type:
示例
>>> g = dgl.distributed.DistGraph('ogb-product') >>> print(g.num_nodes()) 2449029
- number_of_edges(etype=None)[source]
Alias of
num_edges()
- number_of_nodes(ntype=None)[source]
Alias of
num_nodes()
- out_degrees(u='__ALL__')[source]
返回给定节点的出度。
它计算出度。 目前还不支持异构图。
- Parameters:
u (node IDs) –
The node IDs. The allowed formats are:
int
: A single node.Int Tensor: Each element is a node ID. The tensor must have the same device type and ID data type as the graph’s.
iterable[int]: Each element is a node ID.
If not given, return the in-degrees of all the nodes.
- Returns:
The out-degree(s) of the node(s) in a Tensor. The i-th element is the out-degree of the i-th input node. If
v
is anint
, return anint
too.- Return type:
int or Tensor
示例
以下示例使用PyTorch后端。
>>> import dgl >>> import torch
查询所有节点。
>>> g.out_degrees() tensor([2, 2, 0, 0])
查询节点1和2。
>>> g.out_degrees(torch.tensor([1, 2])) tensor([2, 0])
另请参阅
Distributed Tensor
- class dgl.distributed.DistTensor(shape, dtype, name=None, init_func=None, part_policy=None, persistent=False, is_gdata=True, attach=True)[source]
分布式张量。
DistTensor
引用了一个分布式张量,该张量被分片并存储在一组机器集群中。 它具有与Pytorch Tensor相同的接口,用于访问其元数据(例如,形状和数据类型)。 为了访问分布式张量中的数据,它支持切片行和将数据写入行。 它不支持任何深度学习框架的操作符,例如加法和乘法。目前,分布式张量被设计用于存储分布式图的节点数据和边数据。因此,它们的第一维必须是图中节点或边的数量。张量在第一维上根据节点或边的分区策略进行分片。当创建分布式张量时,如果未提供分区策略,则会根据第一维自动确定分区策略。如果第一维与节点类型的节点数量匹配,
DistTensor
将使用该特定节点类型的分区策略;如果第一维与边类型的边数量匹配,DistTensor
将使用该特定边类型的分区策略。如果 DGL 无法自动确定分区策略(例如,多个节点类型或边类型具有相同数量的节点或边),用户必须显式提供分区策略。分布式张量可以是有名称的或匿名的。 当分布式张量有名称时,如果
persistent=True
,张量可以是持久的。 通常,当DistTensor
对象消失时,DGL会销毁系统中的分布式张量。 然而,即使DistTenor
对象在训练器进程中消失,持久张量仍然存在于系统中。 持久张量的生命周期与DGL服务器相同。DGL不允许匿名张量是持久的。当创建一个
DistTensor
对象时,它可能引用一个现有的分布式张量或创建一个新的张量。分布式张量通过传递给构造函数的名称来标识。如果名称存在,DistTensor
将引用现有的张量。在这种情况下,形状和数据类型必须与现有张量匹配。如果名称不存在,将在kvstore中创建一个新的张量。当创建一个分布式张量时,其值被初始化为零。用户可以定义一个初始化函数来控制值的初始化方式。初始化函数有两个输入参数:形状和数据类型,并返回一个张量。下面展示了一个初始化函数的示例:
def init_func(shape, dtype): return torch.ones(shape=shape, dtype=dtype)
- Parameters:
shape (tuple) – 张量的形状。第一个维度必须是分布式图的节点数或边数。
dtype (dtype) – 张量的数据类型。数据类型必须是深度学习框架中的一种。
name (string, optional) – 嵌入的名称。该名称可以在系统中唯一标识嵌入,以便另一个
DistTensor
对象可以引用分布式张量。init_func (callable, optional) – 用于初始化张量数据的函数。如果未提供初始化函数,嵌入值将初始化为零。
part_policy (PartitionPolicy, optional) – 张量行到集群中不同机器的分区策略。 目前,它仅支持节点分区策略或边分区策略。 系统会自动确定正确的分区策略。
persistent (bool) – 创建的张量是否在
DistTensor
对象销毁后仍然存在。is_gdata (bool) – 创建的张量是否为ndata/edata。
attach (bool) – 是否将组ID附加到名称中以使其全局唯一。
示例
>>> init = lambda shape, dtype: th.ones(shape, dtype=dtype) >>> arr = dgl.distributed.DistTensor((g.num_nodes(), 2), th.int32, init_func=init) >>> print(arr[0:3]) tensor([[1, 1], [1, 1], [1, 1]], dtype=torch.int32) >>> arr[0:3] = th.ones((3, 2), dtype=th.int32) * 2 >>> print(arr[0:3]) tensor([[2, 2], [2, 2], [2, 2]], dtype=torch.int32)
注意
创建
DistTensor
是一个同步操作。当一个训练器进程尝试创建一个DistTensor
对象时,只有当所有训练器进程都执行相同的操作时,创建才会成功。- property dtype
返回分布式张量的数据类型。
- Returns:
张量的数据类型。
- Return type:
数据类型
- property part_policy
返回分区策略
- Returns:
分布式张量的分区策略。
- Return type:
分布式节点嵌入
- class dgl.distributed.DistEmbedding(num_embeddings, embedding_dim, name=None, init_func=None, part_policy=None)[source]
分布式节点嵌入。
DGL 提供了一个分布式嵌入来支持需要可学习嵌入的模型。 DGL 的分布式嵌入主要用于学习图模型的节点嵌入。 由于分布式嵌入是模型的一部分,它们通过小批量更新。 分布式嵌入必须由 DGL 的优化器更新,而不是 由深度学习框架(例如,Pytorch 和 MXNet)提供的优化器。
为了支持在具有许多节点的图上进行高效训练,嵌入支持稀疏更新。也就是说,只有参与小批量计算的嵌入才会被更新。请参考分布式优化器了解DGL中可用的优化器。
分布式嵌入以与
dgl.distributed.DistTensor
相同的方式分片并存储在一组机器中,不同之处在于分布式嵌入是可训练的。由于分布式嵌入以与分布式图的节点和边相同的方式分片,因此通常比深度学习框架提供的稀疏嵌入访问效率更高。- Parameters:
num_embeddings (int) – 嵌入的数量。目前,嵌入的数量必须与节点数量或边的数量相同。
embedding_dim (int) – The dimension size of embeddings.
name (str, optional) – 嵌入的名称。该名称可以在系统中唯一标识嵌入,以便另一个DistEmbedding对象可以引用相同的嵌入。
init_func (callable, optional) – The function to create the initial data. If the init function is not provided, the values of the embeddings are initialized to zero.
part_policy (PartitionPolicy, optional) – 分区策略,用于将嵌入分配到集群中的不同机器上。 目前,它仅支持节点分区策略或边分区策略。 系统会自动确定正确的分区策略。
示例
>>> def initializer(shape, dtype): arr = th.zeros(shape, dtype=dtype) arr.uniform_(-1, 1) return arr >>> emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer) >>> optimizer = dgl.distributed.optim.SparseAdagrad([emb], lr=0.001) >>> for blocks in dataloader: ... feats = emb(nids) ... loss = F.sum(feats + 1, 0) ... loss.backward() ... optimizer.step()
注意
当在正向计算中使用
DistEmbedding
对象时,用户必须随后调用step()
。否则, 将会出现一些内存泄漏。
分布式嵌入优化器
- class dgl.distributed.optim.SparseAdagrad(params, lr, eps=1e-10)[source]
使用Adagrad算法的分布式节点嵌入优化器。
此优化器实现了用于优化
dgl.distributed.DistEmbedding
的分布式稀疏版本的Adagrad算法。稀疏意味着它只更新那些梯度有更新的嵌入,这些嵌入通常只占总嵌入的很小一部分。Adagrad maintains a \(G_{t,i,j}\) for every parameter in the embeddings, where \(G_{t,i,j}=G_{t-1,i,j} + g_{t,i,j}^2\) and \(g_{t,i,j}\) is the gradient of the dimension \(j\) of embedding \(i\) at step \(t\).
注意:稀疏Adagrad优化器的支持是实验性的。
- Parameters:
params (list[dgl.distributed.DistEmbedding]) – dgl.distributed.DistEmbedding 的列表。
lr (float) – The learning rate.
eps (float, Optional) – The term added to the denominator to improve numerical stability Default: 1e-10
- load(f)
从每个等级的文件中加载优化器的本地状态。
注意:这需要在所有等级上调用。
- Parameters:
f (Union[str, os.PathLike]) – 要加载的文件的路径。
另请参阅
- save(f)
将本地state_dict保存到每个等级的磁盘上。
保存的字典包含两部分:
‘params’: 优化器的超参数。
- ‘emb_states’: partial optimizer states, each embedding contains 2 items:
`ids`
: 存储在此排名中的节点/边的全局ID。`states`
: 与`ids`
对应的状态数据。
注意:这需要在所有等级上调用。
- Parameters:
f (Union[str, os.PathLike]) – 要保存文件的路径。
另请参阅
- step()
阶跃函数。
在每批结束时调用step函数,将涉及小批量的嵌入梯度推送到DGL的服务器并更新嵌入。
- class dgl.distributed.optim.SparseAdam(params, lr, betas=(0.9, 0.999), eps=1e-08)[source]
使用Adam算法的分布式节点嵌入优化器。
此优化器实现了分布式稀疏版本的Adam算法,用于优化
dgl.distributed.DistEmbedding
。稀疏意味着它只更新那些梯度有更新的嵌入,这些嵌入通常只占总嵌入的很小一部分。Adam maintains a \(Gm_{t,i,j}\) and Gp_{t,i,j} for every parameter in the embeddings, where \(Gm_{t,i,j}=beta1 * Gm_{t-1,i,j} + (1-beta1) * g_{t,i,j}\), \(Gp_{t,i,j}=beta2 * Gp_{t-1,i,j} + (1-beta2) * g_{t,i,j}^2\), \(g_{t,i,j} = lr * Gm_{t,i,j} / (1 - beta1^t) / \sqrt{Gp_{t,i,j} / (1 - beta2^t)}\) and \(g_{t,i,j}\) is the gradient of the dimension \(j\) of embedding \(i\) at step \(t\).
注意:稀疏Adam优化器的支持是实验性的。
- Parameters:
params (list[dgl.distributed.DistEmbedding]) – The list of dgl.distributed.DistEmbedding.
lr (float) – The learning rate.
betas (tuple[float, float], Optional) – Coefficients used for computing running averages of gradient and its square. Default: (0.9, 0.999)
eps (float, Optional) – The term added to the denominator to improve numerical stability Default: 1e-8
- load(f)
从每个等级的文件中加载优化器的本地状态。
注意:这需要在所有等级上调用。
- Parameters:
f (Union[str, os.PathLike]) – The path of the file to load from.
另请参阅
- save(f)
将本地state_dict保存到每个等级的磁盘上。
保存的字典包含两部分:
‘params’: 优化器的超参数。
- ‘emb_states’: partial optimizer states, each embedding contains 2 items:
`ids`
: 存储在此排名中的节点/边的全局ID。`states`
: state data corrseponding to`ids`
.
注意:这需要在所有等级上调用。
- Parameters:
f (Union[str, os.PathLike]) – 要保存的文件路径。
另请参阅
- step()
阶跃函数。
在每批结束时调用step函数,将小批量中涉及的嵌入梯度推送到DGL的服务器并更新嵌入。
分布式工作负载分割
|
分割节点并返回本地等级的子集。 |
|
分割边并返回本地排名的子集。 |
分布式采样
分布式数据加载器
- class dgl.distributed.DistDataLoader(dataset, batch_size, shuffle=False, collate_fn=None, drop_last=False, queue_size=None)[source]
DGL 定制的多进程数据加载器。
DistDataLoader 提供了一个与 Pytorch 的 DataLoader 类似的接口,用于生成小批量数据并进行多进程处理。它利用由
dgl.distributed.initialize()
创建的工作进程来并行化采样。- Parameters:
dataset (a tensor) – 节点ID或边ID的张量。
batch_size (int) – 每批次加载的样本数量。
shuffle (bool, optional) – 设置为
True
以在每个时期重新洗牌数据(默认值:False
)。collate_fn (callable, optional) – 该函数通常用于对批次中节点的邻居或批次中边的端点节点进行采样。
drop_last (bool, optional) – 设置为
True
以丢弃最后一个不完整的批次,如果数据集大小不能被批次大小整除。如果False
并且数据集的大小不能被批次大小整除,则最后一个批次将较小。(默认值:False
)queue_size (int, optional) – 多进程队列的大小
示例
>>> g = dgl.distributed.DistGraph('graph-name') >>> def sample(seeds): ... seeds = th.LongTensor(np.asarray(seeds)) ... frontier = dgl.distributed.sample_neighbors(g, seeds, 10) ... return dgl.to_block(frontier, seeds) >>> dataloader = dgl.distributed.DistDataLoader(dataset=nodes, batch_size=1000, collate_fn=sample, shuffle=True) >>> for block in dataloader: ... feat = g.ndata['features'][block.srcdata[dgl.NID]] ... labels = g.ndata['labels'][block.dstdata[dgl.NID]] ... pred = model(block, feat)
注意
在使用多进程执行DGL的分布式采样时,用户必须使用此类而不是Pytorch的DataLoader,因为DGL的RPC要求所有进程在调用任何DGL的分布式API之前与服务器建立连接。因此,此数据加载器使用在
dgl.distributed.initialize()
中创建的工作进程。注意
此数据加载器不保证迭代顺序。例如, 如果数据集 = [1, 2, 3, 4],批量大小 = 2 且 shuffle = False,则 [1, 2] 和 [3, 4] 的顺序不保证。
分布式图采样操作符
|
从分布式图中给定节点的邻居中采样。 |
|
从分布式图中给定节点的邻居中采样。 |
|
给定一个边ID数组,从分布式图中返回源节点和目标节点ID数组 |
|
返回由给定节点的入边诱导的子图。 |
分区
图分区手册
- class dgl.distributed.GraphPartitionBook[source]
图分区书的基础类。
对于分布式训练,图被分割成多个部分并加载到多台机器中。分区书包含在集群中定位节点和边的所有必要信息。
分区手册包含各种分区信息,包括
分区数量,
节点或边所属的分区ID,
分区所拥有的节点ID和边ID。
分区中节点和边的本地ID。
目前,只有一个类实现了
GraphPartitionBook
:RangePartitionBook
。它基于一些小的元数据计算节点/边ID和分区ID之间的映射,因为节点/边已被重新标记,以使同一分区中的ID落在连续的ID范围内。当图被分区时,会自动构建一个图分区书。 当加载图分区时,也会加载图分区书。 请参阅
partition_graph()
,load_partition()
和load_partition_book()
了解更多详情。- map_to_homo_nid(ids, ntype)[source]
将类型节点ID和类型ID映射到同质节点ID。
- Parameters:
ids (tensor) – 按类型划分的节点ID
ntype (str) – 节点类型
- Returns:
同质节点ID。
- Return type:
张量
- map_to_per_etype(ids)[source]
将同质边ID映射为类型化ID和边类型。
- Parameters:
ids (tensor) – 同质边的ID。
- Returns:
边的类型ID和按类型划分的边ID。
- Return type:
(tensor, tensor)
- map_to_per_ntype(ids)[source]
将同质节点ID映射为类型化ID和节点类型。
- Parameters:
ids (tensor) – 同质节点ID。
- Returns:
节点类型ID和按类型划分的节点ID。
- Return type:
(tensor, tensor)
- metadata()[source]
返回分区元数据。
元数据包括:
机器ID。
每个分区的节点和边的数量。
示例
>>> print(g.get_partition_book().metadata()) >>> [{'machine_id' : 0, 'num_nodes' : 3000, 'num_edges' : 5000}, ... {'machine_id' : 1, 'num_nodes' : 2000, 'num_edges' : 4888}, ... ...]
- nid2partid(nids, ntype)[source]
从全局节点ID到分区ID
- Parameters:
nids (tensor) – 全局节点ID
ntype (str) – The node type
- Returns:
分区ID
- Return type:
张量
将分区书移动到共享内存。
- Parameters:
graph_name (str) – 图名称。此名称将用于从共享内存中读取分区书在另一个进程中。
- class dgl.distributed.PartitionPolicy(policy_str, partition_book)[source]
这定义了一个分布式张量或分布式嵌入的分区策略。
当DGL对张量进行分片并将它们存储在机器集群中时,它需要将张量的行映射到集群中的机器的分区策略。
虽然可以定义任意的分区策略,但DGL目前支持两种分区策略来将节点和边映射到机器上。要从图分区书中定义分区策略,用户需要指定策略名称(‘node’或‘edge’)。
- Parameters:
policy_str (str) – 分区策略名称,例如,‘edge~_N:_E:_N’ 或 ‘node~_N’。
partition_book (GraphPartitionBook) – 一个图分区书
- property partition_book
获取分区书籍
- Returns:
图分区书籍
- Return type:
拆分和加载分区
|
从数据路径加载分区的数据。 |
|
从分区加载节点/边特征数据。 |
|
从分区配置文件中加载图分区书。 |
|
为分布式训练分割图并将分割存储在文件中。 |
|
将dgl的分区转换为GraphBolt的FusedCSCSamplingGraph。 |