[Compilation Cache] Add API to query number of cached computation graphs#8822
Merged
[Compilation Cache] Add API to query number of cached computation graphs#8822
Conversation
yaochengji
reviewed
Mar 12, 2025
Collaborator
Author
|
Merging it now, the failed gpu ci is not related and will be fixed in #8825. |
pgmoka
reviewed
Mar 12, 2025
Comment on lines
+42
to
+51
| input1 = torch.rand(input_shape).to(xla_dev) | ||
| xm.mark_step() | ||
| model(input1) | ||
| xm.mark_step() | ||
| xm.wait_device_ops() | ||
| graph_cnt = xr.get_num_cached_compilation_graph() | ||
| input2 = torch.rand(input_shape).to(xla_dev) | ||
| model(input2) | ||
| xm.mark_step() | ||
| xm.wait_device_ops() |
Collaborator
There was a problem hiding this comment.
It might be nice to add a/some comments here to explain what is happening in each mark_step
Collaborator
|
lgtm |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add an API
torch_xla.runtime.get_num_cached_compilation_graphto query number of cached computation graphs.This is useful to check if recompilation is happening in application code, or for debugging purposes.
Behavior of when persistent cache is enabled:
When persistent cache is used, returns the number of in-memory cached compilation graph hash. When there is a look up in the persistent cache, it will look up the in-memory cache first, and if it is not found, it will look up the on-disk cache. If there is a cache hit in the on-disk cache, the compilation graph will be fetched into the in-memory cache.
Test:
Test {dynamo, non-dynamo} x {in memory cache, persistent cache} cases