Merge pull request #9228 from eclipse/ag_ctc_loss_3

Fix ctc loss and remove specification of cc in builds
master
Adam Gibson 2021-03-12 19:24:05 +09:00 committed by GitHub
commit 5ba9c037a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 120 deletions

View File

@ -35,5 +35,5 @@ jobs:
protoc --version protoc --version
bash ./change-cuda-versions.sh 11.2 bash ./change-cuda-versions.sh 11.2
export OMP_NUM_THREADS=1 export OMP_NUM_THREADS=1
mvn -DskipTestResourceEnforcement=true -Ptestresources -pl ":deeplearning4j-modelimport,:deeplearning4j-core,:nd4j-cuda-11.2,:samediff-import,:libnd4j" -Dlibnd4j.helper=cudnn -Dlibnd4j.compute="5.0 5.2 5.3 6.0 8.0" -Ptest-nd4j-cuda --also-make -Dlibnd4j.chip=cuda clean test mvn -DskipTestResourceEnforcement=true -Ptestresources -pl ":deeplearning4j-modelimport,:deeplearning4j-core,:nd4j-cuda-11.2,:samediff-import,:libnd4j" -Dlibnd4j.helper=cudnn -Ptest-nd4j-cuda --also-make -Dlibnd4j.chip=cuda clean test

View File

@ -430,9 +430,9 @@ fi
if [ -z "$COMPUTE" ]; then if [ -z "$COMPUTE" ]; then
if [ "$ARCH" == "x86-64" ]; then if [ "$ARCH" == "x86-64" ]; then
COMPUTE="5.0 5.2 5.3 6.0 8.0" COMPUTE="all"
else else
COMPUTE="5.0 5.2 5.3 6.0" COMPUTE="all"
fi fi
fi fi

View File

@ -1,5 +1,6 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2021 Deeplearning4j Contributors *
* Copyright (c) 2021 Konduit K.K.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at * terms of the Apache License, Version 2.0 which is available at
@ -12,7 +13,7 @@
* under the License. * under the License.
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*******************************************************************************/tt ******************************************************************************/
// //
// @author AbdelRauf // @author AbdelRauf
// //

View File

@ -58,164 +58,164 @@ void launcher(cudaStream_t *stream, double *input, double *output, Nd4jLong leng
} }
TEST_F(LambdaTests, test_basic_1) { // TEST_F(LambdaTests, test_basic_1) {
auto x = NDArrayFactory::create<double>('c', {5}); // auto x = NDArrayFactory::create<double>('c', {5});
auto e = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.}); // auto e = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.});
//x.applyLambda<double>(f, nullptr); // //x.applyLambda<double>(f, nullptr);
launcher(LaunchContext::defaultContext()->getCudaStream(), (double *)x.specialBuffer(), (double *)x.specialBuffer(), x.lengthOf()); // launcher(LaunchContext::defaultContext()->getCudaStream(), (double *)x.specialBuffer(), (double *)x.specialBuffer(), x.lengthOf());
auto res = cudaStreamSynchronize(*LaunchContext::defaultContext()->getCudaStream()); // auto res = cudaStreamSynchronize(*LaunchContext::defaultContext()->getCudaStream());
ASSERT_EQ(0, res); // ASSERT_EQ(0, res);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
void test(NDArray &x) { // void test(NDArray &x) {
auto f = LAMBDA_D(x) { // auto f = LAMBDA_D(x) {
return x+1.; // return x+1.;
}; // };
x.applyLambda(f, x); // x.applyLambda(f, x);
} // }
template <typename T> // template <typename T>
void test2(NDArray &x) { // void test2(NDArray &x) {
auto f = LAMBDA_T(x) { // auto f = LAMBDA_T(x) {
return x+1.; // return x+1.;
}; // };
x.applyLambda(f, x); // x.applyLambda(f, x);
} // }
void testPairwise(NDArray &x, NDArray &y) { // void testPairwise(NDArray &x, NDArray &y) {
auto f = LAMBDA_DD(x, y) { // auto f = LAMBDA_DD(x, y) {
return x + y +1.; // return x + y +1.;
}; // };
x.applyPairwiseLambda(y, f, x); // x.applyPairwiseLambda(y, f, x);
} // }
void testTriplewise(NDArray &i, NDArray &j, NDArray &k) { // void testTriplewise(NDArray &i, NDArray &j, NDArray &k) {
auto f = LAMBDA_DDD(i, j, k) { // auto f = LAMBDA_DDD(i, j, k) {
return i + j + k + 2.; // return i + j + k + 2.;
}; // };
i.applyTriplewiseLambda(j, k, f, i); // i.applyTriplewiseLambda(j, k, f, i);
} // }
void testIndexed(NDArray &x) { // void testIndexed(NDArray &x) {
auto f = ILAMBDA_D(x) { // auto f = ILAMBDA_D(x) {
return _idx + 1.; // return _idx + 1.;
}; // };
x.applyIndexedLambda(f, x); // x.applyIndexedLambda(f, x);
} // }
void testIndexedPairwise(NDArray &x, NDArray &y) { // void testIndexedPairwise(NDArray &x, NDArray &y) {
auto f = ILAMBDA_DD(x, y) { // auto f = ILAMBDA_DD(x, y) {
return _idx + x + y +1.; // return _idx + x + y +1.;
}; // };
x.applyIndexedPairwiseLambda(y, f, x); // x.applyIndexedPairwiseLambda(y, f, x);
} // }
TEST_F(LambdaTests, test_basic_2) { // TEST_F(LambdaTests, test_basic_2) {
auto x = NDArrayFactory::create<double>('c', {5}); // auto x = NDArrayFactory::create<double>('c', {5});
auto e = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.}); // auto e = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.});
test(x); // test(x);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
TEST_F(LambdaTests, test_basic_3) { // TEST_F(LambdaTests, test_basic_3) {
auto x = NDArrayFactory::create<float>('c', {5}); // auto x = NDArrayFactory::create<float>('c', {5});
auto e = NDArrayFactory::create<float>('c', {5}, {1.f, 1.f, 1.f, 1.f, 1.f}); // auto e = NDArrayFactory::create<float>('c', {5}, {1.f, 1.f, 1.f, 1.f, 1.f});
test(x); // test(x);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
TEST_F(LambdaTests, test_basic_4) { // TEST_F(LambdaTests, test_basic_4) {
auto x = NDArrayFactory::create<float>('c', {5}); // auto x = NDArrayFactory::create<float>('c', {5});
auto e = NDArrayFactory::create<float>('c', {5}, {1.f, 1.f, 1.f, 1.f, 1.f}); // auto e = NDArrayFactory::create<float>('c', {5}, {1.f, 1.f, 1.f, 1.f, 1.f});
test2<float>(x); // test2<float>(x);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
TEST_F(LambdaTests, test_basic_5) { // TEST_F(LambdaTests, test_basic_5) {
auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.}); // auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.});
auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.}); // auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.});
auto e = NDArrayFactory::create<double>('c', {5}, {4., 4., 4., 4., 4.}); // auto e = NDArrayFactory::create<double>('c', {5}, {4., 4., 4., 4., 4.});
testPairwise(x, y); // testPairwise(x, y);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
TEST_F(LambdaTests, test_basic_6) { // TEST_F(LambdaTests, test_basic_6) {
auto x = NDArrayFactory::create<double>('c', {5}); // auto x = NDArrayFactory::create<double>('c', {5});
auto e = NDArrayFactory::create<double>('c', {5}, {1., 2., 3., 4., 5.}); // auto e = NDArrayFactory::create<double>('c', {5}, {1., 2., 3., 4., 5.});
testIndexed(x); // testIndexed(x);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
TEST_F(LambdaTests, test_basic_7) { // TEST_F(LambdaTests, test_basic_7) {
auto w = NDArrayFactory::create<double>('c', {5}, {0., 0., 0., 0., 0.}); // auto w = NDArrayFactory::create<double>('c', {5}, {0., 0., 0., 0., 0.});
auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.}); // auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.});
auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.}); // auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.});
auto e = NDArrayFactory::create<double>('c', {5}, {5., 5., 5., 5., 5.}); // auto e = NDArrayFactory::create<double>('c', {5}, {5., 5., 5., 5., 5.});
testTriplewise(w, x, y); // testTriplewise(w, x, y);
ASSERT_EQ(e, w); // ASSERT_EQ(e, w);
} // }
TEST_F(LambdaTests, test_basic_8) { // TEST_F(LambdaTests, test_basic_8) {
auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.}); // auto x = NDArrayFactory::create<double>('c', {5}, {1., 1., 1., 1., 1.});
auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.}); // auto y = NDArrayFactory::create<double>('c', {5}, {2., 2., 2., 2., 2.});
auto e = NDArrayFactory::create<double>('c', {5}, {4., 5., 6., 7., 8.}); // auto e = NDArrayFactory::create<double>('c', {5}, {4., 5., 6., 7., 8.});
testIndexedPairwise(x, y); // testIndexedPairwise(x, y);
ASSERT_EQ(e, x); // ASSERT_EQ(e, x);
} // }
template <typename T> // template <typename T>
void testPairwiseMy(NDArray &x, NDArray &y, NDArray &z) { // void testPairwiseMy(NDArray &x, NDArray &y, NDArray &z) {
auto f = LAMBDA_TT(x, y){ // auto f = LAMBDA_TT(x, y){
return sd::math::nd4j_max<T>(x, (T)0.f) // return sd::math::nd4j_max<T>(x, (T)0.f)
- x * y // - x * y
+ sd::math::nd4j_log<T,T>((T)1.f // + sd::math::nd4j_log<T,T>((T)1.f
+ sd::math::nd4j_exp<T,T>(-sd::math::nd4j_abs(x))); // + sd::math::nd4j_exp<T,T>(-sd::math::nd4j_abs(x)));
}; // };
x.applyPairwiseLambda(y, f, z); // x.applyPairwiseLambda(y, f, z);
} // }
/////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////
TEST_F(LambdaTests, test_basic_9) { // TEST_F(LambdaTests, test_basic_9) {
NDArray labels('c', {2,3,4},{0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,0,1,0}); // NDArray labels('c', {2,3,4},{0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,0,1,0});
NDArray logits('c', {2,3,4}, sd::DataType::DOUBLE); // NDArray logits('c', {2,3,4}, sd::DataType::DOUBLE);
NDArray output('c', {2,3,4}, sd::DataType::DOUBLE); // NDArray output('c', {2,3,4}, sd::DataType::DOUBLE);
NDArray expected('c', {2,3,4}, {0.744397, 0.598139, 0.554355, 0.913015, 0.474077, 1.037488, 0.403186, 1.171101, 0.341154, 1.313262, 0.287335, 1.463282, 0.241008, 1.620417, 0.201413, 1.783901, 0.167786, 1.952978, 2.039387, 0.126928, 0.115520, 2.305083, 0.095545, 2.486836}); // NDArray expected('c', {2,3,4}, {0.744397, 0.598139, 0.554355, 0.913015, 0.474077, 1.037488, 0.403186, 1.171101, 0.341154, 1.313262, 0.287335, 1.463282, 0.241008, 1.620417, 0.201413, 1.783901, 0.167786, 1.952978, 2.039387, 0.126928, 0.115520, 2.305083, 0.095545, 2.486836});
logits.linspace(0.1, 0.1); // logits.linspace(0.1, 0.1);
NDArray::prepareSpecialUse({&output}, {&logits, &labels}); // NDArray::prepareSpecialUse({&output}, {&logits, &labels});
testPairwiseMy<double>(logits, labels, output); // testPairwiseMy<double>(logits, labels, output);
NDArray::registerSpecialUse({&output}, {&logits, &labels}); // NDArray::registerSpecialUse({&output}, {&logits, &labels});
// output.printBuffer(nullptr, -1, true); // // output.printBuffer(nullptr, -1, true);
ASSERT_TRUE(expected.equalsTo(output)); // ASSERT_TRUE(expected.equalsTo(output));
} // }