Beispiel #1
0
    def test_tensorboard_trace_handler(self):
        use_cuda = torch.profiler.ProfilerActivity.CUDA in supported_activities(
        )
        with _profile(use_cuda=use_cuda, use_kineto=True):
            self.payload(use_cuda=use_cuda)

        with TemporaryDirectoryName() as dname:
            with profile(
                    activities=[torch.profiler.ProfilerActivity.CPU] +
                ([torch.profiler.ProfilerActivity.CUDA] if use_cuda else []),
                    schedule=torch.profiler.schedule(wait=1,
                                                     warmup=1,
                                                     active=2,
                                                     repeat=3),
                    on_trace_ready=torch.profiler.tensorboard_trace_handler(
                        dname)) as p:
                for _ in range(18):
                    self.payload(use_cuda=use_cuda)
                    p.step()

            self.assertTrue(os.path.exists(dname))
            file_num = 0
            for file_name in os.listdir(dname):
                parts = file_name.split('.')
                self.assertTrue(len(parts) > 4)
                self.assertTrue(parts[-4].isdigit() and int(parts[-4]) > 0,
                                "Wrong tracing file name pattern")
                self.assertEqual(parts[-3:], ['pt', 'trace', 'json'])
                file_num += 1
            self.assertEqual(file_num, 3)

        # test case for gzip file format
        with TemporaryDirectoryName() as dname:
            p = profile(
                activities=[torch.profiler.ProfilerActivity.CPU] +
                ([torch.profiler.ProfilerActivity.CUDA] if use_cuda else []),
                schedule=torch.profiler.schedule(wait=1,
                                                 warmup=1,
                                                 active=2,
                                                 repeat=3),
                on_trace_ready=torch.profiler.tensorboard_trace_handler(
                    dname, use_gzip=True))
            p.start()
            for _ in range(18):
                self.payload(use_cuda=use_cuda)
                p.step()
            p.stop()

            self.assertTrue(os.path.exists(dname))
            file_num = 0
            for file_name in os.listdir(dname):
                parts = file_name.split('.')
                self.assertTrue(len(parts) > 4)
                self.assertTrue(parts[-5].isdigit() and int(parts[-5]) > 0,
                                "Wrong tracing file name pattern")
                self.assertEqual(parts[-4:], ['pt', 'trace', 'json', 'gz'])
                file_num += 1
            self.assertEqual(file_num, 3)
Beispiel #2
0
    def test_tensorboard_trace_handler(self):
        with _profile(use_cuda=True, use_kineto=True):
            self.payload()

        with TemporaryDirectoryName() as dname:
            with profile(
                    activities=[
                        torch.profiler.ProfilerActivity.CPU,
                        torch.profiler.ProfilerActivity.CUDA
                    ],
                    schedule=torch.profiler.schedule(wait=1,
                                                     warmup=1,
                                                     active=2,
                                                     repeat=3),
                    on_trace_ready=torch.profiler.tensorboard_trace_handler(
                        dname)) as p:
                for _ in range(18):
                    self.payload()
                    p.step()

            self.assertTrue(os.path.exists(dname))
            file_num = 0
            for file_name in os.listdir(dname):
                parts = file_name.split('.')
                self.assertTrue(len(parts) > 4)
                self.assertTrue(parts[-4].isdigit() and int(parts[-4]) > 0,
                                "Wrong tracing file name pattern")
                self.assertEqual(parts[-3:], ['pt', 'trace', 'json'])
                file_num += 1
            self.assertEqual(file_num, 3)
Beispiel #3
0
 def test_abs_cpu_unicode_temp_dir(self):
     with TemporaryDirectoryName(suffix='中文') as dname:
         shell_env = os.environ.copy()
         shell_env['TMP'] = dname
         cmd = [sys.executable, os.path.basename(__file__), type(self).__name__ + '.test_abs_cpu']
         legacy_jit_flag = '--jit_executor=legacy'
         for v in sys.argv:
             if v == legacy_jit_flag:
                 cmd.append(legacy_jit_flag)
         return_code = shell(cmd, cwd=os.path.dirname(__file__), env=shell_env)
         self.assertEqual(return_code, 0)