Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
ccd67e86
Commit
ccd67e86
authored
Sep 21, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PeakMemoryTracker as a callback.
parent
3dcd7d32
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
tensorpack/callbacks/prof.py
tensorpack/callbacks/prof.py
+31
-1
No files found.
tensorpack/callbacks/prof.py
View file @
ccd67e86
...
...
@@ -16,7 +16,7 @@ from ..utils import logger
from
..utils.concurrency
import
ensure_proc_terminate
,
subproc_call
from
..utils.gpu
import
get_nr_gpu
__all__
=
[
'GPUUtilizationTracker'
,
'GraphProfiler'
]
__all__
=
[
'GPUUtilizationTracker'
,
'GraphProfiler'
,
'PeakMemoryTracker'
]
class
GPUUtilizationTracker
(
Callback
):
...
...
@@ -164,3 +164,33 @@ class GraphProfiler(Callback):
evt
.
tagged_run_metadata
.
tag
=
'trace-{}'
.
format
(
self
.
global_step
)
evt
.
tagged_run_metadata
.
run_metadata
=
metadata
.
SerializeToString
()
self
.
trainer
.
monitors
.
put_event
(
evt
)
class
PeakMemoryTracker
(
Callback
):
"""
Track peak memory in each session run, by
:module:`tf.contrib.memory_stats`.
It can only be used for GPUs.
"""
def
__init__
(
self
,
devices
=
[
'/gpu:0'
]):
"""
Args:
devices([str]): list of devices to track memory on.
"""
self
.
_devices
=
devices
def
_setup_graph
(
self
):
from
tensorflow.contrib.memory_stats
import
MaxBytesInUse
ops
=
[]
for
dev
in
self
.
_devices
:
with
tf
.
device
(
dev
):
ops
.
append
(
MaxBytesInUse
())
self
.
_fetches
=
tf
.
train
.
SessionRunArgs
(
fetches
=
ops
)
def
_before_run
(
self
,
_
):
return
self
.
_fetches
def
_after_run
(
self
,
_
,
rv
):
results
=
rv
.
results
for
mem
,
dev
in
zip
(
results
,
self
.
_devices
):
self
.
trainer
.
monitors
.
put_scalar
(
'PeakMemory(MB)'
+
dev
,
mem
/
1e6
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment