-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add profiling of neural networks * Tests * Refactor profiling * Cosmetic changes * Tests * Cosmetic changes * Cosmetic changes * Refactoring profiler * Documentation * Add profiling test
- Loading branch information
Showing
7 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Profiling networks | ||
------------------ | ||
Profiling execution of tensorflow graph can be enabled with following setting: | ||
|
||
.. code-block:: yaml | ||
:caption config.yaml | ||
model: | ||
profile: True | ||
keep_profiles: 10 | ||
This saves profiles of last 10 runs to the log directory (output directory). | ||
Profiles are in JSON format and can be viewed using Google Chrome. | ||
To view them go to address `chrome://tracing/` and load the json file. | ||
|
||
Gradient clipping | ||
----------------- | ||
For gradient clipping use following setting: | ||
|
||
.. code-block:: yaml | ||
:caption config.yaml | ||
model: | ||
clip_gradient: 5.0 | ||
This clips the absolute value of gradient to 5.0. | ||
Note that the clipping is done to raw gradients before they are multiplied by learning rate or processed in other ways. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import tensorflow as tf | ||
from tensorflow.python.client import timeline | ||
from typing import Dict | ||
import os | ||
|
||
|
||
class Profiler: | ||
""" | ||
Profiles tensorflow graphs and saves the profiles. | ||
""" | ||
|
||
def __init__(self, log_dir: str, keep_profiles: int, session: tf.Session): | ||
""" | ||
:param log_dir: directory where profiles will be saved | ||
:param keep_profiles: how many profiles are saved | ||
""" | ||
self._log_dir = log_dir | ||
self._profile_counter = 0 | ||
self._keep_profiles = keep_profiles | ||
self._run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | ||
self._session = session | ||
|
||
def run(self, fetches: Dict, feed_dict: Dict): | ||
""" | ||
Evaluates the tensorflow graph with profiling, saves profile and returns outputs. | ||
:param session: tensorflow session | ||
:param fetches: names of output tensors | ||
:param feed_dict: input tensors | ||
""" | ||
run_metadata = tf.RunMetadata() | ||
outputs = self._session.run(fetches=fetches, feed_dict=feed_dict, | ||
options=self._run_options, run_metadata=run_metadata) | ||
|
||
with open(os.path.join(self._log_dir, f'profile_{self._profile_counter}.json'), 'w') as ofile: | ||
tl = timeline.Timeline(run_metadata.step_stats) | ||
ofile.write(tl.generate_chrome_trace_format()) | ||
|
||
self._profile_counter = (self._profile_counter + 1) % self._keep_profiles | ||
|
||
return outputs |