Skip to content

ONNX cleaner fuseToLayerNorm

This issue track the progress of the support of the function fuseToLayerNorm.

Which would match the following graphs:

layer_norm_torch_vs_keras

And replace them by a LayerNorm operator.

GraphMatching issue

From the GraphMatching side, matching this pattern can be done but there is a flow due to the fact that the input need to be the same.

With current graph matching, if we want to match B and C with B and C having a different input, we would not be able to differenciate between case one and two:

flowchart TD
	subgraph Case two
	A --> B --> C;
	A --> C
	end
	subgraph Case one
	a0["A0"] --> b["B"] --> c["C"];
	a1["A1"] --> c
	end

Indeed to differenciate, we would need to have this kind of pattern .#0->B#1->C#2;.#3->C#2 (case one) or .#0->B#1->C#2;.#0->C#2 (case two). But we don't want to match the extra operators (A, A0, A1)! This is currently not supported. To do so with current impelementation, we need to remove by hand the extra operator.

I will propose a new syntax element to match a pattern but not return it to handle this kind of cases.

Note: issue tracked here: aidge_core#318 (closed)

ONNX export issue

The LayerNorm operator is not just a graph, it is a full operator with attributes! Once the pattern matched, generating the corresponding ONNX nodes is not trivial.

We need to find from the micro-graph the following attributes: axis, epsilon and stash_type (if the two optional outputs are presents!). This is not trivial, specially with a MetaOperator that contains a micro-graph that can have widely different shapes!

Edited by Cyril Moineau