You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just a note on two optimizations we could do when writing parameters.
Description:
When sampling with nuts the mcmc_writer generates the parameters it needs to write and then sends the parameters as a std::vector to a writer. For cmdstan the writer is the unique_stream_writer that writes to disk.
We call this function decently often and I think we could do a few things to both speed it up while being a little nicer to the system so we can write faster.
unique_stream_writer for a std::vector calls its write_vector member function. This function takes each value in the vector and one at a time write them to disk. Instead of many small calls for writing to disk we should have a string buffer inside of the unique_stream_writer that we write all of the values to first. Then we just write one large buffer to disk once instead of many times.
Inside of mcmc_writer::write_sample_params we keep making the std::vector<double> values for each call. Instead we can put those vectors directly in the mcmc_writer class. That would make mcmc_writer stateful in terms of memory, but to my knowledge we never call an mcmc_writer instance from multiple threads and idt it would make sense to. If we did not want to add state to mcmc_writer we could also pass mcmc_writer::write_sample_params a local allocator to reuse memory.
These optimizations would not really matter for small problems. But once we start getting to 100K+ parameter models reading and writing to disk can be an issue.
Current Version:
v2.36.0
The text was updated successfully, but these errors were encountered:
Summary:
Just a note on two optimizations we could do when writing parameters.
Description:
When sampling with nuts the
mcmc_writer
generates the parameters it needs to write and then sends the parameters as astd::vector
to awriter
. For cmdstan the writer is theunique_stream_writer
that writes to disk.We call this function decently often and I think we could do a few things to both speed it up while being a little nicer to the system so we can write faster.
unique_stream_writer
for astd::vector
calls itswrite_vector
member function. This function takes each value in the vector and one at a time write them to disk. Instead of many small calls for writing to disk we should have a string buffer inside of theunique_stream_writer
that we write all of the values to first. Then we just write one large buffer to disk once instead of many times.Inside of
mcmc_writer::write_sample_params
we keep making thestd::vector<double> values
for each call. Instead we can put those vectors directly in themcmc_writer
class. That would makemcmc_writer
stateful in terms of memory, but to my knowledge we never call anmcmc_writer
instance from multiple threads and idt it would make sense to. If we did not want to add state tomcmc_writer
we could also passmcmc_writer::write_sample_params
a local allocator to reuse memory.These optimizations would not really matter for small problems. But once we start getting to 100K+ parameter models reading and writing to disk can be an issue.
Current Version:
v2.36.0
The text was updated successfully, but these errors were encountered: