Skip to content

Commit

Permalink
[ADD] hessian_is_zero in SlicingDerivatives
Browse files Browse the repository at this point in the history
Added an additional test case with small enough input to run the Hessian
property test.
  • Loading branch information
f-dangel committed Jan 4, 2022
1 parent 2235f0c commit 48e4bbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backpack/core/derivatives/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def no_slice_batch_axis(module: Slicing):

if slice_batch_axis != slice(None):
raise ValueError("Slicing the batch axis is not supported.")

def hessian_is_zero(self, module: Slicing) -> bool: # noqa: D102
return True
6 changes: 5 additions & 1 deletion test/core/derivatives/derivatives_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def test_ea_jac_t_mat_jac_prod(problem: DerivativesTestProblem, request) -> None


@fixture(
params=PROBLEMS + BATCH_NORM_PROBLEMS + RNN_PROBLEMS + EMBEDDING_PROBLEMS,
params=PROBLEMS
+ BATCH_NORM_PROBLEMS
+ RNN_PROBLEMS
+ EMBEDDING_PROBLEMS
+ CUSTOM_SLICING_MODULE_PROBLEMS,
ids=lambda p: p.make_id(),
)
def problem(request) -> DerivativesTestProblem:
Expand Down
4 changes: 4 additions & 0 deletions test/core/derivatives/slicing_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from backpack.custom_module.slicing import Slicing

CUSTOM_SLICING_SETTINGS = [
{
"module_fn": lambda: Slicing((slice(None), 0)),
"input_fn": lambda: rand(size=(2, 4, 2, 5)),
},
{
"module_fn": lambda: Slicing((slice(None),)),
"input_fn": lambda: rand(size=(3, 4, 2, 5)),
Expand Down

0 comments on commit 48e4bbe

Please sign in to comment.