Open jaburgoyne opened 1 year ago
Hello,
I hit this one as well with open_cl. I did not even set STAN_THREADS or STAN_OPENCL globally. The steps were simply
cpp_options = list(stan_opencl = TRUE)
exe_file
option without recompiling(If these steps are not clear enough, I'd be happy to write up an MRE with code.)
Sampling will fail with the erroneous claim that the model was not compiled with stan_opencl = true
. I think @jaburgoyne has correctly identified the root cause. I believe switching the assertions to check the uppercase version of the options would solve the issue without side effect.
@jgabry would you accept a PR to resolve this issue? If so, would you like to switch the checks to uppercase, model_compile_info
setting to lowercase, or something else?
@jaburgoyne (and anyone else who is having this problem), I was able to workaround this issue with this ugliness:
mod$.__enclos_env__$private$cpp_options_$stan_opencl <- TRUE
I went ahead and created a failing testcase for this issue: https://github.com/stan-dev/cmdstanr/compare/master...katrinabrock:cmdstanr:issue-765 (Just for the opencl part. We could create similar cases for the stan_threads part.)
Thanks @jaburgoyne for reporting this. And thanks @katrinabrock for doing more digging and creating the failing test case. A PR would be great, thank you!
It seems to me that lowercase would be the most consistent (and thus
model_compile_info()
should usetolower()
instead oftoupper()
here), but in case this has further-reaching consequences than I can see, I’m making an issue instead of a pull request.
This seems ok to me, but maybe @andrjohns has a different preference or can think of some issue with making this change.
The opencl tests seem to be not working in general. Some are failing, and some, I believe, are passing but not checking the thing they are trying to check. Is there a reason these tests are not included in CI? (I understand why you would not want them to run on CRAN, but is there a reason not to run them in the github actions?)
I've identified two issues so far:
opencl_ids_name
that I can't find referenced anywhere else in the code either in the current version or in the version where this test was introduced: https://github.com/stan-dev/cmdstanr/blob/master/tests/testthat/test-opencl.R#L85 There are possibly other issues with this test script. I think before (or maybe just in parallel to) addressing the issue mentioned in this thread, it would be good to get that test script to a state where tests are passing and actually testing the existing functionality. Maybe I should create a separate issue for this effort?
Made a PR to fix the tests: https://github.com/stan-dev/cmdstanr/pull/1022
I'd also be happy to help if there are steps needed to add this to CI e.g. find/configure a docker container that can run this.
Describe the bug
If threading is enabled globally by way of
STAN_THREADS=true
inmake/local
(as opposed to locally viacpp_options = list(stan_threads = TRUE)
in a call tomodel$compile()
),cmdstanr
does not respect the setting. Althoughmodel$cpp_options
isTRUE
for the keySTAN_THREADS
,assert_valid_threads()
only checks forstan_threads
in lowercase.Although threading is perhaps the most common use case, the same bug would apply to
STAN_OPENCL
and any other C++ option. To fix the bug,CmdStanModel
needs to standardise on all-caps or lowercase for its internalcpp_options
representation. It seems to me that lowercase would be the most consistent (and thusmodel_compile_info()
should usetolower()
instead oftoupper()
here), but in case this has further-reaching consequences than I can see, I’m making an issue instead of a pull request.To Reproduce
Set
STAN_THREADS=true
inmake/local
, compile a model, and then try to runmodel$sample()
withthreads_per_chain
set to some integer greater than 1.Expected behavior
The model should sample using multi-threading instead of complaining (erroneously) that the model has not been compiled with threading enabled.
Operating system
Although this should be platform-agnostic, I am running macOS 13.3.1 on an Apple M1 architecture.
CmdStanR version number
2.32.1
Additional context
None