Comments (10)
Confirmed this, looking into it more
from bridgestan.
Okay, I compiled the same model with CmdStan and then ran ./grad diagnose init=p.json
where p.json was { "fvb": [1,2,3,4,5] }
, and this output the correct values for the gradient.
So, it seems like this is an issue only in BridgeStan somewhere
from bridgestan.
Additional findings:
Adding dummy real
parameters before the vector changes this behavior. With the first, only one zero appears in the gradient. With the second and onward, the gradient is correct.
Whenever the gradient is wrong, calling log_density_hessian seems to cause a segfault in stan::math::internal::reverse_pass_callback_vari
.
The only changes to the model's .hpp file with --O1 are the introduction of some conditional_var_value_t
s to the calls to the deserializer's read
- indicated SoA is being used.
from bridgestan.
Just posting, this isn't a Stan level error as I wrote a test here to see what's going on. I think it's something in bridgestan
from bridgestan.
And the plot thickens. Thanks all for looking into this. Much appreciated.
I had to add set_cmdstan_path!(...)
to get this MWE to run, but then with or without --O1
, this gives output (-27.5, [-1.0, -2.0, -3.0, -4.0, -5.0])
for me.
I compiled the model from the command line and not, and confirmed that the .hpp file contains return std::vector<std::string>{"stanc_version = stanc3 8fce5fb", "stancflags = --O1"};
.
macOS 12.2, Apple clang version 11.0.3, Julia 1.8.2, and I honestly don't know how to check my CmdStan version.
Has anyone narrowed this down to a specific higher level language? Does this happen in Python or R, for those of you that can recreate this?
from bridgestan.
@SteveBronder and I have been able to recreate this in the C example. We seem to have narrowed it down to the model functor, since replacing that with a lambda has resolved it for me
from bridgestan.
Thanks, @SteveBronder. I couldn't quite follow the test. Is it using a new gradient
functional that takes array arguments?
@roualdes or @WardBrian: Is that what is getting called to cause the error in BridgeStan?
Either way, I don't see how the -O1 vs -O0 could affect the soundness of the BridgeStan interface unless there are threading or memory issues somewhere introduced by the optimizations or in the interface.
from bridgestan.
The problem is with model_functor
. We're not sure exactly what is wrong, but it appears something is becoming nullpointer too soon in the autodiff stack. Replacing it with a more standard lambda resolves the issue, so I should have a PR ready soon.
from bridgestan.
For future reference if it ever comes up again, here is the code Steve and I were using to debug with gdb
:
#include "bridgestan.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
char* data;
if (argc > 1) {
data = argv[1];
} else {
data = "";
}
model_rng* model = construct(data, 123, 0);
if (!model) {
return 1;
}
printf("This model's name is %s.\n", name(model));
printf("It has %d parameters.\n", param_num(model, 0, 0));
double params[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
double val;
double* grad = malloc(5 * sizeof(double));
log_density_gradient(model, 1, 1, params, &val, grad);
printf("%f %f %f %f %f", grad[0], grad[1], grad[2], grad[3], grad[4]);
return destruct(model);
}
The easiest way to use this is to replace example.c
with it in the c-example folder and then link to the model provided in the original issue here.
from bridgestan.
Thanks, @SteveBronder. I couldn't quite follow the test. Is it using a new gradient functional that takes array arguments?
@bob-carpenter that function was just the log prob gradient call that bridgestan uses at the C level
from bridgestan.
Related Issues (20)
- Deadlock on Windows when unloading libraries in several threads HOT 1
- Python ctypes.CDDL compiled binary loading error HOT 5
- Can/should StanRNG API be more consistent across the interfaces? HOT 4
- Error in R/example.R HOT 1
- Hessian-vector product from stan-dev/math HOT 1
- Runtime errors during `param_unconstrain` because of precision issues HOT 7
- feature request: `theta_unc` taking multi dimensional arrays as input. HOT 6
- Error in `R/example.R` HOT 20
- Add to Getting Started doc necessary dependencies on Stan and Stan Math HOT 3
- Add to Getting Started doc recommendation to use --shallow-submodules HOT 5
- Add to Getting Started doc how to specify pre-existing Stan directory HOT 1
- Add to doc a section highlighting the functionality or lack there of across the interfaces HOT 3
- Julia tests require STAN_THREADS=true, doc this
- TBB path issue on Windows HOT 2
- Missing support for precompiled header HOT 25
- Tracking: Changes in the next version of Stan
- Better Error Message for Python Interface Automatically Downloading BridgeStan Source HOT 1
- bridgestan on Julia crashes on windows if .julia path has spaces HOT 5
- clang argument error during model compile on MacOS HOT 14
- Functionality necessary to nest Stan models in other PPLs HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bridgestan.