Mirror the registered pytree flatten when building automatic dynamic shapes (#48578)
* Mirror the registered pytree flatten when building automatic dynamic shapes
`get_auto_dynamic_shapes` treated every object with a `__dict__` as flattening to a
flat list of tensors, which is true only for the `Cache` subclasses the exporter
registers itself. A `ModelOutput` is registered by transformers with the standard
dict-like flatten, so `torch.export` expects one child per field -- and a field
holding a tuple keeps that tuple in the tree spec.
Passing a `ModelOutput` as a generate kwarg therefore failed with `Node arity
mismatch; expected 2, but got 3`. Ask the pytree registry for the flatten instead
of assuming one: caches still yield a flat list, outputs keep their nesting.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* skip
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>