Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPI warmup auto metric #821

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
aef5072
Added in switching adaptation
bbbales2 Apr 18, 2019
0b652a0
Changed 'Switching' to 'Auto'. Pointed stan submodule at modified ver…
bbbales2 Apr 20, 2019
58e5527
Merge branch 'develop' of https://github.com/stan-dev/cmdstan into ex…
bbbales2 Sep 4, 2019
f1fc292
Updated submodule
bbbales2 Sep 11, 2019
2e08a1a
update submodule
Jan 8, 2020
8ab2393
update submodule that works with radon model
Jan 15, 2020
5eb7e5c
stdout with 5-core run
Jan 15, 2020
813019f
update submodule
Jan 15, 2020
f802c23
fix gitmodules
Jan 15, 2020
ca2ae96
update submodule
Jan 15, 2020
c26eb9d
update submodule
Jan 15, 2020
c8f7291
add radon example readme
Jan 15, 2020
5e1a43a
update submodule
Jan 22, 2020
c84f519
update submodule
Jan 22, 2020
030350b
update submodule
Jan 22, 2020
bd68821
update submodule
Jan 22, 2020
f7e4337
each chain has its own output file when using cross-chain warmup
Jan 23, 2020
4e1a85d
update submodule
Jan 23, 2020
67c694f
random seed syncronization & cross-chain jitter
Jan 23, 2020
845dfa6
support user input of num_cross_chains in cmdstan
Jan 24, 2020
895d9ff
fix sequential run when no MPI flags are issued
Jan 24, 2020
fea759d
update submodules
Jan 26, 2020
80a0eb5
update submodule
Jan 28, 2020
189fc17
update submodule
Jan 29, 2020
df28673
mpi_warmup.mk in makefile. use MPI_ADAPTED_WARMUP = 1 in make/local
Jan 29, 2020
bdb9153
update submodule
Jan 29, 2020
6d34c23
update randon model readme
Jan 29, 2020
14a7522
cross_chain_window as adapt argument
Jan 30, 2020
2e12541
update doc
Jan 30, 2020
3c26404
typo
Jan 30, 2020
a5fba74
adapt cross_chain_ess argument
Jan 30, 2020
5e98460
sblrc-blr model example
Jan 30, 2020
ded8405
fix MPI output file name
Jan 30, 2020
53ba788
cross_chain_rhat argument
Jan 30, 2020
2d22968
default num_cross_chains to nb. of procs, err out when less
Jan 31, 2020
b64304c
awk to replace num_warmup in output csv with actual one
Feb 4, 2020
fe53576
Revert "awk to replace num_warmup in output csv with actual one"
Feb 4, 2020
b16d18d
add max_num_warmup for MPI warmup metadata
Feb 4, 2020
2047e1b
update submodule
Feb 5, 2020
a75f38b
update submodule
Feb 6, 2020
9357c93
init commit mpi_warmup_v2
Feb 7, 2020
d61a86f
point submodule to stan mpi_warmup_v2
Feb 7, 2020
b8e5768
update submodule
Feb 7, 2020
b40663d
mpi warmup for dense_e nuts
Feb 10, 2020
b3b9d26
update submodule
Feb 10, 2020
6aff628
cross-chain modify chain id instead of chain seed
Feb 11, 2020
f6c3bff
default cross_chain_ess to 200
Feb 11, 2020
c5f6cfd
update submodule
Feb 11, 2020
7d51bd0
update submodule
Feb 11, 2020
5a36981
update submodule
Feb 12, 2020
8648095
update submodule
Feb 13, 2020
cfc9f5f
Updated filename formatting to work with cmdstanr branch
bbbales2 Feb 15, 2020
3b34537
Merge branch 'feature/issue-2814-warmup-auto' into mpi_warmup_auto
bbbales2 Feb 15, 2020
cb1c199
auto metric might be working
bbbales2 Feb 17, 2020
a4bcdfd
Updated Stan module
bbbales2 Feb 18, 2020
f88ee55
Updated Stan submodule
bbbales2 Feb 18, 2020
031c525
Update Stan submodule
bbbales2 Feb 18, 2020
07be3d3
croos-chain warmup
Feb 24, 2020
3958ee7
cross-chain warmup
Feb 24, 2020
29577f5
Merge branch 'mpi_warmup_v2' into mpi_warmup_framework
Feb 24, 2020
fcb6c59
cleanup model examples results
Feb 24, 2020
61b9be4
update submodule
Feb 25, 2020
c7fae1b
update submodule
Feb 25, 2020
6163a7a
update submodule
Feb 25, 2020
998917e
update submodule
Feb 26, 2020
963fe7b
Merge remote-tracking branch 'origin/mpi_warmup_v2' into mpi_warmup_auto
bbbales2 Feb 26, 2020
5793859
Updated include path to flattened Math
bbbales2 Feb 28, 2020
00dc980
Merge remote-tracking branch 'origin/mpi_warmup_v2' into mpi_warmup_auto
bbbales2 Feb 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,048 changes: 1,048 additions & 0 deletions examples/radon/output.1.csv

Large diffs are not rendered by default.

1,048 changes: 1,048 additions & 0 deletions examples/radon/output.2.csv

Large diffs are not rendered by default.

1,048 changes: 1,048 additions & 0 deletions examples/radon/output.3.csv

Large diffs are not rendered by default.

1,048 changes: 1,048 additions & 0 deletions examples/radon/output.4.csv

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run1/output.csv.mpi.0

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run1/output.csv.mpi.1

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run1/output.csv.mpi.2

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run1/output.csv.mpi.3

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run2/output.csv.mpi.0

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run2/output.csv.mpi.1

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run2/output.csv.mpi.2

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run2/output.csv.mpi.3

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run3/output.csv.mpi.0

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run3/output.csv.mpi.1

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run3/output.csv.mpi.2

Large diffs are not rendered by default.

1,051 changes: 1,051 additions & 0 deletions examples/sblrc-blr/run3/output.csv.mpi.3

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/cmdstan/arguments/arg_auto_e.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CMDSTAN_ARGUMENTS_ARG_AUTO_E_HPP
#define CMDSTAN_ARGUMENTS_ARG_AUTO_E_HPP

#include <cmdstan/arguments/unvalued_argument.hpp>

namespace cmdstan {

class arg_auto_e: public unvalued_argument {
public:
arg_auto_e() {
_name = "auto_e";
_description = "Euclidean manifold that chooses between dense/diagonal metric at warmup";
}
};

}
#endif
26 changes: 26 additions & 0 deletions src/cmdstan/arguments/arg_max_num_warmup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef CMDSTAN_ARGUMENTS_ARG_MAX_NUM_WARMUP_HPP
#define CMDSTAN_ARGUMENTS_ARG_MAX_NUM_WARMUP_HPP

#include <cmdstan/arguments/singleton_argument.hpp>

namespace cmdstan {

class arg_max_num_warmup: public int_argument {
public:
arg_max_num_warmup(): int_argument() {
_name = "max_num_warmup";
_description = "Maximum number of warmup iterations";
_validity = "0 <= warmup";
_default = "1000";
_default_value = 1000;
_constrained = true;
_good_value = 2.0;
_bad_value = -1.0;
_value = _default_value;
}

bool is_valid(int value) { return value >= 0; }
};

}
#endif
2 changes: 2 additions & 0 deletions src/cmdstan/arguments/arg_metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cmdstan/arguments/arg_unit_e.hpp>
#include <cmdstan/arguments/arg_diag_e.hpp>
#include <cmdstan/arguments/arg_dense_e.hpp>
#include <cmdstan/arguments/arg_auto_e.hpp>

namespace cmdstan {

Expand All @@ -17,6 +18,7 @@ namespace cmdstan {
_values.push_back(new arg_unit_e());
_values.push_back(new arg_diag_e());
_values.push_back(new arg_dense_e());
_values.push_back(new arg_auto_e());

_default_cursor = 1;
_cursor = _default_cursor;
Expand Down
5 changes: 5 additions & 0 deletions src/cmdstan/arguments/arg_sample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cmdstan/arguments/categorical_argument.hpp>
#include <cmdstan/arguments/arg_num_samples.hpp>
#include <cmdstan/arguments/arg_max_num_warmup.hpp>
#include <cmdstan/arguments/arg_num_warmup.hpp>
#include <cmdstan/arguments/arg_save_warmup.hpp>
#include <cmdstan/arguments/arg_thin.hpp>
Expand All @@ -18,7 +19,11 @@ namespace cmdstan {
_description = "Bayesian inference with Markov Chain Monte Carlo";

_subarguments.push_back(new arg_num_samples());
#ifdef MPI_ADAPTED_WARMUP
_subarguments.push_back(new arg_max_num_warmup());
#else
_subarguments.push_back(new arg_num_warmup());
#endif
_subarguments.push_back(new arg_save_warmup());
_subarguments.push_back(new arg_thin());
_subarguments.push_back(new arg_adapt());
Expand Down
60 changes: 49 additions & 11 deletions src/cmdstan/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stan/services/optimize/lbfgs.hpp>
#include <stan/services/optimize/newton.hpp>
#include <stan/services/sample/fixed_param.hpp>
#include <stan/services/sample/hmc_nuts_auto_e_adapt.hpp>
#include <stan/services/sample/hmc_nuts_dense_e.hpp>
#include <stan/services/sample/hmc_nuts_dense_e_adapt.hpp>
#include <stan/services/sample/hmc_nuts_diag_e.hpp>
Expand Down Expand Up @@ -143,6 +144,10 @@ namespace cmdstan {
unsigned int cross_chain_window = 0;
double cross_chain_rhat = 0.0;
unsigned int cross_chain_ess = 0;

std::string output_file = dynamic_cast<string_argument*>(parser.arg("output")->arg("file"))->value();
std::string diagnostic_file = dynamic_cast<string_argument*>(parser.arg("output")->arg("diagnostic_file"))->value();

#ifdef MPI_ADAPTED_WARMUP
if (parser.arg("method")->arg("sample")) {
categorical_argument* adapt = dynamic_cast<categorical_argument*>(parser.arg("method")->arg("sample")->arg("adapt"));
Expand All @@ -157,10 +162,8 @@ namespace cmdstan {
stan::services::util::set_cross_chain_id(id, num_cross_chains);
id_arg -> set_value(static_cast<int>(id));

string_argument* ptr_out = dynamic_cast<string_argument*>(parser.arg("output")->arg("file"));
std::string f_out = ptr_out -> value();
stan::services::util::set_cross_chain_file(f_out, num_cross_chains);
ptr_out -> set_value(f_out);
stan::services::util::set_cross_chain_file(output_file, num_cross_chains);
stan::services::util::set_cross_chain_file(diagnostic_file, num_cross_chains);

info.set_num_chains(num_cross_chains);
err.set_num_chains(num_cross_chains);
Expand All @@ -176,17 +179,14 @@ namespace cmdstan {
stan::callbacks::writer init_writer;
stan::callbacks::interrupt interrupt;

std::fstream output_stream(dynamic_cast<string_argument*>(parser.arg("output")->arg("file"))->value().c_str(),
std::fstream::out);
std::fstream output_stream(output_file.c_str(), std::fstream::out);
#ifdef MPI_ADAPTED_WARMUP
stan::callbacks::mpi_stream_writer sample_writer(num_cross_chains, output_stream, "# ");
#else
stan::callbacks::stream_writer sample_writer(output_stream, "# ");
#endif


std::fstream diagnostic_stream(dynamic_cast<string_argument*>(parser.arg("output")->arg("diagnostic_file"))->value().c_str(),
std::fstream::out);
std::fstream diagnostic_stream(diagnostic_file.c_str(), std::fstream::out);
#ifdef MPI_ADAPTED_WARMUP
stan::callbacks::mpi_stream_writer diagnostic_writer(num_cross_chains, diagnostic_stream, "# ");
#else
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace cmdstan {
if (adapt_engaged == true && num_warmup == 0) {
info("The number of warmup samples (num_warmup) must be greater than zero if adaptation is enabled.");
return_code = stan::services::error_codes::CONFIG;
} else if (engine->value() == "nuts" && metric->value() == "dense_e" && adapt_engaged == false && metric_supplied == false) {
} else if (engine->value() == "nuts" && (metric->value() == "dense_e" || metric->value() == "auto_e") && adapt_engaged == false && metric_supplied == false) {
int max_depth = dynamic_cast<int_argument*>(dynamic_cast<categorical_argument*>(algo->arg("hmc")->arg("engine")->arg("nuts"))->arg("max_depth"))->value();
return_code = stan::services::sample::hmc_nuts_dense_e(model,
*init_context,
Expand All @@ -436,7 +436,7 @@ namespace cmdstan {
init_writer,
sample_writer,
diagnostic_writer);
} else if (engine->value() == "nuts" && metric->value() == "dense_e" && adapt_engaged == false && metric_supplied == true) {
} else if (engine->value() == "nuts" && (metric->value() == "dense_e" || metric->value() == "auto_e") && adapt_engaged == false && metric_supplied == true) {
int max_depth = dynamic_cast<int_argument*>(dynamic_cast<categorical_argument*>(algo->arg("hmc")->arg("engine")->arg("nuts"))->arg("max_depth"))->value();
return_code = stan::services::sample::hmc_nuts_dense_e(model,
*init_context,
Expand Down Expand Up @@ -495,6 +495,44 @@ namespace cmdstan {
init_writer,
sample_writer,
diagnostic_writer);
} else if (engine->value() == "nuts" && metric->value() == "auto_e" && adapt_engaged == true && metric_supplied == false) {
int max_depth = dynamic_cast<int_argument*>(dynamic_cast<categorical_argument*>(algo->arg("hmc")->arg("engine")->arg("nuts"))->arg("max_depth"))->value();
double delta = dynamic_cast<real_argument*>(adapt->arg("delta"))->value();
double gamma = dynamic_cast<real_argument*>(adapt->arg("gamma"))->value();
double kappa = dynamic_cast<real_argument*>(adapt->arg("kappa"))->value();
double t0 = dynamic_cast<real_argument*>(adapt->arg("t0"))->value();
unsigned int init_buffer = dynamic_cast<u_int_argument*>(adapt->arg("init_buffer"))->value();
unsigned int term_buffer = dynamic_cast<u_int_argument*>(adapt->arg("term_buffer"))->value();
unsigned int window = dynamic_cast<u_int_argument*>(adapt->arg("window"))->value();
return_code = stan::services::sample::hmc_nuts_auto_e_adapt(model,
*init_context,
random_seed,
id,
init_radius,
num_cross_chains,
cross_chain_window,
cross_chain_rhat,
cross_chain_ess,
num_warmup,
num_samples,
num_thin,
save_warmup,
refresh,
stepsize,
stepsize_jitter,
max_depth,
delta,
gamma,
kappa,
t0,
init_buffer,
term_buffer,
window,
interrupt,
logger,
init_writer,
sample_writer,
diagnostic_writer);
} else if (engine->value() == "nuts" && metric->value() == "dense_e" && adapt_engaged == true && metric_supplied == true) {
int max_depth = dynamic_cast<int_argument*>(dynamic_cast<categorical_argument*>(algo->arg("hmc")->arg("engine")->arg("nuts"))->arg("max_depth"))->value();
double delta = dynamic_cast<real_argument*>(adapt->arg("delta"))->value();
Expand Down
2 changes: 1 addition & 1 deletion stan
Submodule stan updated 49 files
+1 −1 src/stan/analyze/mcmc/autocovariance.hpp
+1 −1 src/stan/analyze/mcmc/compute_potential_scale_reduction.hpp
+1 −1 src/stan/io/dump.hpp
+1 −1 src/stan/io/reader.hpp
+1 −1 src/stan/io/stan_csv_reader.hpp
+1 −1 src/stan/io/writer.hpp
+1 −1 src/stan/mcmc/chains.hpp
+1 −1 src/stan/mcmc/covar_adaptation.hpp
+76 −0 src/stan/mcmc/hmc/hamiltonians/auto_e_metric.hpp
+69 −0 src/stan/mcmc/hmc/hamiltonians/auto_e_point.hpp
+1 −1 src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp
+79 −0 src/stan/mcmc/hmc/nuts/adapt_auto_e_nuts.hpp
+0 −1 src/stan/mcmc/hmc/nuts/adapt_diag_e_nuts.hpp
+26 −0 src/stan/mcmc/hmc/nuts/auto_e_nuts.hpp
+1 −1 src/stan/mcmc/hmc/nuts/base_nuts.hpp
+328 −0 src/stan/mcmc/mpi_auto_adaptation.hpp
+17 −16 src/stan/mcmc/mpi_covar_adaptation.hpp
+1 −0 src/stan/mcmc/mpi_metric_adaptation.hpp
+1 −0 src/stan/mcmc/mpi_var_adaptation.hpp
+1 −1 src/stan/mcmc/var_adaptation.hpp
+1 −1 src/stan/model/gradient.hpp
+1 −1 src/stan/model/indexing/lvalue.hpp
+1 −1 src/stan/model/indexing/rvalue.hpp
+1 −1 src/stan/model/log_prob_grad.hpp
+1 −1 src/stan/model/log_prob_propto.hpp
+1 −1 src/stan/optimization/bfgs.hpp
+197 −0 src/stan/services/sample/hmc_nuts_auto_e_adapt.hpp
+1 −1 src/stan/services/sample/hmc_nuts_dense_e.hpp
+1 −1 src/stan/services/sample/hmc_nuts_dense_e_adapt.hpp
+1 −1 src/stan/services/sample/hmc_nuts_diag_e.hpp
+1 −1 src/stan/services/sample/hmc_nuts_diag_e_adapt.hpp
+1 −1 src/stan/services/sample/hmc_nuts_unit_e.hpp
+1 −1 src/stan/services/sample/hmc_nuts_unit_e_adapt.hpp
+1 −1 src/stan/services/sample/hmc_static_dense_e.hpp
+1 −1 src/stan/services/sample/hmc_static_dense_e_adapt.hpp
+1 −1 src/stan/services/sample/hmc_static_diag_e.hpp
+1 −1 src/stan/services/sample/hmc_static_diag_e_adapt.hpp
+1 −1 src/stan/services/util/initialize.hpp
+8 −2 src/stan/services/util/mpi_cross_chain.hpp
+1 −1 src/stan/services/util/read_dense_inv_metric.hpp
+1 −1 src/stan/services/util/validate_dense_inv_metric.hpp
+1 −1 src/stan/services/util/validate_diag_inv_metric.hpp
+1 −1 src/stan/variational/base_family.hpp
+1 −1 src/stan/variational/families/normal_fullrank.hpp
+1 −1 src/stan/variational/families/normal_meanfield.hpp
+2 −1 src/stan/variational/print_progress.hpp
+7 −0 src/test/test-models/good/model/correlated_gaussian.stan
+7 −0 src/test/test-models/good/model/independent_gaussian.stan
+7 −0 src/test/test-models/good/model/known_hessian.stan