本文简要介绍python语言中 torch.distributed.rpc.TensorPipeRpcBackendOptions.set_device_map
的用法。
用法:
set_device_map(to, device_map)
worker_name(str) -被叫方姓名。
device_map(python的字典:int,str, 或者torch.device) -从该工作人员到被调用方的设备放置映射。该映射必须是可逆的。
设置每个 RPC 调用者和被调用者对之间的设备映射。可以多次调用此函数以增量添加设备放置配置。
>>> # both workers >>> def add(x, y): >>> print(x) # tensor([1., 1.], device='cuda:1') >>> return x + y, (x + y).to(2) >>> >>> # on worker 0 >>> options = TensorPipeRpcBackendOptions( >>> num_worker_threads=8, >>> device_maps={"worker1": {0: 1}} >>> # maps worker0's cuda:0 to worker1's cuda:1 >>> ) >>> options.set_device_map("worker1", {1: 2}) >>> # maps worker0's cuda:1 to worker1's cuda:2 >>> >>> rpc.init_rpc( >>> "worker0", >>> rank=0, >>> world_size=2, >>> backend=rpc.BackendType.TENSORPIPE, >>> rpc_backend_options=options >>> ) >>> >>> x = torch.ones(2) >>> rets = rpc.rpc_sync("worker1", add, args=(x.to(0), 1)) >>> # The first argument will be moved to cuda:1 on worker1. When >>> # sending the return value back, it will follow the invert of >>> # the device map, and hence will be moved back to cuda:0 and >>> # cuda:1 on worker0 >>> print(rets[0]) # tensor([2., 2.], device='cuda:0') >>> print(rets[1]) # tensor([2., 2.], device='cuda:1')
例子:
参数:
相关用法
- Python PyTorch Tensor.unflatten用法及代码示例
- Python PyTorch Tensor.register_hook用法及代码示例
- Python PyTorch Tensor.storage_offset用法及代码示例
- Python PyTorch Tensor.to用法及代码示例
- Python PyTorch Tensor.sparse_mask用法及代码示例
- Python PyTorch Tensor.is_leaf用法及代码示例
- Python PyTorch Tensor.imag用法及代码示例
- Python PyTorch Tensor.unfold用法及代码示例
- Python PyTorch Tensor.real用法及代码示例
- Python PyTorch Tensor.refine_names用法及代码示例
- Python PyTorch Tensor.rename用法及代码示例
- Python PyTorch Tensor.view用法及代码示例
- Python PyTorch Tensor.new_empty用法及代码示例
- Python PyTorch Tensor.index_copy_用法及代码示例
- Python PyTorch Tensor.new_tensor用法及代码示例
- Python PyTorch Tensor.scatter_用法及代码示例
- Python PyTorch Tensor.fill_diagonal_用法及代码示例
- Python PyTorch Tensor.repeat用法及代码示例
- Python PyTorch Tensor.item用法及代码示例
- Python PyTorch Tensor.tolist用法及代码示例
- Python PyTorch Tensor.put_用法及代码示例
- Python PyTorch Tensor.map_用法及代码示例
- Python PyTorch Tensor.stride用法及代码示例
- Python PyTorch Tensor.index_fill_用法及代码示例
- Python PyTorch Tensor.align_as用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.distributed.rpc.TensorPipeRpcBackendOptions.set_device_map。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。