Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sparsity_rate_for_model(self):
nonzero = 0
count = 0
for m in self.model.modules():
if isinstance(m, tuple(COMPRESSION_MODULES.registry_dict.values())):
continue
sparsified_module = False
for minfo in self.sparsified_module_info:
if minfo.module == m:
mask = minfo.operand.apply_binary_mask(m.weight)
nonzero = nonzero + mask.nonzero().size(0)
count = count + mask.numel()
if not m.bias is None:
nonzero = nonzero + m.bias.nonzero().size(0)
count = count + m.bias.numel()
sparsified_module = True
if not sparsified_module: