MCPcopy Create free account
hub / github.com/modelscope/modelscope / is_parallel

Function is_parallel

modelscope/trainers/parallel/utils.py:5–23  ·  view source on GitHub ↗

Check if a module is wrapped by parallel object. The following modules are regarded as parallel object: - torch.nn.parallel.DataParallel - torch.nn.parallel.distributed.DistributedDataParallel You may add you own parallel object by registering it to `modelscope.parallel.PARALLEL`.

(module)

Source from the content-addressed store, hash-verified

3
4
5def is_parallel(module):
6 """Check if a module is wrapped by parallel object.
7
8 The following modules are regarded as parallel object:
9 - torch.nn.parallel.DataParallel
10 - torch.nn.parallel.distributed.DistributedDataParallel
11 You may add you own parallel object by registering it to `modelscope.parallel.PARALLEL`.
12
13 Args:
14 module (nn.Module): The module to be checked.
15
16 Returns:
17 bool: True if the is wrapped by parallel object.
18 """
19 module_wrappers = []
20 for group, module_dict in PARALLEL.modules.items():
21 module_wrappers.extend(list(module_dict.values()))
22
23 return isinstance(module, tuple(module_wrappers))

Callers 2

train_stepMethod · 0.90
place_modelMethod · 0.85

Calls 2

itemsMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…