MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / update

Method update

python/oneflow/nn/utils/container.py:251–277  ·  view source on GitHub ↗
(self, modules: Mapping[str, T])

Source from the content-addressed store, hash-verified

249 return self._modules.values()
250
251 def update(self, modules: Mapping[str, T]) -> None:
252 if not isinstance(modules, collections.abc.Iterable):
253 raise TypeError(
254 "ModuleDict.update should be called with an iterable of key/value pairs, but got "
255 + type(modules).__name__
256 )
257 if isinstance(modules, (OrderedDict, T, collections.abc.Mapping)):
258 for (key, module) in modules.items():
259 self[key] = module
260 else:
261 for (j, m) in enumerate(modules):
262 if not isinstance(m, collections.abc.Iterable):
263 raise TypeError(
264 "ModuleDict update sequence element #"
265 + str(j)
266 + " should be Iterable; is"
267 + type(m).__name__
268 )
269 if not len(m) == 2:
270 raise ValueError(
271 "ModuleDict update sequence element #"
272 + str(j)
273 + " has length "
274 + str(len(m))
275 + "; 2 is required"
276 )
277 self[m[0]] = m[1]
278
279 return DictContainer
280

Callers 8

__init__Method · 0.95
__setstate__Method · 0.45
load_state_dictMethod · 0.45
load_state_dictMethod · 0.45
load_state_dictMethod · 0.45
load_state_dictMethod · 0.45
load_state_dictMethod · 0.45
load_state_dictMethod · 0.45

Calls 2

typeEnum · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected