Repository navigation
Mirror the registered pytree flatten when building automatic dynamic shapes - #48578
Conversation
…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 <[email protected]>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
tested locally over all models, it doesn't change much here because model outputs are never passed as inputs during export. |
CI recapDashboard: View test results in Grafana |
zucchini-nlp
left a comment
There was a problem hiding this comment.
Thanks, it works with the other PR that added ModeOutput in generate. Can you just double-check that changes in test_export are expected?
| "GroundingDinoForObjectDetection": "Same `timeout` failure as `Mask2FormerModel`.", | ||
| "MMGroundingDinoModel": "Same `timeout` failure as `Mask2FormerModel`.", | ||
| "MMGroundingDinoForObjectDetection": "Same `timeout` failure as `Mask2FormerModel`.", | ||
| "Sam2VisionModel": "Same `timeout` failure as `Mask2FormerModel`.", |
There was a problem hiding this comment.
no timeout anymore, or was the real issue in ModelOutput?
There was a problem hiding this comment.
we skip sam2 altogether (see above it), when testing locally i found that torch 2.13+ broke it
…shapes (huggingface#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 <[email protected]> * skip --------- Co-authored-by: Claude Opus 5 <[email protected]>
What does this PR do?
get_auto_dynamic_shapestreated every object with a__dict__as flattening to a flat list of tensors, which is true only for theCachesubclasses the exporter registers itself. AModelOutputis registered by transformers with the standard dict-like flatten, sotorch.exportexpects one child per field -- and a field holding a tuple keeps that tuple in the tree spec.Passing a
ModelOutputas a generate kwarg therefore failed withNode 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.Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. These often are low-quality, or fix extremely minor issues that occur rarely or never in practice.
As a result, we're instituting a rule that first-time contributors should not use code agents to submit PRs or issues.
We'd also ask autonomous "OpenClaw"-like agents not to open any PRs or issues.
Issues/PRs from first-time contributors that violate this rule will probably just be closed without review, and we
might block you, especially if you open more than one or appear to be deliberately ignoring this. We especially do not
want new contributors to jump in on random issues to contribute an agent-written fix. This creates lots of noise
for reviewers and other users and will almost certainly get you blocked.
For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request checks?
to it if that's the case.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.