8000 Support namedtuple and dataclass by oulgen · Pull Request #41 · pytorch-labs/helion · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support namedtuple and dataclass #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: gh/oulgen/4/base
Choose a base branch
from

Conversation

oulgen
Copy link
Contributor
@oulgen oulgen commented May 14, 2025

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 14, 2025
oulgen added a commit that referenced this pull request May 14, 2025
ghstack-source-id: 6adba55
Pull Request resolved: #41
oulgen added a commit that referenced this pull request May 14, 2025
ghstack-source-id: fa11c39
Pull Request resolved: #41
oulgen added a commit that referenced this pull request May 14, 2025
ghstack-source-id: 6532b21
Pull Request resolved: #41
@oulgen oulgen requested review from jansel and yf225 May 14, 2025 19:13
@oulgen oulgen marked this pull request as ready for review May 14, 2025 19:13
Comment on lines +142 to +147
type_: type[object] | str = type(obj)
if isinstance(obj, tuple) and hasattr(obj, "_fields"):
# this is a namedtuple
type_ = "namedtuple"
elif dataclasses.is_dataclass(obj):
type_ = "dataclass"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's put this in the except block so the common case is faster.

@@ -462,6 +469,12 @@ def _sequence_key(fn: Kernel, obj: Sequence) -> Hashable:
return type(obj), tuple([fn._specialization_key(item) for item in obj])


def _mapping_key(fn: Kernel, obj: dict[str | int, object]) -> Hashable:
return type(obj), tuple(
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't type(obj) always be dict? I think we need the original type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0