mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-21 13:20:08 +08:00
* initial implementation * formatting, pass through profiler, docstring * call profiler during training * add initial tests * report stats when training is done * fix formatting * error handling, bugfix in passthroughprofiler * finish documenting profiler arg in Trainer * relax required precision for profiling tests * option to dump cProfiler results to text file * use logging, format with black * include profiler in docs * improved logging and better docs * appease the linter * better summaries, wrapper for iterables * fix typo * allow profiler=True creation * more documentation * add tests for advanced profiler * Update trainer.py * make profilers accessible in pl.utilities * reorg profiler files * change import for profiler tests Co-authored-by: William Falcon <waf2107@columbia.edu>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from pytorch_lightning.profiler import Profiler, AdvancedProfiler
|
|
import time
|
|
import numpy as np
|
|
|
|
|
|
def test_simple_profiler():
|
|
p = Profiler()
|
|
|
|
with p.profile("a"):
|
|
time.sleep(3)
|
|
|
|
with p.profile("a"):
|
|
time.sleep(1)
|
|
|
|
with p.profile("b"):
|
|
time.sleep(2)
|
|
|
|
with p.profile("c"):
|
|
time.sleep(1)
|
|
|
|
# different environments have different precision when it comes to time.sleep()
|
|
np.testing.assert_almost_equal(p.recorded_durations["a"], [3, 1], decimal=1)
|
|
np.testing.assert_almost_equal(p.recorded_durations["b"], [2], decimal=1)
|
|
np.testing.assert_almost_equal(p.recorded_durations["c"], [1], decimal=1)
|
|
|
|
|
|
def test_advanced_profiler():
|
|
def get_duration(profile):
|
|
return sum([x.totaltime for x in profile.getstats()])
|
|
|
|
p = AdvancedProfiler()
|
|
|
|
with p.profile("a"):
|
|
time.sleep(3)
|
|
|
|
with p.profile("a"):
|
|
time.sleep(1)
|
|
|
|
with p.profile("b"):
|
|
time.sleep(2)
|
|
|
|
with p.profile("c"):
|
|
time.sleep(1)
|
|
|
|
a_duration = get_duration(p.profiled_actions["a"])
|
|
np.testing.assert_almost_equal(a_duration, [4], decimal=1)
|
|
b_duration = get_duration(p.profiled_actions["b"])
|
|
np.testing.assert_almost_equal(b_duration, [2], decimal=1)
|
|
c_duration = get_duration(p.profiled_actions["c"])
|
|
np.testing.assert_almost_equal(c_duration, [1], decimal=1)
|