Add selection mechanism in graph
-
Review changes -
-
Download -
Patches
-
Plain diff
The main feature of this MR is to introduce the Select
operator, allowing conditionnal graph execution.
The condition can be data dependent, yet the graph scheduling remains fully static!
As per Aidge's philosophy, sub-graph hierarchy is an optional feature, not a mandatory workaround, contrary to ONNX's If
operator or PyTorch torch.cond
method. The Select
operator has the following advantages over them:
- Allow interleaved and hierarchical conditions;
- Allow pre-execution of conditional branches or not.
Two scheduling behaviors are possible, depending on wether Scheduler::tagConditionalNodes()
was called or not:
- Without tag: the graph is scheduled and run as is, meaning every conditional branch is run before selection. Of course, this may lead to lots of unnecessary computation. However, branches can be run in parallel, as well as in parallel with the condition determination path;
- With tags: only the selected conditional branch is run. To achieve this, the condition determination path has to be scheduled and run entirely before any conditional branch.
This MR adds the following:
- Operator
Mod
(modulus), conformant to ONNX; - Operator
CryptoHash
, for computing SHA256 (using OpenSSL, now an optional dependency toaidge_backend_cpu
); - Operator
Select
, which selects one of its inputs; - The
Scheduler::tagConditionalNodes()
method that tags nodes with their conditions in theschedule.cond
attribute; - Adaptation of the Scheduler to take into account the
schedule.cond
nodes tag; - Addition of
analysis/
sub-folder with theStaticAnalysis
andOperatorStats
now in separate source files; - Addition of
DynamicAnalysis
class that has the same functions asStaticAnalysis
but on the scheduled graph. TheDynamicAnalysis
will therefore report stats for the actual graph execution, which may differ from the static graph if for example some nodes are run multiple time (in recurrent/cyclic graphs) or never run (conditional node); - Add unit tests for
GraphView::replace()
from !281 (closed); -
Registrar
now also displays the list of available keys when a key is not found; - Solves #240 (closed).
Example
In the following example, we implement a conditional graph where the condition depends on the input data.
%%{init: {'flowchart': { 'curve': 'monotoneY'}, 'fontFamily': 'Verdana' } }%%
flowchart TB
Producer_0("input<br/><sub><em>(Producer#0)</em></sub>"):::producerCls_rootCls
CryptoHash_0("hash<br/><sub><em>(CryptoHash#0)</em></sub>")
Mod_0("mod<br/><sub><em>(Mod#0)</em></sub>")
ReLU_0("relu fa:fa-circle-question<br/><sub><em>(ReLU#0)</em></sub>")
Tanh_0("tanh fa:fa-circle-question<br/><sub><em>(Tanh#0)</em></sub>"):::conditionCls
Sqrt_0("sqrt fa:fa-circle-question<br/><sub><em>(Sqrt#0)</em></sub>"):::conditionCls
Select_0("select<br/><sub><em>(Select#0)</em></sub>")
Producer_1(<em>Producer#1</em>):::producerCls
Producer_0-->|"0 [2, 3] Float32<br/>↓<br/>0"|CryptoHash_0
Producer_0-->|"0 [2, 3] Float32<br/>↓<br/>0"|ReLU_0
Producer_0-->|"0 [2, 3] Float32<br/>↓<br/>0"|Tanh_0
Producer_0-->|"0 [2, 3] Float32<br/>↓<br/>0"|Sqrt_0
CryptoHash_0-->|"0 [4] UInt64<br/>↓<br/>0"|Mod_0
Mod_0-->|"0 [4] UInt64<br/>↓<br/>0"|Select_0
ReLU_0-->|"0 [2, 3] Float32<br/>↓<br/>1"|Select_0
Tanh_0-->|"0 [2, 3] Float32<br/>↓<br/>2"|Select_0
Sqrt_0-->|"0 [2, 3] Float32<br/>↓<br/>3"|Select_0
Producer_1-->|"0 [1] UInt64<br/>↓<br/>1"|Mod_0
Select_0--->|"0 [2, 3] Float32<br/>↓"|output0((out#0)):::outputCls
classDef inputCls fill:#afa
classDef outputCls fill:#ffa
classDef externalCls fill:#ccc
classDef producerCls fill:#ccf
classDef genericCls fill:#f9f9ff,stroke-width:1px,stroke-dasharray: 5 5
classDef metaCls stroke-width:5px
classDef rootCls stroke:#f00
classDef producerCls_rootCls stroke:#f00,fill:#ccf
classDef genericCls_rootCls stroke:#f00,fill:#f9f9ff,stroke-width:1px,stroke-dasharray: 5 5
classDef metaCls_rootCls stroke:#f00,stroke-width:5px
TODO later
-
Add support of conditions in node exports;
Edited by Olivier BICHLER
Merge request reports
Compare and
- version 19d365b0d6
- version 1851a9ebe6
- version 173c4e6838
- version 16d1ac46b2
- version 15316bf5ca
- version 14a89e6390
- version 13d453aa1d
- version 127a9b48f4
- version 11aa722795
- version 100cad06ff
- version 9069bb401
- version 80d3d9853
- version 74e336d18
- version 61d180093
- version 541bf7880
- version 4bf739093
- version 319f7e435
- version 2352a7c9b
- version 124193c0c
- dev (base)
- latest versionc5492e2316 commits,
- version 19d365b0d615 commits,
- version 1851a9ebe614 commits,
- version 173c4e683813 commits,
- version 16d1ac46b212 commits,
- version 15316bf5ca11 commits,
- version 14a89e639010 commits,
- version 13d453aa1d9 commits,
- version 127a9b48f48 commits,
- version 11aa7227958 commits,
- version 100cad06ff7 commits,
- version 9069bb4017 commits,
- version 80d3d98537 commits,
- version 74e336d186 commits,
- version 61d1800935 commits,
- version 541bf788021 commits,
- version 4bf73909320 commits,
- version 319f7e43519 commits,
- version 2352a7c9b18 commits,
- version 124193c0c17 commits,
Compare changes
- Side-by-side
- Inline
Files
38Loading