fix: store cuda_available variable and extend perf_counter fix to all get_computational_cost functions#553
Open
vinitjain2005 wants to merge 2 commits into
Open
Conversation
1a7c937 to
15c272d
Compare
15c272d to
1bc2e4d
Compare
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.
Summary
This PR extends the timing fix originally proposed in the closed PR to all
get_computational_cost()functions across the library, and also addresses the review comment to storetorch.cuda.is_available()in a variable instead of calling it on every loop iteration.Closes #453
Problem
The
get_computational_cost()functions across multiple files had two issues:torch.cuda.synchronize()was called unconditionally on every iteration — it is a no-op on CPU and was designed only for CUDA devicestime.time()was used for timing — it has low resolution on Windows (15ms granularity) causing timing to show 0ms or jump in 15ms chunkstorch.cuda.is_available()was being called on every loop iteration instead of being stored once as a variableFix
Files Changed
perceptionmetrics/models/torch_detection.pyget_computational_cost()functionperceptionmetrics/models/torch_segmentation.pyTorchImageSegmentationModel.get_computational_cost()TorchLiDARSegmentationModel.get_computational_cost()perceptionmetrics/models/tf_segmentation.pyTensorflowImageSegmentationModel.get_computational_cost()has_gpuvariable (already stored before loop)and replaces
time.time()withtime.perf_counter()Impact
Every user running computational cost estimation on CPU gets accurate timing results. This is especially relevant since CUDA is optional and most contributors and new users run on CPU-only machines.
References
torch.cuda.synchronize()only synchronizes CUDA device operationstime.perf_counter()is the recommended high-resolution timer for benchmarkingGithub: @vinitjain2005