Skip to content

Commit

Permalink
Fix type checking for `fbcode//vision/fair/fvcore/tests:fvcore_bm-lib…
Browse files Browse the repository at this point in the history
…rary` (#151)

Summary: Pull Request resolved: #151

Reviewed By: MaggieMoss

Differential Revision: D64551306

fbshipit-source-id: 51152483f603c069476a6f679896c4f410bb2002
  • Loading branch information
grievejia authored and facebook-github-bot committed Oct 17, 2024
1 parent fa5b663 commit d051804
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 448 deletions.
3 changes: 0 additions & 3 deletions tests/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions tests/bm_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ def main() -> None:
if isfile(f) and not f.endswith("bm_main.py")
]

# pyre-fixme[16]: `List` has no attribute `__iter__`.
for module_name in module_names:
module = importlib.import_module(module_name)
for attr in dir(module):
# Run all the functions with names "bm_*" in the module.
if attr.startswith("bm_"):
# pyre-fixme[16]: `str` has no attribute `__add__`.
# pyre-fixme[58]: `+` is not supported for operand types `str` and
# `Any`.
print("Running benchmarks for " + module_name + "/" + attr + "...")
getattr(module, attr)()


# pyre-fixme[16]: `str` has no attribute `__eq__`.
if __name__ == "__main__":
main() # pragma: no cover
29 changes: 0 additions & 29 deletions tests/test_activation_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ class SmallConvNet(nn.Module):
layers for activation count.
"""

# pyre-fixme[11]: Annotation `int` is not defined as a type.
def __init__(self, input_dim: int) -> None:
super(SmallConvNet, self).__init__()
conv_dim1 = 8
conv_dim2 = 4
conv_dim3 = 2
# pyre-fixme[29]: `type[Conv2d]` is not a function.
self.conv1 = nn.Conv2d(input_dim, conv_dim1, 1, 1)
# pyre-fixme[29]: `type[Conv2d]` is not a function.
self.conv2 = nn.Conv2d(conv_dim1, conv_dim2, 1, 2)
# pyre-fixme[29]: `type[Conv2d]` is not a function.
self.conv3 = nn.Conv2d(conv_dim2, conv_dim3, 1, 2)

def forward(self, x: torch.Tensor) -> torch.Tensor:
Expand All @@ -41,7 +37,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
x = self.conv3(x)
return x

# pyre-fixme[11]: Annotation `tuple` is not defined as a type.
def get_gt_activation(self, x: torch.Tensor) -> Tuple[int, int, int]:
x = self.conv1(x)
count1 = prod(list(x.size()))
Expand All @@ -60,14 +55,11 @@ class TestActivationCountAnalysis(unittest.TestCase):
def setUp(self) -> None:
# nn.Linear uses a different operator based on version, so make sure
# we are testing the right thing.
# pyre-fixme[29]: `type[Linear]` is not a function.
lin = nn.Linear(10, 10)
lin_x: torch.Tensor = torch.randn(10, 10)
trace = torch.jit.trace(lin, (lin_x,))
node_kinds = [node.kind() for node in trace.graph.nodes()]
# pyre-fixme[58]: `in` is not supported for right operand type `List[Any]`.
assert "aten::addmm" in node_kinds or "aten::linear" in node_kinds
# pyre-fixme[58]: `in` is not supported for right operand type `List[Any]`.
if "aten::addmm" in node_kinds:
self.lin_op = "addmm"
else:
Expand All @@ -81,12 +73,10 @@ def test_conv2d(self) -> None:
input_dim = 3
spatial_dim = 32
x = torch.randn(batch_size, input_dim, spatial_dim, spatial_dim)
# pyre-fixme[29]: `type[SmallConvNet]` is not a function.
convNet = SmallConvNet(input_dim)
ac_dict, _ = activation_count(convNet, (x,))
gt_count = sum(convNet.get_gt_activation(x))

# pyre-fixme[29]: `type[defaultdict]` is not a function.
gt_dict = defaultdict(float)
gt_dict["conv"] = gt_count / 1e6
self.assertDictEqual(
Expand All @@ -102,14 +92,10 @@ def test_linear(self) -> None:
batch_size = 1
input_dim = 10
output_dim = 20
# pyre-fixme[29]: `type[Linear]` is not a function.
netLinear = nn.Linear(input_dim, output_dim)
x = torch.randn(batch_size, input_dim)
ac_dict, _ = activation_count(netLinear, (x,))
# pyre-fixme[16]: `int` has no attribute `__mul__`.
# pyre-fixme[58]: `*` is not supported for operand types `int` and `int`.
gt_count = batch_size * output_dim
# pyre-fixme[29]: `type[defaultdict]` is not a function.
gt_dict = defaultdict(float)
gt_dict[self.lin_op] = gt_count / 1e6
self.assertEqual(
Expand All @@ -121,27 +107,18 @@ def test_supported_ops(self) -> None:
Test the activation count for user provided handles.
"""

# pyre-fixme[11]: Annotation `list` is not defined as a type.
# pyre-fixme[11]: Annotation `str` is not defined as a type.
def dummy_handle(inputs: List[Any], outputs: List[Any]) -> typing.Counter[str]:
# pyre-fixme[29]: `type[Counter]` is not a function.
return Counter({"conv": 100})

batch_size = 1
input_dim = 3
spatial_dim = 32
x = torch.randn(batch_size, input_dim, spatial_dim, spatial_dim)
# pyre-fixme[29]: `type[SmallConvNet]` is not a function.
convNet = SmallConvNet(input_dim)
# pyre-fixme[11]: Annotation `Handle` is not defined as a type.
# pyre-fixme[11]: Annotation `dict` is not defined as a type.
sp_ops: Dict[str, Handle] = {"aten::_convolution": dummy_handle}
ac_dict, _ = activation_count(convNet, (x,), sp_ops)
# pyre-fixme[29]: `type[defaultdict]` is not a function.
gt_dict = defaultdict(float)
conv_layers = 3
# pyre-fixme[16]: `int` has no attribute `__mul__`.
# pyre-fixme[58]: `*` is not supported for operand types `int` and `int`.
gt_dict["conv"] = 100 * conv_layers / 1e6
self.assertDictEqual(
gt_dict,
Expand All @@ -156,13 +133,9 @@ def test_activation_count_class(self) -> None:
batch_size = 1
input_dim = 10
output_dim = 20
# pyre-fixme[29]: `type[Linear]` is not a function.
netLinear = nn.Linear(input_dim, output_dim)
x = torch.randn(batch_size, input_dim)
# pyre-fixme[16]: `int` has no attribute `__mul__`.
# pyre-fixme[58]: `*` is not supported for operand types `int` and `int`.
gt_count = batch_size * output_dim
# pyre-fixme[29]: `type[Counter]` is not a function.
gt_dict = Counter(
{
"": gt_count,
Expand All @@ -175,11 +148,9 @@ def test_activation_count_class(self) -> None:
input_dim = 3
spatial_dim = 32
x = torch.randn(batch_size, input_dim, spatial_dim, spatial_dim)
# pyre-fixme[29]: `type[SmallConvNet]` is not a function.
convNet = SmallConvNet(input_dim)
acts_counter = ActivationCountAnalysis(convNet, (x,))
gt_counts = convNet.get_gt_activation(x)
# pyre-fixme[29]: `type[Counter]` is not a function.
gt_dict = Counter(
{
"": sum(gt_counts),
Expand Down
Loading

0 comments on commit d051804

Please sign in to comment.