Created
June 19, 2025 13:04
-
-
Save lopsided/9cf3e7177082f8901ec5450ff8aab94f to your computer and use it in GitHub Desktop.
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
| import gc | |
| import psutil | |
| from ptflops import get_model_complexity_info | |
| network = ForecastModel() # Replace with your actual model | |
| # Use ptflops to get the MACs | |
| macs, _ = get_model_complexity_info( | |
| network, | |
| network.input_shape, | |
| as_strings=False, | |
| print_per_layer_stat=False, | |
| ) | |
| # Reset VRAM and garbage collect | |
| torch.cuda.empty_cache() | |
| torch.cuda.reset_peak_memory_stats() | |
| gc.collect() | |
| # Get the RAM usage before | |
| process = psutil.Process() | |
| before_ram = process.memory_info().rss | |
| start = time.time() | |
| _process_sample_input() | |
| end = time.time() | |
| after_ram = process.memory_info().rss | |
| # Results | |
| vram_bytes = torch.cuda.max_memory_allocated() | |
| ram_bytes = after_ram - before_ram | |
| latency_s = end - start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment