@@ -62,3 +62,39 @@ and then inside the loop over batches:
For convenience, you can try these edits by commenting and uncommenting lines in `ipex_example.py` and `run_ipex_example.sh`. Both approaches only run for about two minutes.
## PyTorch Profiler
Measures time and memory consumption of model operators. (Note that this is only for PyTorch functions.)\
- with_stack=True includes the file and line number of operations in the trace, so it adds overhead but could be helpful.
- record_shapes=True might skew the timings, but it collects information about input dimensions
- You could then print a sorted table of timings. (This version of `ipex_example.py` ran for about 6 minutes.) If you later want to explore other ways to sort the table, you could copy it into something like Excel.
- You could also choose to save a Chrome trace. You can view the Chrome trace in the Chrome browser by going to chrome://tracing and loading the trace file.
```
prof.export_chrome_trace("trace_file.json")
```
- In the case of this example, the Chrome trace is 360 MB, which is fine. However, the trace files saved this way are often too large to load. You'll either get an error or it will quietly fail without a trace appearing. (Perhaps one solution would be splitting the JSON file into smaller segments before loading it.)
- You could also add the PyTorch profiler elsewhere in the code in order to save smaller traces. For example, the profiler could be around just one training step (`train_step(data, target, batch_idx)`). If, for your application, the trace is still too big to load in Chrome, you might want to wrap one forward pass (`output = model(data)`) and one backward pass (`loss.backward()`) separately so that two different trace files get saved.
For convenience, you can try these edits by commenting and uncommenting lines in ipex_example.py. Whether I printed the table or saved the Chrome trace, the whole job took about six minutes.
Notes:
- If I used the legacy PyTorch profiler on Sunspot to create a Chrome trace and loaded it in Chrome, I got a JSON parsing error. I fixed it using this: