Skip to content

Added prototype free functions to deserializer#3018

Merged
rok-cesnovar merged 22 commits into
developfrom
feature/free-functions-deserializer
Mar 18, 2021
Merged

Added prototype free functions to deserializer#3018
rok-cesnovar merged 22 commits into
developfrom
feature/free-functions-deserializer

Conversation

@bbbales2
Copy link
Copy Markdown
Member

@bbbales2 bbbales2 commented Mar 11, 2021

Submission Checklist

  • Run unit tests: ./runTests.py src/test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary

I added an example of how unit vector free would work

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Columbia University

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@bbbales2 bbbales2 marked this pull request as draft March 11, 2021 15:35
@bbbales2 bbbales2 changed the title Added prototype free unit vector [WIP] Added prototype free unit vector Mar 11, 2021
@bbbales2 bbbales2 changed the title [WIP] Added prototype free unit vector [WIP] Added prototype free functions to deserializer Mar 11, 2021
@bbbales2
Copy link
Copy Markdown
Member Author

@SteveBronder I think these should be copy-pasted into the serializer class. They aren't making use of anything in deserializer.

Otherwise I think all the frees are here and the new bits are tested.

@stan-buildbot
Copy link
Copy Markdown
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.46 3.42 1.01 1.11% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.98 -1.82% slower
eight_schools/eight_schools.stan 0.11 0.11 1.03 3.14% faster
gp_regr/gp_regr.stan 0.16 0.16 1.04 3.48% faster
irt_2pl/irt_2pl.stan 5.29 5.31 1.0 -0.35% slower
performance.compilation 90.96 88.77 1.02 2.4% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.93 8.87 1.01 0.67% faster
pkpd/one_comp_mm_elim_abs.stan 30.0 32.7 0.92 -8.99% slower
sir/sir.stan 128.11 125.74 1.02 1.85% faster
gp_regr/gen_gp_data.stan 0.05 0.04 1.09 8.66% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.09 3.09 1.0 0.04% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.4 0.39 1.03 2.75% faster
arK/arK.stan 1.87 1.9 0.98 -1.57% slower
arma/arma.stan 0.63 0.65 0.98 -2.06% slower
garch/garch.stan 0.5 0.5 1.0 0.14% faster
Mean result: 1.00768454389

Jenkins Console Log
Blue Ocean
Commit hash: 99178e6


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Copy link
Copy Markdown
Collaborator

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

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

Looks good! Quick q for @rybern on the API pattern here and we should be good to go.

Comment thread src/stan/io/deserializer.hpp Outdated
* @return Unconstrained variable
*/
template <typename S, typename L, typename U>
inline auto free_lub(const S& y, const L& lb, const U& ub) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[optional] @rybern is it okay that the name pattern here is

free_{constrain_name}(object, {constrain_params});

Or would it be easier for you if we had the params come first like in the constrain functions?

Also @bbbales2 should we name these read_free_{constrain_name} and change the constrain functions to read_constrain_{constrain_name}? That would just help keep the API more consistent

Copy link
Copy Markdown

@rybern rybern Mar 12, 2021

Choose a reason for hiding this comment

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

I don't think that'll make it any easier or harder for me, up to you.

Edit: it would actually make it easier for me if lp__ came before the constraint parameters in the read constraint functions, but I should have mentioned that before and I can work around it.

This looks awesome!

Comment on lines +61 to +62
std::vector<std::vector<Eigen::VectorXd>> std_std_vec
= {{vec1, vec2}, {vec2, vec1}};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would have saved us a lot of code if I had remembered that std::vector versions just call the underlying and could have done them all in one go. Very nice!

Copy link
Copy Markdown
Collaborator

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

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

Actually Ben I goofed here approving this. The signature should match the read functions like

template <typename Ret, require_not_std_vector_t<Ret>* = nullptr>
  inline auto free_ordered(dims...) {

Our goal is to replace the code here

https://gist.github.com/SteveBronder/283a8cc24787383232d26590e207ba0c#file-original_model-hpp-L1076

      double x_param_scal;
      x_param_scal = std::numeric_limits<double>::quiet_NaN();
      x_param_scal = context__.vals_r("x_param_scal")[(1 - 1)];
      double x_param_scal_free__;
      x_param_scal_free__ = std::numeric_limits<double>::quiet_NaN();
      x_param_scal_free__ = stan::math::lb_free(x_param_scal, 0);

With code like

double x_param_scal_free__ = deserializer.read_free_lb<double>(0);

@bbbales2
Copy link
Copy Markdown
Member Author

@SteveBronder it was way easier to write tests with the serializer in place, so this will wait on that pull to go in.

There are a couple more changes I still need to add but will get them tomorrow or something:

  1. Write a unit test for the changes here (I may have broken other tests or something I'm not sure)
  2. Rename read_lb and stuff to read_constrain_lb etc.

@SteveBronder
Copy link
Copy Markdown
Collaborator

Aight the serializer pr should be good to go

@bbbales2 bbbales2 changed the title [WIP] Added prototype free functions to deserializer Added prototype free functions to deserializer Mar 15, 2021
@bbbales2 bbbales2 marked this pull request as ready for review March 15, 2021 20:06
@bbbales2
Copy link
Copy Markdown
Member Author

@SteveBronder This should be good to go once #3019 is in

@stan-buildbot
Copy link
Copy Markdown
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.42 3.54 0.97 -3.38% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.93 -7.25% slower
eight_schools/eight_schools.stan 0.11 0.11 0.97 -3.03% slower
gp_regr/gp_regr.stan 0.16 0.16 1.02 1.59% faster
irt_2pl/irt_2pl.stan 5.28 5.28 1.0 -0.04% slower
performance.compilation 91.12 88.47 1.03 2.91% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.87 8.9 1.0 -0.33% slower
pkpd/one_comp_mm_elim_abs.stan 29.76 29.63 1.0 0.46% faster
sir/sir.stan 128.64 127.88 1.01 0.59% faster
gp_regr/gen_gp_data.stan 0.04 0.03 1.02 1.75% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.08 3.09 1.0 -0.28% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.39 0.97 -2.98% slower
arK/arK.stan 1.89 1.93 0.98 -1.97% slower
arma/arma.stan 0.63 0.64 0.99 -1.03% slower
garch/garch.stan 0.51 0.51 1.0 -0.25% slower
Mean result: 0.991816551639

Jenkins Console Log
Blue Ocean
Commit hash: 1c9b79a


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@bbbales2
Copy link
Copy Markdown
Member Author

@serban-nicusor-toptal Looks like Jenkins is throwing out of space errors:

make/tests:93: recipe for target 'src/stan/io/dump.hpp-test' failed
make: *** [src/stan/io/dump.hpp-test] Error 1
make: *** Waiting for unfinished jobs....
test/dummy.cpp:1:22: fatal error: error writing to /tmp/ccAA3ozy.s: No space left on device
    1 | int main() {return 0;}

@stan-buildbot
Copy link
Copy Markdown
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.52 3.4 1.03 3.38% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.95 -5.25% slower
eight_schools/eight_schools.stan 0.11 0.11 0.98 -2.41% slower
gp_regr/gp_regr.stan 0.16 0.16 1.0 0.38% faster
irt_2pl/irt_2pl.stan 5.29 5.3 1.0 -0.25% slower
performance.compilation 90.81 88.49 1.03 2.56% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.91 8.92 1.0 -0.14% slower
pkpd/one_comp_mm_elim_abs.stan 29.29 29.33 1.0 -0.14% slower
sir/sir.stan 127.43 128.84 0.99 -1.11% slower
gp_regr/gen_gp_data.stan 0.04 0.04 1.0 0.48% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.13 3.08 1.02 1.55% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.39 0.95 -4.8% slower
arK/arK.stan 1.89 1.93 0.98 -2.15% slower
arma/arma.stan 0.65 0.63 1.02 2.37% faster
garch/garch.stan 0.52 0.51 1.02 1.77% faster
Mean result: 0.998085254286

Jenkins Console Log
Blue Ocean
Commit hash: 403c06c


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@SteveBronder
Copy link
Copy Markdown
Collaborator

@rybern fyi we are going with the signatures read() for basic reads, read_constrain_* for reading and constraining variables, and read_free_* for reading and free'ing variables

@bbbales2
Copy link
Copy Markdown
Member Author

@SteveBronder this is green

@SteveBronder
Copy link
Copy Markdown
Collaborator

Let me give it one quick read through though should be good

@rybern
Copy link
Copy Markdown

rybern commented Mar 17, 2021

@SteveBronder excellent

Copy link
Copy Markdown
Collaborator

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

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

Cool and good!

Comment thread src/stan/io/deserializer.hpp Outdated
Comment on lines +1064 to +1087
template <typename Ret>
inline auto read_free_simplex(size_t size) {
return stan::math::simplex_free(this->read<Ret>(size));
}

/**
* Read serialized simplices and unconstrain them
*
* @tparam Ret Type of output
* @tparam Sizes Types of dimensions of output
* @param vecsize Vector size
* @param sizes dimensions
* @return Unconstrained vectors
*/
template <typename Ret, typename... Sizes,
require_std_vector_t<Ret>* = nullptr>
inline auto read_free_simplex(size_t vecsize, Sizes... sizes) {
std::decay_t<Ret> ret;
ret.reserve(vecsize);
for (size_t i = 0; i < vecsize; ++i) {
ret.emplace_back(read_free_simplex<value_type_t<Ret>>(sizes...));
}
return ret;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this need a

  template <typename Ret, require_not_std_vector_t<Ret>* = nullptr>
  inline auto read_free_simplex(size_t size) {

Or nah because you can't have a std::vector simplex? I'm pretty sure now we don't need it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added it anyway for symmetry with everything else lol. Pretty sure we don't need it too cause the number of size arguments will define which thing gets used.

@SteveBronder
Copy link
Copy Markdown
Collaborator

It won't let me click the button for some reason but this is good to go!

goodcoolgood

@bbbales2
Copy link
Copy Markdown
Member Author

My merge button is here. I'll click it if @rok-cesnovar hasn't clicked it by the AM.

@stan-buildbot
Copy link
Copy Markdown
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.47 3.47 1.0 0.01% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.97 -2.83% slower
eight_schools/eight_schools.stan 0.11 0.11 1.01 0.71% faster
gp_regr/gp_regr.stan 0.16 0.16 1.0 -0.13% slower
irt_2pl/irt_2pl.stan 5.31 5.28 1.01 0.69% faster
performance.compilation 91.7 89.05 1.03 2.89% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.94 8.96 1.0 -0.21% slower
pkpd/one_comp_mm_elim_abs.stan 29.47 32.94 0.89 -11.79% slower
sir/sir.stan 128.9 128.51 1.0 0.31% faster
gp_regr/gen_gp_data.stan 0.03 0.04 0.95 -5.64% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.08 3.09 1.0 -0.23% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.41 0.4 1.02 1.8% faster
arK/arK.stan 1.9 1.9 1.0 -0.3% slower
arma/arma.stan 0.64 0.68 0.94 -6.1% slower
garch/garch.stan 0.51 0.52 0.98 -2.53% slower
Mean result: 0.985880330155

Jenkins Console Log
Blue Ocean
Commit hash: c5b5e24


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@rok-cesnovar rok-cesnovar merged commit b7229a2 into develop Mar 18, 2021
@rok-cesnovar rok-cesnovar deleted the feature/free-functions-deserializer branch March 18, 2021 06:05
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.

6 participants