MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / isinstance_namedtuple

Function isinstance_namedtuple

deepspeed/runtime/zero/parameter_offload.py:25–36  ·  view source on GitHub ↗

Is this an instance of namedtuple/NamedTuple? From: https://stackoverflow.com/a/62692640 Args: obj (object): An object. Returns: bool: True if namedtuple/NamedTuple else False.

(obj: object)

Source from the content-addressed store, hash-verified

23
24
25def isinstance_namedtuple(obj: object) -> bool:
26 """
27 Is this an instance of namedtuple/NamedTuple?
28 From: https://stackoverflow.com/a/62692640
29
30 Args:
31 obj (object): An object.
32
33 Returns:
34 bool: True if namedtuple/NamedTuple else False.
35 """
36 return isinstance(obj, tuple) and hasattr(obj, '_asdict') and hasattr(obj, '_fields')
37
38
39# ensure we only warn once, otherwise every iteration will trigger a warning

Callers 1

_apply_to_tensors_onlyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected