parameter
parameter
¤
ParameterAddressBook
¤
Bases: AddressBook
The address book data structure for the parameter computational graphs. See TorchParameter. The address book stores a list of AddressBookEntry, where each entry stores the information needed to gather the inputs to each (possibly folded) node in the parameter computational graph.
Source code in cirkit/backend/torch/parameters/parameter.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
_select_index(node_outputs, mids, idx)
staticmethod
¤
Source code in cirkit/backend/torch/parameters/parameter.py
48 49 50 51 52 53 54 55 | |
from_index_info(fold_idx_info)
classmethod
¤
Constructs the parameter nodes address book using fold index information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fold_idx_info
|
FoldIndexInfo
|
The fold index information. |
required |
Returns:
| Type | Description |
|---|---|
ParameterAddressBook
|
A parameter nodes address book. |
Source code in cirkit/backend/torch/parameters/parameter.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
lookup(module_outputs, *, in_graph=None)
¤
Source code in cirkit/backend/torch/parameters/parameter.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
TorchParameter
¤
Bases: TorchDiAcyclicGraph[TorchParameterNode]
A torch parameter is a computational graph consisting of computational nodes, and computing a tensor parameter that is then used by a circuit layer. That is, given F the number of folds, and (K_1,\ldots,K_n) the shape of each parameter fold, a torch parameter computes a tensor of shape (F,K_1,\ldots,K_n). Note that a torch parameter does not take any tensor as input.
Source code in cirkit/backend/torch/parameters/parameter.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
device
property
¤
Retrieve the device of the parameter computational graph. Currently, it assumes all torch.nn.parameter.Parameter it contains are stored in the same device.
Returns:
| Type | Description |
|---|---|
device
|
torch.device: The device. |
num_folds
property
¤
The number of folds of the computed tensor parameter.
Returns:
| Type | Description |
|---|---|
int
|
The number of folds. |
shape
property
¤
The shape of the computed tensor parameter, without considering the number of folds. That is, if the number of folds (see TorchParameter.num_folds) is F and the shape is (K_1,\ldots,K_n), it means the torch parameter computes a tensor of shape (F, K_1,\ldots,K_n).
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
The shape of the computed tensor parameter, without considering the number of folds. |
__call__()
¤
Source code in cirkit/backend/torch/parameters/parameter.py
167 168 169 | |
__init__(modules, in_modules, outputs, *, fold_idx_info=None)
¤
Initialize a torch parameter computational graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modules
|
Sequence[TorchParameterNode]
|
The parameter computational nodes. |
required |
in_modules
|
dict[TorchParameterNode, Sequence[TorchParameterNode]]
|
A dictionary mapping nodes to their input nodes, if any. |
required |
outputs
|
Sequence[TorchParameterNode]
|
A list of nodes that are the output nodes in the computational graph. |
required |
fold_idx_info
|
FoldIndexInfo | None
|
The folding index information. It can be None if the Torch graph is not folded. |
None
|
Source code in cirkit/backend/torch/parameters/parameter.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
_build_address_book(fold_idx_info)
¤
Source code in cirkit/backend/torch/parameters/parameter.py
186 187 | |
_build_unfold_index_info()
¤
Source code in cirkit/backend/torch/parameters/parameter.py
181 182 183 184 | |
extra_repr()
¤
Source code in cirkit/backend/torch/parameters/parameter.py
189 190 | |
forward()
¤
Evaluate the parameter computational graph.
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The output parameter tensor, having shape (F, K_1,\ldots K_n), where F is the number of folds, and (K_1,\ldots,K_n) is the shape of each parameter tensor slice. |
Source code in cirkit/backend/torch/parameters/parameter.py
171 172 173 174 175 176 177 178 179 | |
reset_parameters()
¤
Reset the parameters of the parameter computational graph.
Source code in cirkit/backend/torch/parameters/parameter.py
162 163 164 165 | |