X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=pysvrt.git;a=blobdiff_plain;f=svrtset.py;h=54c4dec2efd560810be6ea9e76a5b60c82b162c7;hp=0a14121c9a838fb15db18e5b3f114dad2f695e60;hb=HEAD;hpb=a4820693a16a173fd21b8a7580342fe0ad9e8af8 diff --git a/svrtset.py b/svrtset.py index 0a14121..54c4dec 100755 --- a/svrtset.py +++ b/svrtset.py @@ -111,11 +111,21 @@ class CompressedVignetteSet: acc = 0.0 acc_sq = 0.0 + usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss for b in range(0, self.nb_batches): target = torch.LongTensor(self.batch_size).bernoulli_(0.5) input = svrt.generate_vignettes(problem_number, target) - acc += input.sum() / input.numel() - acc_sq += (input * input).sum() / input.numel() + + # FIXME input_as_float should not be necessary but there + # are weird memory leaks going on, which do not seem to be + # my fault + if b == 0: + input_as_float = input.float() + else: + input_as_float.copy_(input) + acc += input_as_float.sum() / input.numel() + acc_sq += input_as_float.pow(2).sum() / input.numel() + self.targets.append(target) self.input_storages.append(svrt.compress(input.storage())) if logger is not None: logger(self.nb_batches * self.batch_size, b * self.batch_size) @@ -125,6 +135,10 @@ class CompressedVignetteSet: print('Memory leak?!') raise + mem = (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss - usage) * 1024 + print('Using {:.02f}Gb total {:.02f}b / samples' + .format(mem / (1024 * 1024 * 1024), mem / self.nb_samples)) + self.mean = acc / self.nb_batches self.std = sqrt(acc_sq / self.nb_batches - self.mean * self.mean)