[Pattern Language] Matching a tuple with variable size

Is it possible to match a tuple which has a variable number of tensors in it, something like

tensors = is_tuple((<any_number_of_tensors>))

other than using tensors = wildcard() ?

@mbrookhart perhaps you might know the answer to this?

Is this what you’re looking for? https://tvm.apache.org/docs/langref/relay_pattern.html#matching-non-call-nodes

I’ve looked at that guide, but I haven’t spotted an example where a tuple is matched simply for being a tuple, regardless of what it contains. So

tensors = is_tuple((wildcard(), wildcard()))

matches only tuples with exactly two things in it, but it would be cool to have a way of matching a tuple with any number of things in it (thinking about concat here which can have an arbitrary number of input tensors).

This was requested here:TuplePattern for any number of inputs to the tuple

I did some prototyping on it, but never got it fully in place (it kind of demands doing the same thing on call args and function args)

This week is kind of chaotic, if someone wants to take that and make a PR I’m happy to review, otherwise I’ll block of some time on Friday to work on it.

2 Likes

Thank you, @mbrookhart! It’s not a blocking issue for us at the moment, but it would be a useful feature.

Also managed to fix partitioning Functions with fuzzy bodies :smiley: Skipping that test has been bothering me for a while.

2 Likes