MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / lazy_init_hook

Function lazy_init_hook

python/paddle/distributed/auto_parallel/api.py:339–361  ·  view source on GitHub ↗
(param, origin_hook)

Source from the content-addressed store, hash-verified

337 if isinstance(data, EagerParamBase):
338
339 def lazy_init_hook(param, origin_hook):
340 for placement in param.placements:
341 assert not placement.is_partial(), (
342 "Lazy init not support partial reshard. Notice that: shard a param to partial "
343 "won't save any memory, but will increase the communication cost!"
344 )
345
346 # lazy init hook with randomness controlling
347 def _init_func(var, block):
348 if dist.get_rank() not in param.process_mesh.process_ids:
349 # None calc rank, just return no init.
350 return
351 # get the unique rng name
352 rng_name = determinate_rng(
353 dist.get_rank(),
354 process_mesh=param.process_mesh,
355 placements=param.placements,
356 )
357 # real call the init function
358 with rng_state(rng_name):
359 origin_hook(var, block)
360
361 return _init_func
362
363 dist_param = EagerParamBase.from_tensor(
364 tensor,

Callers 1

shard_tensorFunction · 0.85

Calls 1

is_partialMethod · 0.45

Tested by

no test coverage detected