improve memory consumption by clearing cache + move image to cpu (#412)

* reduced mem on train; figuring out memory leak on visualizer

* steadily below 10G memory

* cpu loading image

* update docstrings

* added scrolling

* Revert "update docstrings"

This reverts commit a914387cf8.

* Revert "Revert "update docstrings""

This reverts commit 177c3dd6f1.

* Revert "added scrolling"

This reverts commit f37351ee7f.
This commit is contained in:
evonneng authored and GitHub committed 2022-09-12 23:00:44 -07:00
1 parent 54f7affe02
commit 4801a99b2a
11 files changed
+22 -12

No files matched your search

+8 -3
View File
@@ -19,20 +19,25 @@ Miscellaneous helper code.
import hashlib
import json
from math import floor, log
from typing import Any, Callable, Dict, Union
from typing import Any, Callable, Dict, List, Optional, Union
import torch
def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu"):
def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu", exclude: Optional[List[str]] = None):
"""Set everything in the dict to the specified torch device.
Args:
stuff: things to convert to torch
device: machine to put the "stuff" on
exclude: list of keys to skip over transferring to device
"""
if isinstance(stuff, dict):
for k, v in stuff.items():
stuff[k] = get_dict_to_torch(v, device)
if exclude and k in exclude:
stuff[k] = v
else:
stuff[k] = get_dict_to_torch(v, device)
return stuff
if isinstance(stuff, torch.Tensor):
return stuff.to(device)