Skip to content

Commit 8fae8cc

Browse files
generatedunixname499836121facebook-github-bot
authored andcommitted
add APIs to determine a class is a namedtuple or PyStructSequence (#113257)
Summary: Changes in this PR: 1. Add `is_structseq` and `is_structseq_class` functions to determine a object or a class is PyStructSequence. 2. Add a generic class `structseq` which can be used as the registration key for PyStructSequence types like `namedtuple` for Named Tuple types. 3. Change `is_namedtuple` to accept subclasses of namedtuple to be namedtuple. Before this PR, only namedtuple class directly created by `collections.namedtuple` or `typing.NamedTuple` were namedtuple classes while their subclasses were not. This PR makes `is_namedtuple` return true for subclasses of namedtuple class. Resolves #75982. New tests are included in this PR. - #75982 X-link: pytorch/pytorch#113257 Approved by: https://github.com/zou3519 Reviewed By: clee2000 Differential Revision: D72251158 fbshipit-source-id: cd57a40c0507ff7cb21fc42f42d42edf95379eef
1 parent 40a841b commit 8fae8cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

userbenchmark/dynamo/dynamobench/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ def load(cls, model, example_inputs):
13971397
# see https://github.com/pytorch/pytorch/issues/113029
13981398
example_outputs = copy.deepcopy(model)(*example_args, **example_kwargs)
13991399

1400-
if pytree._is_namedtuple_instance(example_outputs):
1400+
if pytree.is_namedtuple_instance(example_outputs):
14011401
typ = type(example_outputs)
14021402
pytree._register_namedtuple(
14031403
typ,

0 commit comments

Comments
 (0)