Depends on your model set up but in general I think this is not easy to do in a static graph, as you can not add or remove node once the graph is compiled.
You can have a look at Dirichlet process mixtures for density estimation doc where the number of component is unknown (but truncated).