Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 26f73cf

Browse files
authored
Merge pull request #244 from facebookresearch/mul-red-test
unit test for mul reduction, use pytest + gen=2/pop=1 to improve test time
2 parents 6712ed3 + c3b0817 commit 26f73cf

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ third-party/llvm_sources*
88
third-party-install/*
99
buck-out
1010
.buckd
11+
.pytest_cache
1112
conda
1213
.nfs*
1314
*/.nfs*

.jenkins/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if [[ "$DISTRIB_RELEASE" == 14.04 ]]; then
7272
source activate tc-env
7373
conda install -y -c pytorch pytorch
7474
conda install -y pyyaml
75+
conda install -yc conda-forge pytest
7576
WITH_PYTHON_C2=OFF CORES=$(nproc) CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
7677
else
7778
echo "Building TC in non-conda env"
@@ -86,6 +87,7 @@ if [[ "$DISTRIB_RELEASE" == 16.04 ]]; then
8687
source activate tc-env
8788
conda install -y pytorch cuda90 -c pytorch
8889
conda install -y pyyaml
90+
conda install -yc conda-forge pytest
8991
WITH_PYTHON_C2=OFF CORES=$(nproc) CLANG_PREFIX=/usr/local/clang+llvm-tapir5.0 BUILD_TYPE=Release ./build.sh --all
9092
else
9193
echo "Building TC in non-conda env"

tensor_comprehensions/tc_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131

3232
# these are quick options for finishing autotuning
3333
autotuner_settings = {
34-
"threads": 32, "generations": 2, "pop_size": 5,
34+
"threads": 32, "generations": 1, "pop_size": 2,
3535
}
3636

3737
# TC prunes autotuning for kernels which require < 256 threads. So to tune small
3838
# size kernels, we set the min kernel threads to 1
3939
small_sizes_autotuner_settings = {
40-
"threads": 32, "generations": 2, "pop_size": 5, "tuner_min_launch_total_threads": 1,
40+
"threads": 32, "generations": 1, "pop_size": 2, "tuner_min_launch_total_threads": 1,
4141
}
4242

4343
###############################################################################

test_python/layers/test_matmul_train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def matmul_grad(float(M,N) A, float(N,K) B, float(M,K) O_grad) -> (A_grad, B_gra
2020
}
2121
"""
2222

23-
matmul = tc.define(MATMUL_LANG, name="matmul", training=True, backward="matmul_grad")
23+
matmul = tc.define(LANG, name="matmul", training=True, backward="matmul_grad")
2424
mat1 = Parameter(torch.randn(3, 4).cuda())
2525
mat2 = Variable(torch.randn(4, 5).cuda(), requires_grad=True)
2626
out = matmul(mat1, mat2, options=[tc.Options("mlp"), tc.Options("mlp")])
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2017-present, Facebook, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
##############################################################################
15+
16+
import tensor_comprehensions as tc
17+
18+
import torch
19+
import unittest
20+
21+
22+
class TestMultReduction(unittest.TestCase):
23+
24+
def test_mult_reduction(self):
25+
LANG = """
26+
def conv_mult(float(N,C,H,W) I, float(M,C,KH,KW) W1) -> (O) {
27+
O(n, m, h, w) *=! I(n, c, h + kh, w + kw) * W1(m, c, kh, kw)
28+
}
29+
"""
30+
N, C, H, W, O, kH, kW = 64, 10, 24, 24, 10, 7, 7
31+
conv_mult = tc.define(LANG, name="conv_mult")
32+
I, W1 = torch.ones(N, C, H, W).cuda(), torch.ones(O, C, kH, kW).cuda()
33+
# Note: There is no bias here
34+
out = conv_mult(I, W1)
35+
assert out.data.min() > 0
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()

test_python/run_test.sh

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,7 @@ $PYTHON test_tc_torch.py -v
3030
# PyTorch layer tests
3131
###############################################################################
3232
echo "Running all PyTorch layers tests"
33-
$PYTHON layers/test_absolute.py -v
34-
$PYTHON layers/test_autotuner.py -v
35-
$PYTHON layers/test_avgpool.py -v
36-
$PYTHON layers/test_avgpool_autotune.py -v
37-
$PYTHON layers/test_batchmatmul.py -v
38-
$PYTHON layers/test_batchnorm.py -v
39-
$PYTHON layers/test_layernorm.py -v
40-
$PYTHON layers/test_cast.py -v
41-
$PYTHON layers/test_concat.py -v
42-
$PYTHON layers/test_convolution.py -v
43-
$PYTHON layers/test_convolution_strided.py -v
44-
$PYTHON layers/test_convolution_reorder.py -v
45-
$PYTHON layers/test_convolution_strided_autotune.py -v
46-
$PYTHON layers/test_convolution_train.py -v
47-
$PYTHON layers/test_copy.py -v
48-
$PYTHON layers/test_cos.py -v
49-
$PYTHON layers/test_cosine_similarity.py -v
50-
$PYTHON layers/test_dump_cuda.py -v
51-
$PYTHON layers/test_external_cuda_injection.py -v
52-
$PYTHON layers/test_fc.py -v
53-
$PYTHON layers/test_fusion_fcrelu.py -v
54-
$PYTHON layers/test_broadcast_fcrelu.py -v
55-
$PYTHON layers/test_group_convolution.py -v
56-
$PYTHON layers/test_group_convolution_strided.py -v
57-
$PYTHON layers/test_indexing.py -v
58-
$PYTHON layers/test_lookup_table.py -v
59-
$PYTHON layers/test_matmul.py -v
60-
$PYTHON layers/test_matmul_reuse_outputs.py -v
61-
$PYTHON layers/test_maxpool.py -v
62-
$PYTHON layers/test_relu.py -v
63-
$PYTHON layers/test_scale.py -v
64-
$PYTHON layers/test_sigmoid.py -v
65-
$PYTHON layers/test_small_mobilenet.py -v
66-
$PYTHON layers/test_softmax.py -v
67-
$PYTHON layers/test_tanh.py -v
68-
$PYTHON layers/test_tensordot.py -v
69-
$PYTHON layers/test_transpose.py -v
33+
$PYTHON -m pytest -v --full-trace --junit-xml="/tmp/tensorcomp/python/result.xml" layers/
7034

7135
echo "All PyTorch layer tests have finished"
7236

0 commit comments

Comments
 (0)