-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function to get the amount of memory used by torch tensors #676
base: master
Are you sure you want to change the base?
Conversation
@@ -250,6 +256,7 @@ static const struct luaL_Reg torch_utils__ [] = { | |||
{"pointer", luaT_lua_pointer}, | |||
{"setheaptracking", torch_setheaptracking}, | |||
{"updateerrorhandlers", torch_updateerrorhandlers}, | |||
{"getmemory", torch_getmemory}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about memoryused
? It might be more self-explanatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that simply getmemory
is not a good name.
memoryused
is indeed better.
Any other opinions ? cutorch
has a getMemoryUsage
(which prints the total memory available and the memory used for the GPU). Maybe it would be good to have some uniformity in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMemoryUsage
sounds good to me as well 😄 I agree that it might be better to keep it similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there is a difference between getMemoryUsage
and this PR in the sense that this PR aims at showing the memory used by torch, and not the total memory used. BTW, the same PR could be done in cutorch
, in which case we would have different functions which behave differently but with a similar purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, ok, you're right. Do you have any suggestions for the name? getTorchMemory[Usage]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.getHeapSize ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds a bit as if it would return Lua's heap size as well, but I like it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.tensormemoryusage_if_youre_not_using_too_many_threads_plusOrMinus100MB()
Also, I could add |
Allows to get the amount of memory used by torch tensors.
In conjunction with
collectgarbage('count')
, we can have some good estimates of the total amount of memory used (except if other data structures are used, liketds
).Note: as
heapSize
is only updated by batches of ~ 1MB, so creating really small tensors won't show any immediate difference.I will add docs if we agree to merge this.