Skip to content

Flatten mix/fun and finish flattening of /mix - #1584

Merged
rok-cesnovar merged 20 commits into
developfrom
flatten-mix-fun
Jan 7, 2020
Merged

rok-cesnovar merged 20 commits into
developfrom
flatten-mix-fun

Conversation

@rok-cesnovar

@rok-cesnovar rok-cesnovar commented Jan 5, 2020 •

Copy link
Copy Markdown
Member

Summary

This PR flattens mix/fun and finishes flattening the mix folder by creating the stan/math/mix.hpp header. This again touches a lot of files, but the changes are very simple. Only around 5 files required manual merging, the rest are renaming changes.

Tests

This also fixes #1453 with 744fea1

Side Effects

/

Checklist

@mcol

mcol commented Jan 5, 2020

Copy link
Copy Markdown
Member

There's the old MathMixMatFun.add_vec_mat failure occurring again... Jenkins reports the tolerance to be 0.0001, but the test clearly sets it to be 0.0005, so I don't know what's going on (locally the test passes).

@rok-cesnovar

Copy link
Copy Markdown
Member Author

What is weirder is that the test error seems to be 1. I ran this on my Ubuntu setup with mpi, exact same compiler, and the test passes. This PR only moves the test so this is very bizarre. Will dig into this test a bit more.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Jenkins reports the tolerance to be 0.0001, but the test clearly sets it to be 0.0005

That is a good point also yes.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Ah, I found it.

  Eigen::VectorXd v5(5);
  v5 << 1, 2, 3, 4, 5;
  Eigen::VectorXd v5b(5);
  v5 << 2, 3, 4, 5, 6;
  Eigen::VectorXd rv5(5);
  v5 << 1, 2, 3, 4, 5;
  Eigen::VectorXd rv5b(5);
  v5 << 2, 3, 4, 5, 6;
  stan::test::expect_ad(tols, f, v5, v5b);
  stan::test::expect_ad(tols, f, rv5, rv5b);

This was probably it all along. Only v5 is initialized. Will fix this in this PR. subtract_vec_mat suffers from the same problem.

@mcol

mcol commented Jan 5, 2020

Copy link
Copy Markdown
Member

Well spotted!

mcol
mcol previously approved these changes Jan 5, 2020

@mcol mcol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anything that needs changing, so it's ready to go!

@mcol

mcol commented Jan 5, 2020

Copy link
Copy Markdown
Member

This is not having an easy time:

In file included from test/unit/math/mix/fun/log_mix_test.cpp:1:0:
./test/unit/math/test_ad.hpp: In function 'void stan::test::internal::test_gradient(const stan::test::ad_tolerances&, const F&, const VectorXd&, double, bool)
 [with F = stan::test::internal::expect_ad_helper(const stan::test::ad_tolerances&, const F&, const G&, const VectorXd&, Ts ...)::<lambda(int)>
 [with F = stan::test::internal::expect_ad_vvv(const stan::test::ad_tolerances&, const F&, int, const T2&, const T3&)
 [with F = mathMixScalFun_logMix_Test::TestBody()::<lambda(const auto:46&, const auto:47&, const auto:48&)>; T2 = double; T3 = double]::<lambda(const auto:23&, const auto:24&)>; G = stan::test::internal::expect_ad_vv(const stan::test::ad_tolerances&, const F&, const T1&, const T2&)
 [with F = stan::test::internal::expect_ad_vvv(const stan::test::ad_tolerances&, const F&, int, const T2&, const T3&)
 [with F = mathMixScalFun_logMix_Test::TestBody()::<lambda(const auto:46&, const auto:47&, const auto:48&)>; T2 = double; T3 = double]::<lambda(const auto:23&, const auto:24&)>; T1 = double; T2 = double]::<lambda(const auto:9&)>; Ts = {double, double}]::<lambda(const auto:5&)>]':
./test/unit/math/test_ad.hpp:245:3: internal compiler error: Segmentation fault
   test_gradient(tols, g, x, gx);
   ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://sourceforge.net/projects/mingw-w64> for instructions.
<builtin>: recipe for target 'test/unit/math/mix/fun/log_mix_test.o' failed
mingw32-make: *** [test/unit/math/mix/fun/log_mix_test.o] Error 1

That's on Windows, no issue on Linux

@mcol

mcol commented Jan 5, 2020

Copy link
Copy Markdown
Member

I've reproduced it on Windows locally, and it still causes an error in the compiler, but the traceback is slightly different:

In file included from ./stan/math/fwd/functor.hpp:4:0,
                 from ./stan/math/fwd.hpp:14,
                 from ./stan/math/mix.hpp:9,
                 from ./test/unit/math/test_ad.hpp:8,
                 from test/unit/math/mix/fun/log_mix_test.cpp:1:
