probcomp / Venturecxx

Primary implementation of the Venture probabilistic programming system
http://probcomp.csail.mit.edu/venture/
GNU General Public License v3.0
28 stars 6 forks source link

automatic, unwanted use of all available cores by the conditional multivariate normal #662

Open Schaechtle opened 7 years ago

Schaechtle commented 7 years ago

When the the conditional normal is called (e.g. by a GP) one of the routines of numpy that calls the BLAS library will cause computation to be automatically multi-threaded on all the cores a machine possesses. This can collide with ones own idea of parallelism (e.g. using resample_multiprocess) and make computation very slow.

To avoid this behaviour make sure to set this this environment variable: OPENBLAS_NUM_THREADS=1.

The effect can be reproduced by running the script below (henceforth called "test_cmvn.vnts")

define observations = linspace(-2, 2, 100);
assume covariance_matrix ~ inv_wishart(id_matrix(100), 100);
assume mean_vector =  fill(100,0);
assume mv_normal = () ~> {  multivariate_normal(mean_vector, covariance_matrix) };
observe mv_normal() = observations;
infer mh(default, all, 1000);

with and without the variable set:

$ venture -f  test_cmvn.vnts

vs.

$ OPENBLAS_NUM_THREADS=1 venture -f  test_cmvn.vnts

@marcoct was also bitten by this. I am not too sure how/where this should be documented. At the end of the day, computing the posterior covariance quickly is a desired aspect of running a single GP.

Suggested fix: we could display a warning whenever make_gp is called.

Opinions?