Skip to content

Commit fcfd175

Browse files
JasonKChowfacebook-github-bot
authored andcommitted
Define a EMPTY_SIZE constant for allocators (facebookresearch#790)
Summary: All inducing point allocators now use an empty_size constant as the argument default for the batch shape. This avoids the flake8 warning. Differential Revision: D73886891
1 parent 289635b commit fcfd175

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

aepsych/models/inducing_points/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from aepsych.utils import get_dims
1414
from botorch.models.utils.inducing_point_allocators import InducingPointAllocator
1515

16+
EMPTY_SIZE = torch.Size([])
17+
1618

1719
class BaseAllocator(InducingPointAllocator, ConfigurableMixin):
1820
"""Base class for inducing point allocators."""
@@ -34,7 +36,7 @@ def allocate_inducing_points(
3436
inputs: torch.Tensor | None = None,
3537
covar_module: torch.nn.Module | None = None,
3638
num_inducing: int = 100,
37-
input_batch_shape: torch.Size = torch.Size([]),
39+
input_batch_shape: torch.Size = EMPTY_SIZE,
3840
) -> torch.Tensor:
3941
"""
4042
Abstract method for allocating inducing points. Must replace the

aepsych/models/inducing_points/fixed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any
99

1010
import torch
11-
from aepsych.models.inducing_points.base import BaseAllocator
11+
from aepsych.models.inducing_points.base import BaseAllocator, EMPTY_SIZE
1212

1313

1414
class FixedAllocator(BaseAllocator):
@@ -31,7 +31,7 @@ def allocate_inducing_points(
3131
inputs: torch.Tensor | None = None,
3232
covar_module: torch.nn.Module | None = None,
3333
num_inducing: int = 100,
34-
input_batch_shape: torch.Size = torch.Size([]),
34+
input_batch_shape: torch.Size = EMPTY_SIZE,
3535
) -> torch.Tensor:
3636
"""Allocate inducing points by returning the fixed inducing points.
3737
@@ -93,7 +93,7 @@ def allocate_inducing_points(
9393
inputs: torch.Tensor | None = None,
9494
covar_module: torch.nn.Module | None = None,
9595
num_inducing: int = 100,
96-
input_batch_shape: torch.Size = torch.Size([]),
96+
input_batch_shape: torch.Size = EMPTY_SIZE,
9797
) -> torch.Tensor:
9898
points = self.main_allocator.allocate_inducing_points(
9999
inputs=inputs,

aepsych/models/inducing_points/greedy_variance_reduction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# LICENSE file in the root directory of this source tree.
77

88
import torch
9-
from aepsych.models.inducing_points.base import BaseAllocator
9+
from aepsych.models.inducing_points.base import BaseAllocator, EMPTY_SIZE
1010
from botorch.models.utils.inducing_point_allocators import (
1111
GreedyVarianceReduction as BaseGreedyVarianceReduction,
1212
)
@@ -18,7 +18,7 @@ def allocate_inducing_points(
1818
inputs: torch.Tensor | None = None,
1919
covar_module: torch.nn.Module | None = None,
2020
num_inducing: int = 100,
21-
input_batch_shape: torch.Size = torch.Size([]),
21+
input_batch_shape: torch.Size = EMPTY_SIZE,
2222
) -> torch.Tensor:
2323
"""Allocate inducing points using the GreedyVarianceReduction strategy. This is
2424
a thin wrapper around BoTorch's GreedyVarianceRedution inducing point allocator.

aepsych/models/inducing_points/kmeans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# LICENSE file in the root directory of this source tree.
77

88
import torch
9-
from aepsych.models.inducing_points.base import BaseAllocator
9+
from aepsych.models.inducing_points.base import BaseAllocator, EMPTY_SIZE
1010
from scipy.cluster.vq import kmeans2
1111

1212

@@ -18,7 +18,7 @@ def allocate_inducing_points(
1818
inputs: torch.Tensor | None = None,
1919
covar_module: torch.nn.Module | None = None,
2020
num_inducing: int = 100,
21-
input_batch_shape: torch.Size = torch.Size([]),
21+
input_batch_shape: torch.Size = EMPTY_SIZE,
2222
) -> torch.Tensor:
2323
"""
2424
Generates `num_inducing` inducing points using k-means++ initialization on the input data.

aepsych/models/inducing_points/sobol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import torch
1111
from aepsych.config import Config
12-
from aepsych.models.inducing_points.base import BaseAllocator
12+
from aepsych.models.inducing_points.base import BaseAllocator, EMPTY_SIZE
1313
from botorch.utils.sampling import draw_sobol_samples
1414

1515

@@ -36,7 +36,7 @@ def allocate_inducing_points(
3636
inputs: torch.Tensor | None = None,
3737
covar_module: torch.nn.Module | None = None,
3838
num_inducing: int = 100,
39-
input_batch_shape: torch.Size = torch.Size([]),
39+
input_batch_shape: torch.Size = EMPTY_SIZE,
4040
) -> torch.Tensor:
4141
"""
4242
Generates `num_inducing` inducing points within the specified bounds using Sobol sampling.

0 commit comments

Comments
 (0)