Yep - my guess is that your effort would be better spent trying to get your model into a single graph, rather than figure out a way to hand-stitch the multiple graphs together (which might be doable for your specific use case, but in general is difficult to do in a safe way).
Do you have a runnable repro / can point to the user code that is causing that exception?
Suppose you have code like this:
def f(x):
# y's shape is data-dependent
y = x.nonzero()
# normally this will error, since we don't know statically what y.shape[0] is (data-dependent)
if y.shape[0] > 1:
return y.sin()
else:
return y.cos()
One thing you can try is adding torch._check(y.shape[0] > 1), if you know that for your model, it’s ok to burn in one of the two branches.
If you really need a single graph that can potentially handle both cases, in theory you should be able to do something like this:
return torch.cond(y.shape[0] > 1, true_fn, false_fn)
Although I’m not too sure what the state is of cond() where the condition contains (unbacked) dynamic shapes. It’s probably worth filing a (minimal) repro github issue if you run into problems with it.