def log_weights_sparsity(self, model, epoch): fname = self.get_fname("weights_sparsity") with open(fname, "w") as csv_file: params_size = 0 sparse_params_size = 0 writer = csv.writer(csv_file) # write the header writer.writerow([ "parameter", "shape", "volume", "sparse volume", "sparsity level" ]) for name, param in model.state_dict().items(): if param.dim() in [2, 4]: _density = density(param) params_size += torch.numel(param) sparse_params_size += param.numel() * _density writer.writerow([ name, size_to_str(param.size()), torch.numel(param), int(_density * param.numel()), (1 - _density) * 100, ])
def log_weights_sparsity(self, model, epoch): with open(self.fname, 'w') as csv_file: params_size = 0 sparse_params_size = 0 writer = csv.writer(csv_file) # write the header writer.writerow([ 'parameter', 'shape', 'volume', 'sparse volume', 'sparsity level' ]) for name, param in model.state_dict().items(): if param.dim() in [2, 4]: _density = density(param) params_size += torch.numel(param) sparse_params_size += param.numel() * _density writer.writerow([ name, size_to_str(param.size()), torch.numel(param), int(_density * param.numel()), (1 - _density) * 100 ])