KEMBAR78
Fixes for `collections.NamedTuple` by guilhermeleobas · Pull Request #159367 · pytorch/pytorch · GitHub
Skip to content

Conversation

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Jul 29, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/159367

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 6b959c2 with merge base e299926 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guilhermeleobas guilhermeleobas marked this pull request as ready for review August 1, 2025 14:29
@mlazos
Copy link
Contributor

mlazos commented Aug 2, 2025

test? Especially for the SourcelessBuilder changes

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
return None

if name == "_fields":
return VariableTracker.build(tx, self.fields())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a source for this, or else it will use sourceless builder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually have DataclassFieldsSource all ready for you :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried and it doesn't work. I think I need to implement my own NamedTupleFieldsSource.

[33] > ~/micromamba/envs/pytorch313/lib/python3.13/dataclasses.py(1319)
....
1308     def fields(class_or_instance):
1309         """Return a tuple describing the fields of this dataclass.
1310
1311         Accepts a dataclass or an instance of one. Tuple elements are of
1312         type Field.
1313         """
1314
1315         # Might it be worth caching this, per class?
1316         try:
1317             fields = getattr(class_or_instance, _FIELDS)
1318         except AttributeError:
1319  ->         breakpoint()
1320             raise TypeError('must be called with a dataclass type or instance') from None
1321
1322         # Exclude pseudo-fields.  Note that fields is sorted by insertion
1323         # order, so the order of the tuple is as the fields were defined.
1324         return tuple(f for f in fields.values() if f._field_type is _FIELD)

(Pdb+) class_or_instance
MyTuple(a=tensor([1.]), b=tensor([2.]), ab=tensor([3.]))
(Pdb+) _FIELDS
'__dataclass_fields__'
(Pdb+) getattr(class_or_instance, _FIELDS)
*** AttributeError: 'MyTuple' object has no attribute '__dataclass_fields__'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, yeah I think I was tired and thought these were compatible, implementing your own source will work. You can follow my PR implementing the DataclassFieldsSource if it helps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added. If you could take a look.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guilhermeleobas guilhermeleobas requested a review from mlazos August 15, 2025 20:00
[ghstack-poisoned]
guilhermeleobas added a commit that referenced this pull request Aug 16, 2025
ghstack-source-id: 9028efc
Pull-Request: #159367
@guilhermeleobas
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 18, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

can-gaa-hou pushed a commit to can-gaa-hou/pytorch that referenced this pull request Aug 22, 2025
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
@github-actions github-actions bot deleted the gh/guilhermeleobas/216/head branch September 18, 2025 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants