Timing in Torchscript

Below code is not working in torch.jit.script

    def forward(self, x):
        start = time.time() * 1000
        y = self.compute_conv1d((x))
        print("cost %d ms" % (time.time() * 1000 - start))
        return y

error

RuntimeError: 
Python builtin <built-in function time> is currently not supported in Torchscript:

Since time.time() is not supported in Torchscript, is there any way to measure each module’s cost inside script model? I’m running on a cpu machine.

Thanks

something like

@jit.ignore
def jtime() -> float:
  return time.time()

autograd.profiler.profile + export_chrome_trace is another method

2 Likes

@googlebot thank you! It works!

I am getting the following exception when I call the function suggested by knitvoger’s code:

@jit.ignore
def jtime() -> float:
  return time.time()

ValueError: Unknown type annotation: ‘float’ at