Pytorch-Memory-Utils
Pytorch-Memory-Utils copied to clipboard
'__file__' is incompatible with interactive python
When executing MemTracker(frame) in ipython, it throws KeyError:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-8-fcbd53b39126> in <module>
----> 1 gpu_tracker = MemTracker(frame)
./gpu_mem_track.py in __init__(self, frame, detail, path, verbose, device)
27
28 self.func_name = frame.f_code.co_name
---> 29 self.filename = frame.f_globals["__file__"]
30 if (self.filename.endswith(".pyc") or
31 self.filename.endswith(".pyo")):
KeyError: '__file__'
It seems that the member variable filename is never used. These lines could be safely removed.
https://github.com/Oldpan/Pytorch-Memory-Utils/blob/ee19a7b6545298f8a850e81514b6f28f4bf2c4ba/gpu_mem_track.py#L29-L32
Sorry for that. I didn't think about ipython condition.I only used it in normal python program. Maybe you can fix it or fork this project to finish on you own. Or maybe I'll find a appropriate time to prefect this project~