diff --git a/tensordict/utils.py b/tensordict/utils.py index 0e370856f..f282edd53 100644 --- a/tensordict/utils.py +++ b/tensordict/utils.py @@ -22,7 +22,6 @@ from collections.abc import KeysView from contextlib import nullcontext from copy import copy -from dataclasses import _FIELDS, GenericAlias from functools import wraps from importlib import import_module from numbers import Number @@ -75,6 +74,18 @@ if TYPE_CHECKING: from tensordict.tensordict import TensorDictBase +try: + from dataclasses import _FIELDS, GenericAlias +except ImportError: + # python < 3.9 + from dataclasses import _FIELDS + + class GenericAlias: + """Placeholder.""" + + ... + + try: try: from torch._C._functorch import ( # @manual=fbcode//caffe2:torch