-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c2295c
commit b042ac3
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
import lightning | ||
from lightning.pytorch.callbacks import Callback | ||
from nequip.data import AtomicDataDict | ||
from nequip.train import NequIPLightningModule | ||
|
||
class Profiler(Callback): | ||
"""Proxy class for `TensorBoard Profiler <https://pytorch.org/tutorials/intermediate/tensorboard_profiler_tutorial.html>`_. | ||
Example usage in config: | ||
:: | ||
trainer: | ||
... | ||
callbacks: | ||
- _target_: nequip.train.callbacks.Profiler | ||
trace_output: "./proflog" | ||
Args: | ||
trace_output (str): directory where profile data is stored | ||
""" | ||
|
||
def __init__(self, trace_output='proflog'): | ||
super().__init__() | ||
self.prof = torch.profiler.profile( | ||
schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=1), | ||
on_trace_ready=torch.profiler.tensorboard_trace_handler(trace_output), | ||
record_shapes=True, | ||
profile_memory=True, | ||
with_stack=True | ||
) | ||
|
||
def on_train_start(self, trainer, pl_module): | ||
self.prof.start() | ||
def on_train_end(self, trainer, pl_module): | ||
self.prof.stop() | ||
def on_train_batch_start( | ||
self, | ||
trainer: lightning.Trainer, | ||
pl_module: NequIPLightningModule, | ||
batch: AtomicDataDict.Type, | ||
batch_idx: int, | ||
): | ||
"""""" | ||
self.prof.step() |