What is Dominator pattern in dataflow_pattern?

What is usage of Dominator? in what of scenarios should we use it? In the documentation there is only one sentence saying

Syntatic sugar for creating an Dominator pattern

https://tvm.apache.org/docs/reference/api/python/relay/dataflow_pattern.html#tvm.relay.dataflow_pattern.dominates

and after searching the codebase, I only found one usage of the API

maybe you could see testcast test_quadruple_rewrite_dominator the ir after domiiniates and rewrite

def @main(%input, %weight) {
  %0 = nn.conv2d(%input, %weight, padding=[0, 0, 0, 0]);
  %1 = nn.relu(%0);
  %2 = nn.relu(%1);
  %3 = nn.leaky_relu(%0, alpha=0f);
  %4 = add(%2, %3);
  %5 = nn.conv2d(%4, %weight, padding=[0, 0, 0, 0]);
  %6 = nn.relu(%5);
  %7 = nn.relu(%6);
  %8 = tanh(%7);
  %9 = nn.leaky_relu(%5, alpha=0f);
  %10 = add(%8, %9);
  %11 = nn.conv2d(%10, %weight, padding=[0, 0, 0, 0]);
  %12 = nn.relu(%11);
  %13 = nn.relu(%12);
  %14 = tanh(%13);
  %15 = add(%13, %14);
  %16 = nn.conv2d(%15, %weight, padding=[0, 0, 0, 0]);
  %17 = nn.relu(%16);
  %18 = add(%17, %17);
  %19 = tanh(%18);
  %20 = nn.leaky_relu(%16, alpha=0f);
  add(%19, %20)
}

def @main(%input, %weight) {
  %0 = nn.conv2d(%input, %weight, padding=[0, 0, 0, 0]);
  %1 = nn.conv2d(%0, %weight, padding=[0, 0, 0, 0]);
  %2 = nn.conv2d(%1, %weight, padding=[0, 0, 0, 0]);
  nn.conv2d(%2, %weight, padding=[0, 0, 0, 0])
}

It seem like the dominates pattern only care start, intermidie, and child(end). no matter how many ops in the middle. then it will match out ops.

1 Like