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)
| 3 | |
| 4 | |
| 5 | def 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)) |
no test coverage detected
searching dependent graphs…