Skip to content

Commit 40141f7

Browse files
committed
Implement the unittest for hash op
test=develop
1 parent accb7b5 commit 40141f7

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

cmake/external/xxhash.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ExternalProject_Add(
1616
CONFIGURE_COMMAND ""
1717
BUILD_IN_SOURCE 1
1818
PATCH_COMMAND
19-
BUILD_COMMAND make lib
19+
BUILD_COMMAND sed -i "s/-Wstrict-prototypes -Wundef/-Wstrict-prototypes -Wundef -fPIC/g" ${XXHASH_SOURCE_DIR}/src/extern_xxhash/Makefile && make lib
2020
INSTALL_COMMAND export PREFIX=${XXHASH_INSTALL_DIR}/ && make install
2121
TEST_COMMAND ""
2222
)

paddle/fluid/operators/hash_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class HashOp : public framework::OperatorWithKernel {
4646
// keep the last dim to 1
4747
out_dims.emplace_back(1);
4848

49-
ctx->SetOutputDim("Out", dims);
49+
ctx->SetOutputDim("Out", framework::make_ddim(out_dims));
5050
ctx->ShareLoD("X", /*->*/ "Out");
5151
}
5252
};

paddle/scripts/paddle_build.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ function cmake_gen() {
9595
exit 1
9696
fi
9797
fi
98-
else
98+
else
9999
if [ "$1" != "" ]; then
100-
echo "using python abi: $1"
100+
echo "using python abi: $1"
101101
if [ "$1" == "cp27-cp27m" ]; then
102102
export LD_LIBRARY_PATH=/opt/_internal/cpython-2.7.11-ucs2/lib:${LD_LIBRARY_PATH#/opt/_internal/cpython-2.7.11-ucs4/lib:}
103103
export PATH=/opt/python/cp27-cp27m/bin/:${PATH}
@@ -119,15 +119,15 @@ function cmake_gen() {
119119
fi
120120
fi
121121
fi
122-
122+
123123
if [ "$SYSTEM" == "Darwin" ]; then
124124
WITH_DISTRIBUTE=${WITH_DISTRIBUTE:-ON}
125125
WITH_AVX=${WITH_AVX:-ON}
126126
INFERENCE_DEMO_INSTALL_DIR=${INFERENCE_DEMO_INSTALL_DIR:-~/.cache/inference_demo}
127127
else
128128
INFERENCE_DEMO_INSTALL_DIR=${INFERENCE_DEMO_INSTALL_DIR:-/root/.cache/inference_demo}
129129
fi
130-
130+
131131
cat <<EOF
132132
========================================
133133
Configuring cmake in /paddle/build ...
@@ -394,8 +394,8 @@ EOF
394394
export http_proxy=
395395
export https_proxy=
396396
# TODO: jiabin need to refine this part when these tests fixed on mac
397-
ctest --output-on-failure -j $1
398-
# make install should also be test when unittest
397+
ctest --output-on-failure -j $1
398+
# make install should also be test when unittest
399399
make install -j 8
400400
pip install --user ${INSTALL_PREFIX:-/paddle/build}/opt/paddle/share/wheels/*.whl
401401
if [[ ${WITH_FLUID_ONLY:-OFF} == "OFF" ]] ; then

python/paddle/fluid/tests/unittests/test_hash_op.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,32 @@ def setUp(self):
2222
self.op_type = "hash"
2323
self.init_test_case()
2424
self.inputs = {'X': (self.in_seq, self.lod)}
25-
self.attrs = {'num_hash': 8, 'mod_by': 10000}
25+
self.attrs = {'num_hash': 4, 'mod_by': 10000}
2626
self.outputs = {'Out': (self.out_seq, self.lod)}
2727

2828
def init_test_case(self):
29+
np.random.seed = 1
2930
self.in_seq = np.random.randint(0, 10, (30, 1)).astype("int32")
3031
self.lod = [[9, 4, 11, 6]]
31-
self.out_seq = np.ones([30, 8], dtype=np.int32)
32+
# self.out_seq = np.ones([30, 4, 1], dtype=np.int32)
33+
self.out_seq = [
34+
[[9662], [9217], [1129], [8487]], [[9662], [9217], [1129], [8487]],
35+
[[8310], [1327], [1654], [4567]], [[6897], [3218], [2013], [1241]],
36+
[[9407], [6715], [6949], [8094]], [[8473], [694], [5142], [2479]],
37+
[[8310], [1327], [1654], [4567]], [[6897], [3218], [2013], [1241]],
38+
[[4372], [9456], [8204], [6695]], [[6897], [3218], [2013], [1241]],
39+
[[8473], [694], [5142], [2479]], [[4372], [9456], [8204], [6695]],
40+
[[4372], [9456], [8204], [6695]], [[8473], [694], [5142], [2479]],
41+
[[9407], [6715], [6949], [8094]], [[9369], [4525], [8935], [9210]],
42+
[[4372], [9456], [8204], [6695]], [[4372], [9456], [8204], [6695]],
43+
[[9369], [4525], [8935], [9210]], [[6897], [3218], [2013], [1241]],
44+
[[9038], [7951], [5953], [8657]], [[9407], [6715], [6949], [8094]],
45+
[[9662], [9217], [1129], [8487]], [[9369], [4525], [8935], [9210]],
46+
[[9038], [7951], [5953], [8657]], [[9662], [9217], [1129], [8487]],
47+
[[9369], [4525], [8935], [9210]], [[1719], [5986], [9919], [3421]],
48+
[[4372], [9456], [8204], [6695]], [[9038], [7951], [5953], [8657]]
49+
]
50+
self.out_seq = np.array(self.out_seq)
3251

3352
def test_check_output(self):
3453
self.check_output()

0 commit comments

Comments
 (0)