Skip to content

Commit ec7212f

Browse files
authored
Merge pull request #230 from comet-ml/chasefortier-patch-3
Create README.md
2 parents b7e0164 + 02d18cb commit ec7212f

File tree

1 file changed

+101
-0
lines changed
  • panels/TensorboardTorchProfilerViewer

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
### TensorboardProfileViewer
2+
3+
The `TensorboardProfileViewer` panel is used to visualize Tensorboard
4+
Profile data logged data inside a Comet Custom Panel.
5+
6+
7+
<table>
8+
<tr>
9+
<td>
10+
<img src="https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/TensorboardProfileViewer/tensorboard-profile-viewer.png"
11+
style="max-width: 300px; max-height: 300px;">
12+
</img>
13+
</td>
14+
</tr>
15+
</table>
16+
17+
First, run your experiment, including writing and logging the
18+
Tensorboard logdir:
19+
20+
```python
21+
# Use the PyTorch profiler with trace saving
22+
with torch.profiler.profile(
23+
activities=[
24+
torch.profiler.ProfilerActivity.CPU
25+
],
26+
record_shapes=True,
27+
on_trace_ready=torch.profiler.tensorboard_trace_handler("./logdir") # Saves trace
28+
) as prof:
29+
for _ in range(5):
30+
output = model(input)
31+
prof.step() # Important: must call step() in each iteration
32+
33+
34+
#Log the folder to Comet
35+
experiment.log_tensorflow_folder("./logdir")
36+
```
37+
38+
Finally click on "Select Experiment with log:" in this panel.
39+
40+
#### Example
41+
42+
This example logs some dummy data to Tensorflow, and
43+
then logs the Tensorflow folder to Comet.
44+
45+
```python
46+
import comet_ml
47+
import torch
48+
import torch.nn as nn
49+
import torch.profiler
50+
51+
#Start Comet experiment
52+
comet_ml.login()
53+
experiment = comet_ml.start(project_name="tf-profiler")
54+
55+
# Define a simple model
56+
model = nn.Linear(10, 1)
57+
input = torch.randn(1, 10)
58+
59+
# Use the PyTorch profiler with trace saving
60+
with torch.profiler.profile(
61+
activities=[
62+
torch.profiler.ProfilerActivity.CPU
63+
],
64+
record_shapes=True,
65+
on_trace_ready=torch.profiler.tensorboard_trace_handler("./logdir") # Saves trace
66+
) as prof:
67+
for _ in range(5):
68+
output = model(input)
69+
prof.step() # Important: must call step() in each iteration
70+
71+
72+
73+
#Log the folder to Comet
74+
experiment.log_tensorflow_folder("./logdir")
75+
76+
experiment.end()
77+
experiment.end()
78+
```
79+
80+
#### Python Panel
81+
82+
To include this panel from the github repo, use this code in a Custom Python Panel:
83+
84+
```
85+
%include https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/TensorboardTorchProfilerViewer/TensorboardTorchProfilerViewer.py
86+
```
87+
88+
Or, you can simply [copy the code](https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/TensorboardTorchProfilerViewer/TensorboardTorchProfilerViewer.py) into a custom Python Panel.
89+
90+
#### How it works
91+
92+
The Python panel will start a Tensorboard server and make available
93+
the logs from the experiment that is selected.
94+
95+
#### Resources
96+
97+
* [Example Comet Project]([https://www.comet.com/dsblank/tensorboard-profile/](https://www.comet.com/chasefortier/tf-profiler/f156e9c72d9b4e12b8eae4ecf6db43a1?compareXAxis=step&experiment-tab=panels&prevPath=%2Fchasefortier%2Ftf-profiler%2Fview%2Fnew%2Fpanels&showOutliers=true&smoothing=0&xAxis=step))
98+
* Documentation:
99+
* [Logging tensorflow folders](https://www.comet.com/docs/v2/api-and-sdk/python-sdk/reference/Experiment/#comet_ml.Experiment.log_tensorflow_folder)
100+
* [Automatic Tensorboard logging](https://www.comet.com/docs/v2/integrations/third-party-tools/tensorboard/#configure-comet-for-tensorboard)
101+
* [Download tensorboard folders](https://www.comet.com/docs/v2/api-and-sdk/python-sdk/reference/APIExperiment/#comet_ml.APIExperiment.download_tensorflow_folder)

0 commit comments

Comments
 (0)