parameter
parameter
¤
ParameterAddressBook
¤
Bases: AddressBook[TorchParameterNode]
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
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 95 96 97 98 99 100 101 102 103 | |
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[TorchParameterNode]
|
The fold index information. |
required |
Returns:
| Type | Description |
|---|---|
ParameterAddressBook
|
A parameter nodes address book. |
Source code in cirkit/backend/torch/parameters/parameter.py
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 95 96 97 98 99 100 101 102 103 | |
lookup(module_outputs, *, in_graph=None)
¤
Source code in cirkit/backend/torch/parameters/parameter.py
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 | |
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
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
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
177 178 | |
__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
|
Mapping[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[TorchParameterNode] | 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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
extra_repr()
¤
Source code in cirkit/backend/torch/parameters/parameter.py
200 201 | |
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
180 181 182 183 184 185 186 187 188 | |
from_binary(n, p1, p2)
classmethod
¤
Constructs a parameter by using a binary parameter operation node and by specifying its inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
TorchBinaryParameterOp
|
The binary parameter operation node. |
required |
p1
|
Union[TorchParameterInput, TorchParameter]
|
The first parameter input node, or another parameter. |
required |
p2
|
Union[TorchParameterInput, TorchParameter]
|
The second parameter input node, or another parameter. |
required |
Returns:
| Type | Description |
|---|---|
TorchParameter
|
A parameter that encodes the application of the given parameter operation node to the two outputs given by the parameter inputs or parameters. |
Source code in cirkit/backend/torch/parameters/parameter.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
from_input(p)
classmethod
¤
Constructs a parameter from a leaf symbolic node only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
TorchParameterInput
|
The parameter input. |
required |
Returns:
| Type | Description |
|---|---|
TorchParameter
|
A parameter containing only the given parameter input. |
Source code in cirkit/backend/torch/parameters/parameter.py
203 204 205 206 207 208 209 210 211 212 213 | |
from_nary(n, *ps)
classmethod
¤
Constructs a parameter by using a parameter operation node and by specifying its inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
TorchParameterOp
|
The parameter operation node. |
required |
*ps
|
Union[TorchParameterInput, TorchParameter]
|
A sequence of parameter input nodes or parameters. |
()
|
Returns:
| Type | Description |
|---|---|
TorchParameter
|
A parameter that encodes the application of the given parameter operation node to the outputs given by the parameter input nodes or parameters. |
Source code in cirkit/backend/torch/parameters/parameter.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
from_sequence(p, *ns)
classmethod
¤
Constructs a parameter from a composition of parameter nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Union[TorchParameterInput, TorchParameter]
|
The entry point of the sequence, which can be either a parameter input or another parameter. |
required |
*ns
|
TorchParameterOp
|
A sequence of parameter nodes. |
()
|
Returns:
| Type | Description |
|---|---|
TorchParameter
|
A parameter that encodes the composition of the parameter nodes, starting from the given entry point of the sequence. |
Source code in cirkit/backend/torch/parameters/parameter.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
from_unary(n, p)
classmethod
¤
Constructs a parameter by using a unary parameter operation node and by specifying its inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
TorchUnaryParameterOp
|
The unary parameter operation node. |
required |
p
|
Union[TorchParameterInput, TorchParameter]
|
The parameter input node, or another parameter. |
required |
Returns:
| Type | Description |
|---|---|
TorchParameter
|
A parameter that encodes the application of the given parameter operation node to the output given by the parameter input node or parameter. |
Source code in cirkit/backend/torch/parameters/parameter.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
reset_parameters()
¤
Reset the parameters of the parameter computational graph.
Source code in cirkit/backend/torch/parameters/parameter.py
172 173 174 175 | |