-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profiler annotations & tutorial #582
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ecb3fb2
Allocator stats docs
Pangoraw 8b021b0
Add API to create profiler annotations
Pangoraw a5a7a1b
profiling tutorial
Pangoraw 5a400ee
sig cleanup
Pangoraw 23b1e06
vitepress config
Pangoraw 82f6b5a
vitepress config 2
Pangoraw 9e7eb26
note about allocatorstats
Pangoraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Tutorials | ||
|
||
We are currently working on adding tutorials to Reactant!! Please check back soon! | ||
- [Profiling](@ref profiling). | ||
|
||
We are currently working on adding more tutorials to Reactant!! Please check back soon! |
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,84 @@ | ||
# [Profiling](@id profiling) | ||
|
||
## Capturing traces | ||
|
||
When running Reactant, it is possible to capture traces using the [XLA profiler](https://jax.readthedocs.io/en/latest/profiling.html). | ||
These traces can provide information about where the XLA specific parts of program spend time during compilation or execution. | ||
|
||
Let's setup a simple function which we can then profile | ||
|
||
```@example profiling | ||
using Reactant | ||
|
||
x = Reactant.to_rarray(randn(Float32, 100, 2)) | ||
W = Reactant.to_rarray(randn(Float32, 10, 100)) | ||
b = Reactant.to_rarray(randn(Float32, 10)) | ||
|
||
linear(x, W, b) = (W * x) .+ b | ||
``` | ||
|
||
The profiler can be accessed using the [`Reactant.with_profiler`](@ref Reactant.Profiler.with_profiler) function. | ||
|
||
```@example profiling | ||
Reactant.with_profiler("./") do | ||
mylinear = Reactant.@compile linear(x, W, b) | ||
mylinear(x, W, b) | ||
end | ||
``` | ||
|
||
Running this function should create a folder called `plugins` in the folder provided to `Reactant.with_profiler` which will | ||
contain the trace files. The traces can then be visualized in different ways. | ||
|
||
!!! note | ||
For more insights about the current state of Reactant, it is possible to fetch device information about allocations using the [`Reactant.XLA.allocatorstats`](@ref) function. | ||
|
||
## Perfetto UI | ||
|
||
![The perfetto interface](images/perfetto.png) | ||
|
||
The first and easiest way to visualize a captured trace is to use the online [`perfetto.dev`](https://ui.perfetto.dev/) tool. | ||
[`Reactant.with_profiler`](@ref Reactant.Profiler.with_profiler) has a keyword parameter called `create_perfetto_link` which will create a usable perfetto URL for the generated trace. | ||
The function will block execution until the URL has been clicked and the trace is visualized. The URL only works once. | ||
|
||
```julia | ||
Reactant.with_profiler("./"; create_perfetto_link=true) do | ||
mylinear = Reactant.@compile linear(x, W, b) | ||
mylinear(x, W, b) | ||
end | ||
``` | ||
|
||
!!! note | ||
It is recommended to use the Chrome browser to open the perfetto URL. | ||
|
||
## Tensorboard | ||
|
||
![The tensorboard interface](images/tensorboard.png) | ||
|
||
Another option to visualize the generated trace files is to use the [tensorboard profiler plugin](https://www.tensorflow.org/tensorboard/tensorboard_profiling_keras). | ||
The tensorboard viewer can offer more details than the timeline view such as visualization for compute graphs. | ||
|
||
First install tensorboard and its profiler plugin: | ||
|
||
```bash | ||
pip install tensorboard tensorboard-plugin-profile | ||
``` | ||
|
||
And then run the following in the folder where the `plugins` folder was generated: | ||
|
||
```bash | ||
tensorboard --logdir ./ | ||
``` | ||
|
||
## Adding Custom Annotations | ||
|
||
By default, the traces contain only information captured from within XLA. | ||
The [`Reactant.Profiler.annotate`](@ref) function can be used to annotate traces for Julia code evaluated *during tracing*. | ||
|
||
```julia | ||
Reactant.Profiler.annotate("my_annotation") do | ||
# Do things... | ||
end | ||
``` | ||
|
||
The added annotations will be captured in the traces and can be seen in the different viewers along with the default XLA annotations. | ||
When the profiler is not activated, then the custom annotations have no effect and can therefore always be activated. |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these screenshots by us or are they taken from somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by us, those are from the example