DeepSpeed
ebb75d7e - Fix repeated FlopsProfiler metric accumulation (#8246)

Commit
34 days ago
Fix repeated FlopsProfiler metric accumulation (#8246) ## Summary - restore `F.scaled_dot_product_attention` after profiling - restore `Tensor.__matmul__` after profiling - restore `torch.bmm` from its correct saved implementation - add a CPU regression test covering repeated profiling sessions and operation restoration - scope the existing FP16 skip to the test that actually requires FP16 ## Problem `FlopsProfiler` temporarily replaces PyTorch operations with FLOP-counting wrappers. Its cleanup path did not restore `F.scaled_dot_product_attention` or `Tensor.__matmul__`, causing wrappers to accumulate across profiling sessions. As a result, identical model executions reported progressively increasing FLOPs and MACs. The `torch.bmm` cleanup was also incorrect: ```python torch.bmm = old_functions[torch.matmul.__str__] ``` Because torch.matmul had already been restored, this rebound torch.bmm to torch.matmul for the rest of the process. This changed normal PyTorch behavior after profiling: torch.bmm began accepting inputs supported by broadcasting matmul but invalid for bmm. ## Fix Restore every patched operation from its matching saved original function. The patch and cleanup paths now cover the same set of operations with matching PyTorch version guards. ## Testing A CPU regression test profiles the same scaled-dot-product-attention operation three times and verifies: - every session reports identical FLOP and MAC totals - F.scaled_dot_product_attention, Tensor.__matmul__, and torch.bmm are restored to their original function objects after every session Observed totals: Before: [(65536, 32768), (131072, 65536), (196608, 98304)] After: [(65536, 32768), (65536, 32768), (65536, 32768)] All pre-commit checks pass. Fixes #7413 Signed-off-by: Vedant Chauhan <staranonymous1011@gmail.com>
Parents
Loading