MCPcopy Create free account
hub / github.com/pytorch/executorch / _maybe_get_attr_value

Method _maybe_get_attr_value

exir/graph.py:59–80  ·  view source on GitHub ↗
(
            mod: torch.nn.Module, qualified_name: str
        )

Source from the content-addressed store, hash-verified

57 # Gets the actual value of the attribute if it exists so that we can use
58 # it to set the 'spec' metadata
59 def _maybe_get_attr_value(
60 mod: torch.nn.Module, qualified_name: str
61 ) -> Optional[torch.Tensor]:
62 module_path, _, name = qualified_name.rpartition(".")
63
64 try:
65 submod: torch.nn.Module = mod.get_submodule(module_path)
66 except AttributeError:
67 warnings.warn(f"Failed to fetch module {module_path}!", stacklevel=1)
68 return None
69
70 # See if the value is a buffer
71 if name in submod._buffers:
72 return submod._buffers[name]
73
74 # See if the value is a parameter
75 if hasattr(submod, name):
76 attr = getattr(submod, name)
77 if isinstance(attr, torch.nn.Parameter):
78 return attr
79
80 return None
81
82 buffer = _maybe_get_attr_value(self.owning_module, qualified_name)
83 if buffer is not None:

Callers

nothing calls this directly

Calls 1

get_submoduleMethod · 0.80

Tested by

no test coverage detected