parameters
parameters
¤
DEFAULT_PARAMETER_OPT_RULES = {LogSoftmaxPattern: apply_log_softmax, ReduceSumOuterProductPattern: apply_sum_outer_prod_einsum}
module-attribute
¤
KroneckerOutParameterPattern
¤
Bases: ParameterOptPatternDefn
This pattern detects Kronecker parameter which are output of the graph.
It is used when performing the tensor dot trick on sum or dot layers that have weights coming from such node.
Source code in cirkit/backend/torch/optimization/parameters.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
entries()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
40 41 42 | |
is_output()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
36 37 38 | |
LogSoftmaxPattern
¤
Bases: ParameterOptPatternDefn
Detect a sequence of Softmax node -> Log node
Source code in cirkit/backend/torch/optimization/parameters.py
45 46 47 48 49 50 51 52 53 54 | |
entries()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
52 53 54 | |
is_output()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
48 49 50 | |
ReduceSumOuterProductPattern
¤
Bases: ParameterOptPatternDefn
Source code in cirkit/backend/torch/optimization/parameters.py
57 58 59 60 61 62 63 64 | |
entries()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
62 63 64 | |
is_output()
classmethod
¤
Source code in cirkit/backend/torch/optimization/parameters.py
58 59 60 | |
apply_log_softmax(compiler, match)
¤
Fuse the log and softmax in one logsoftmax node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiler
|
TorchCompiler
|
The current compiler. |
required |
match
|
ParameterOptMatch
|
The match object containing the modules to optimize. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TorchLogSoftmaxParameter]
|
tuple[TorchLogSoftmaxParameter]: the corresponding logsoftmax node. |
Source code in cirkit/backend/torch/optimization/parameters.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
apply_sum_outer_prod_einsum(compiler, match)
¤
Transform the sum on an outer product into a single einsum to reduce memory usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiler
|
TorchCompiler
|
Current torch compiler. |
required |
match
|
ParameterOptMatch
|
Match containing the module to fuse. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TorchEinsumParameter] | tuple[TorchEinsumParameter, TorchFlattenParameter]
|
tuple[TorchEinsumParameter] | tuple[TorchEinsumParameter,TorchFlattenParameter]: returns the einsum corresponding to the matched modules. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The function is not implemented for more than 4 dimensions. |
Source code in cirkit/backend/torch/optimization/parameters.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |