final fixups to memory_cache

- fixed backwards calculation of minimum available memory
- only execute m.padding adjustment code once upon load
This commit is contained in:
Lincoln Stein 2022-10-12 15:56:06 -04:00
parent aa6aa68753
commit 1c102c71fc
2 changed files with 5 additions and 6 deletions

View File

@ -679,11 +679,6 @@ class Generate:
)
self._set_sampler()
for m in self.model.modules():
if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d)):
m._orig_padding_mode = m.padding_mode
self.model_name = model_name
return self.model

View File

@ -122,7 +122,7 @@ class ModelCache(object):
def _check_memory(self):
avail_memory = psutil.virtual_memory()[1]
if avail_memory + AVG_MODEL_SIZE < self.min_avail_mem:
if AVG_MODEL_SIZE + self.min_avail_mem > avail_memory:
least_recent_model = self._pop_oldest_model()
if least_recent_model is not None:
del self.models[least_recent_model]
@ -172,6 +172,10 @@ class ModelCache(object):
model.cond_stage_model.device = self.device
model.eval()
for m in model.modules():
if isinstance(m, (torch.nn.Conv2d, torch.nn.ConvTranspose2d)):
m._orig_padding_mode = m.padding_mode
# usage statistics
toc = time.time()
print(f'>> Model loaded in', '%4.2fs' % (toc - tic))