MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / named_parameters

Method named_parameters

imperative/python/megengine/module/module.py:233–262  ·  view source on GitHub ↗

r"""Returns an iterable for key :class:`~.Parameter` pairs of the module, where ``key`` is the dotted path from this module to the :class:`~.Parameter`. Args: prefix: prefix prepended to the keys. recursive: if ``True``, returns all :class:`~.Parameter` withi

(
        self, prefix: Optional[str] = None, recursive: bool = True, **kwargs
    )

Source from the content-addressed store, hash-verified

231 )
232
233 def named_parameters(
234 self, prefix: Optional[str] = None, recursive: bool = True, **kwargs
235 ) -> Iterable[Tuple[str, Parameter]]:
236 r"""Returns an iterable for key :class:`~.Parameter` pairs of the module, where
237 ``key`` is the dotted path from this module to the :class:`~.Parameter`.
238
239 Args:
240 prefix: prefix prepended to the keys.
241 recursive: if ``True``, returns all :class:`~.Parameter` within this
242 module, else only returns :class:`~.Parameter` that are direct attributes
243 of this module.
244 """
245
246 if "requires_grad" in kwargs:
247 del kwargs["requires_grad"]
248 logger.warning(
249 "Tensor currently has no requires_grad attribute "
250 "so requires_grad argument is ignored here"
251 )
252
253 def predicate(obj) -> bool:
254 return _is_parameter(obj)
255
256 yield from self._flatten(
257 with_key=True,
258 prefix=prefix,
259 predicate=predicate,
260 recursive=recursive,
261 **kwargs,
262 )
263
264 def buffers(self, recursive: bool = True, **kwargs) -> Iterable[Tensor]:
265 r"""Returns an iterable for the buffers of the module.

Callers 2

test_module_apiFunction · 0.80
_check_paramFunction · 0.80

Calls 1

_flattenMethod · 0.95

Tested by 2

test_module_apiFunction · 0.64
_check_paramFunction · 0.64