From d9fd97ef0a5e1c442cb1570134d41adccd758d5b Mon Sep 17 00:00:00 2001 From: Felix Dangel Date: Thu, 27 Nov 2025 10:13:27 -0500 Subject: [PATCH 1/5] [ADD] Print memory delta in memory leak test --- test/test___init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test___init__.py b/test/test___init__.py index 197cb1fe5..b71df4950 100644 --- a/test/test___init__.py +++ b/test/test___init__.py @@ -76,7 +76,7 @@ def memory_leak(device, context=None): if context is None: context = nullcontext - for _ in range(steps): + for s in range(steps): lossfunc = torch.nn.CrossEntropyLoss().to(device) lossfunc = extend(lossfunc) @@ -87,6 +87,7 @@ def memory_leak(device, context=None): loss = lossfunc(model(X), y) # this is what kills it memory = pytorch_current_memory_usage() + print(f"Step {s}, Memory delta: {(memory - memory_init) / 2**20:.2f} MiB.") if memory - memory_init > memory_leak_threshold: raise RuntimeError( f"Memory leak detected: context={context}, device={device}" From b3090a920c43e89e2ec8b6bfd149becdf23c84ac Mon Sep 17 00:00:00 2001 From: Felix Dangel Date: Thu, 27 Nov 2025 10:15:30 -0500 Subject: [PATCH 2/5] [CI] Always run full tests --- .github/workflows/test.yaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d947771b1..1daba8752 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,14 +1,6 @@ name: Test -on: - push: - branches: - - '*' - pull_request: - branches: - - development - - master - - release +on: [push, pull_request] jobs: tests: @@ -34,10 +26,5 @@ jobs: make install-test pip install torch${{ matrix.pytorch-version }} torchvision - name: Run test - if: contains('refs/heads/master refs/heads/development refs/heads/release', github.ref) run: | make test - - name: Run test-light - if: contains('refs/heads/master refs/heads/development refs/heads/release', github.ref) != 1 - run: | - make test-light From 0b235d2874d132ba519df0231e9a4b9de0d7f92e Mon Sep 17 00:00:00 2001 From: Felix Dangel Date: Thu, 27 Nov 2025 16:20:26 -0500 Subject: [PATCH 3/5] [FIX] Try running `test_memory_leak` separately --- makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index b0d4726a3..8098ccfa8 100644 --- a/makefile +++ b/makefile @@ -56,16 +56,20 @@ help: ### # Test coverage test: - @pytest -vx -rs --run-optional-tests=montecarlo --cov=backpack . + @pytest -vx -rs --run-optional-tests=montecarlo --cov=backpack . -k "test_memory_leak" + @pytest -vx -rs --run-optional-tests=montecarlo --cov=backpack . -k "not test_memory_leak" test-light: - @pytest -vx -rs --cov=backpack . + @pytest -vx -rs --cov=backpack . -k "test_memory_leak" + @pytest -vx -rs --cov=backpack . -k "not test_memory_leak" test-no-gpu: - @pytest -k "not cuda" -vx -rs --run-optional-tests=montecarlo --cov=backpack . + @pytest -k "not cuda and test_memory_leak" -vx -rs --run-optional-tests=montecarlo --cov=backpack . + @pytest -k "not cuda and not test_memory_leak" -vx -rs --run-optional-tests=montecarlo --cov=backpack . test-light-no-gpu: - @pytest -k "not cuda" -vx -rs --cov=backpack . + @pytest -k "not cuda and test_memory_leak" -vx -rs --cov=backpack . + @pytest -k "not cuda and not test_memory_leak" -vx -rs --cov=backpack . ### # Linter and autoformatter From 814edc4c4581efbeda397e6f1fe5854c640eaf4f Mon Sep 17 00:00:00 2001 From: Felix Dangel Date: Thu, 27 Nov 2025 17:42:00 -0500 Subject: [PATCH 4/5] [DOC] Update changelog --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 3af3cab0e..c32ea3dc1 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix CI (apply latest `black`, use latest `pytest` and `pytest-benchmark`) ([PR](https://github.com/f-dangel/backpack/pull/348)) + - Follow-up fix, isolating a test that re-produces a memory leak. + Always run the full test suite + ([PR](https://github.com/f-dangel/backpack/pull/349)) - Improve efficiency of Hessian-vector product ([PR](https://github.com/f-dangel/backpack/pull/341)) From bd3a342b4c8963ee541c6c8f0e38491b0e7889be Mon Sep 17 00:00:00 2001 From: Felix Dangel Date: Thu, 27 Nov 2025 17:50:37 -0500 Subject: [PATCH 5/5] [DOC] Add parentheses --- makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 8098ccfa8..0fb96b492 100644 --- a/makefile +++ b/makefile @@ -64,12 +64,12 @@ test-light: @pytest -vx -rs --cov=backpack . -k "not test_memory_leak" test-no-gpu: - @pytest -k "not cuda and test_memory_leak" -vx -rs --run-optional-tests=montecarlo --cov=backpack . - @pytest -k "not cuda and not test_memory_leak" -vx -rs --run-optional-tests=montecarlo --cov=backpack . + @pytest -k "(not cuda) and test_memory_leak" -vx -rs --run-optional-tests=montecarlo --cov=backpack . + @pytest -k "(not cuda) and (not test_memory_leak)" -vx -rs --run-optional-tests=montecarlo --cov=backpack . test-light-no-gpu: - @pytest -k "not cuda and test_memory_leak" -vx -rs --cov=backpack . - @pytest -k "not cuda and not test_memory_leak" -vx -rs --cov=backpack . + @pytest -k "(not cuda) and test_memory_leak" -vx -rs --cov=backpack . + @pytest -k "(not cuda) and (not test_memory_leak)" -vx -rs --cov=backpack . ### # Linter and autoformatter