./stan/math/fwd/functor/gradient.hpp: In function 'stan::test::internal::expect_ad_helper(const stan::test::ad_tolerances&, const F&, const G&, const VectorXd&, Ts ...)::<lambda(int)>::<lambda(const auto:5&)>
 [with auto:5 = Eigen::Matrix<stan::math::fvar<double>, -1, 1>; F = mathMixScalFun_logMix_Test::TestBody()::<lambda(const auto:46&, const auto:47&, const auto:48&)>; G = stan::test::internal::expect_ad_vvv(const stan::test::ad_tolerances&, const F&, const T1&, const T2&, const T3&)
 [with F = mathMixScalFun_logMix_Test::TestBody()::<lambda(const auto:46&, const auto:47&, const auto:48&)>; T1 = double; T2 = int; T3 = double]::<lambda(const auto:18&)>; Ts = {double, int, double}]':
./stan/math/fwd/functor/gradient.hpp:47:31: internal compiler error: Segmentation fault
     fvar<T> fx_fvar = f(x_fvar);
                               ^
Please submit a full bug report,
with preprocessed source if appropriate.

@bob-carpenter

bob-carpenter commented Jan 5, 2020 via email

Copy link
Copy Markdown
Member

@bob-carpenter

bob-carpenter commented Jan 5, 2020 via email

Copy link
Copy Markdown
Member

@mcol

mcol commented Jan 6, 2020

Copy link
Copy Markdown
Member

Commenting out the matMixscalFun test block solves the segfault (as the file becomes the one before flattening), while commenting out the mathMixMatFun test block makes no difference.
For me it's enough to comment out any one of the stan::test::expect_ad lines in the
void expect_log_mix(const std::vector<double>& p, const std::vector<std::vector<double>>& ds) function to solve the bug. Both when it fails and when it succeeds, I see memory use for cc1plus.exe going over 4.1GB (I have 16GB).

At -O2 it still crashes, but at -O1 it compiles fine. When setting the optimization level to -O0 I got:

C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/as.exe: test/unit/math/mix/fun/log_mix_test.o: too many sections (49468)
C:\Users\marco\AppData\Local\Temp\ccJx3Qho.s: Assembler messages:
C:\Users\marco\AppData\Local\Temp\ccJx3Qho.s: Fatal error: can't write test/unit/math/mix/fun/log_mix_test.o: File too big
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/as.exe: test/unit/math/mix/fun/log_mix_test.o: too many sections (49468)
C:\Users\marco\AppData\Local\Temp\ccJx3Qho.s: Fatal error: can't close test/unit/math/mix/fun/log_mix_test.o: File too big
<builtin>: recipe for target 'test/unit/math/mix/fun/log_mix_test.o' failed
mingw32-make: *** [test/unit/math/mix/fun/log_mix_test.o] Error 1

@bob-carpenter

bob-carpenter commented Jan 6, 2020 via email

Copy link
Copy Markdown
Member

@rok-cesnovar

rok-cesnovar commented Jan 6, 2020 •

Copy link
Copy Markdown
Member Author

Are bigger translation units getting compiled after the refactor?

Yeah, log_mix_test was one of the rare ones in this flatten where there were tests in multiple subfolders (scal and arr in this case) so this PR merges the scalar tests with the existing array tests. It seems that the one added test in this file caused it to crash due to lack of resources.

Commenting out the matMixscalFun test block solves the segfault

Thanks so much for debugging this one! Will probably split this in multiple files if there is no other non-hacky solution to this problem.

@alashworth Do you have any tricks up your sleave to handle compiling larger test files on Windows? Since you are using jumbo builds you probably already seen this before.

@alashworth

Copy link
Copy Markdown
Member

The "easiest" fix is to make sure you are compiling with -Wa,-mbig-obj. Then try compiling with a higher optimization level. Past this requires a lot more manual work moving things in and out of translation units, and taking a count of how many templated functions are being created in the .obj file.

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Thanks, trying if seting the flag will work. It doesnt seem as huge of a test file to be needing other tricks: https://github.com/stan-dev/math/blob/5e18d5eb189008175178bd207a8453dbbc152b49/test/unit/math/mix/fun/log_mix_test.cpp Hopefully :)

@bob-carpenter

bob-carpenter commented Jan 6, 2020 via email

Copy link
Copy Markdown
Member

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Yeah, the big-obj flag did not work.

g++ -Wa,-mbig-obj -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs      -I lib/tbb_2019_U8/include -O3  -I . -I lib/eigen_3.3.3 -I lib/boost_1.72.0 -I lib/sundials_4.1.0/include -I lib/gtest_1.8.1/include -I lib/gtest_1.8.1   -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS       -c -MT test/unit/math/mix/fun/log_mix_test.o -M -E -MG -MP -MF test/unit/math/mix/fun/log_mix_test.d test/unit/math/mix/fun/log_mix_test.cpp

