package#
Module Contents#
A basic network package data structure used in FedLab. Everything is Tensor in FedLab. |
- supported_torch_dtypes#
- class Package(message_code=None, content=None)#
Bases:
object
A basic network package data structure used in FedLab. Everything is Tensor in FedLab.
Note
slice_size_i = tensor_i.shape[0]
, that is, every element in slices indicates the size of a sub-Tensor in content.Package
maintains 3 variables:header
:torch.Tensor([sender_rank, recv_rank, content_size, message_code, data_type])
slices
:list[slice_size_1, slice_size_2]
content
:torch.Tensor([tensor_1, tensor_2, ...])
- Parameters
message_code (MessageCode) – Message code
content (torch.Tensor, optional) – Tensors contained in this package.
- append_tensor(self, tensor)#
Append new tensor to
Package.content
- Parameters
tensor (torch.Tensor) – Tensor to append in content.
- append_tensor_list(self, tensor_list)#
Append a list of tensors to
Package.content
.- Parameters
tensor_list (list[torch.Tensor]) – A list of tensors to append to
Package.content
.
- to(self, dtype)#
- static parse_content(slices, content)#
Parse package content into a list of tensors
- Parameters
slices (list[int]) – A list containing number of elements of each tensor. Each number is used as offset in parsing process.
content (torch.Tensor) –
Package.content
, a 1-D tensor composed of several 1-D tensors and their corresponding offsets. For more details aboutPackage
.
- Returns
A list of 1-D tensors parsed from
content
- Return type
- static parse_header(header)#
Parse header to get information of current package.
- Parameters
header (torch.Tensor) –
Package.header
, a 1-D tensor composed of 4 elements:torch.Tensor([sender_rank, recv_rank, slice_size, message_code, data_type])
.
:param For more details about
Package
.:- Returns
A tuple containing 5 elements:
(sender_rank, recv_rank, slice_size, message_code, data_type)
.- Return type