g++ -Wa,-mbig-obj -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs      -I lib/tbb_2019_U8/include -O3  -I . -I lib/eigen_3.3.3 -I lib/boost_1.72.0 -I lib/sundials_4.1.0/include -I lib/gtest_1.8.1/include -I lib/gtest_1.8.1 -I lib/gtest_1.8.1/include -I lib/gtest_1.8.1    -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS        -c -o test/unit/math/mix/fun/log_mix_test.o test/unit/math/mix/fun/log_mix_test.cpp

produced the same seg fault, so multiple translation units it is.

@bob-carpenter Should I just split them to log_mix_arr_test.cpp and log_mix_test_scal_test.cpp?

@bob-carpenter

bob-carpenter commented Jan 6, 2020 via email

Copy link
Copy Markdown
Member

@mcol mcol mentioned this pull request Jan 6, 2020
3 tasks done
@stan-buildbot

Copy link
Copy Markdown
Contributor

(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 1.0)
(stat_comp_benchmarks/benchmarks/low_dim_corr_gauss/low_dim_corr_gauss.stan, 0.99)
(stat_comp_benchmarks/benchmarks/irt_2pl/irt_2pl.stan, 1.01)
(stat_comp_benchmarks/benchmarks/pkpd/one_comp_mm_elim_abs.stan, 0.99)
(stat_comp_benchmarks/benchmarks/eight_schools/eight_schools.stan, 1.0)
(stat_comp_benchmarks/benchmarks/gp_regr/gp_regr.stan, 1.0)
(stat_comp_benchmarks/benchmarks/arK/arK.stan, 1.0)
(performance.compilation, 1.02)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan, 0.99)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix/low_dim_gauss_mix.stan, 1.02)
(stat_comp_benchmarks/benchmarks/sir/sir.stan, 1.06)
(stat_comp_benchmarks/benchmarks/pkpd/sim_one_comp_mm_elim_abs.stan, 0.96)
(stat_comp_benchmarks/benchmarks/garch/garch.stan, 1.01)
(stat_comp_benchmarks/benchmarks/gp_regr/gen_gp_data.stan, 1.0)
(stat_comp_benchmarks/benchmarks/arma/arma.stan, 0.99)
Result: Regex did not match anything
Commit hash: 3db0e91778befa1fdc52930ea5bad00c988396a9

@rok-cesnovar

Copy link
Copy Markdown
Member Author

I restarted the test with the Stan upstream pointing to your PR @mcol. We should hit green now.

@mcol

mcol commented Jan 7, 2020 •

Copy link
Copy Markdown
Member

I pushed a fix for an include that I introduced on develop, and restarted the job pointing to stan-dev/stan#2874. I hope it's alright!

@rok-cesnovar

Copy link
Copy Markdown
Member Author

Sure. Thanks!

@stan-buildbot

Copy link
Copy Markdown
Contributor

(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 0.97)
(stat_comp_benchmarks/benchmarks/low_dim_corr_gauss/low_dim_corr_gauss.stan, 1.05)
(stat_comp_benchmarks/benchmarks/irt_2pl/irt_2pl.stan, 1.01)
(stat_comp_benchmarks/benchmarks/pkpd/one_comp_mm_elim_abs.stan, 1.05)
(stat_comp_benchmarks/benchmarks/eight_schools/eight_schools.stan, 0.95)
(stat_comp_benchmarks/benchmarks/gp_regr/gp_regr.stan, 1.01)
(stat_comp_benchmarks/benchmarks/arK/arK.stan, 1.0)
(performance.compilation, 1.02)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan, 0.95)
(stat_comp_benchmarks/benchmarks/low_dim_gauss_mix/low_dim_gauss_mix.stan, 1.0)
(stat_comp_benchmarks/benchmarks/sir/sir.stan, 0.98)
(stat_comp_benchmarks/benchmarks/pkpd/sim_one_comp_mm_elim_abs.stan, 1.06)
(stat_comp_benchmarks/benchmarks/garch/garch.stan, 1.01)
(stat_comp_benchmarks/benchmarks/gp_regr/gen_gp_data.stan, 0.99)
(stat_comp_benchmarks/benchmarks/arma/arma.stan, 1.08)
Result: Regex did not match anything
Commit hash: 3db0e91778befa1fdc52930ea5bad00c988396a9

@mcol mcol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we there finally? :)

@rok-cesnovar
rok-cesnovar merged commit a6d7b7a into develop Jan 7, 2020
@mcol
mcol deleted the flatten-mix-fun branch January 7, 2020 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MathMixMatFun.add and MathMixMatFun.subtract tests seem to fail randomly?

5 participants