-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add time values as sampler stats for NUTS #3986
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# limitations under the License. | ||
|
||
from collections import namedtuple | ||
import time | ||
|
||
import numpy as np | ||
import logging | ||
|
@@ -132,6 +133,9 @@ def _hamiltonian_step(self, start, p0, step_size): | |
|
||
def astep(self, q0): | ||
"""Perform a single HMC iteration.""" | ||
perf_start = time.perf_counter() | ||
process_start = time.process_time() | ||
|
||
p0 = self.potential.random() | ||
start = self.integrator.compute_state(q0, p0) | ||
|
||
|
@@ -166,6 +170,9 @@ def astep(self, q0): | |
|
||
hmc_step = self._hamiltonian_step(start, p0, step_size) | ||
|
||
perf_end = time.perf_counter() | ||
process_end = time.process_time() | ||
|
||
self.step_adapt.update(hmc_step.accept_stat, adapt_step) | ||
self.potential.update(hmc_step.end.q, hmc_step.end.q_grad, self.tune) | ||
if hmc_step.divergence_info: | ||
|
@@ -191,7 +198,13 @@ def astep(self, q0): | |
if not self.tune: | ||
self._samples_after_tune += 1 | ||
|
||
stats = {"tune": self.tune, "diverging": bool(hmc_step.divergence_info)} | ||
stats = { | ||
"tune": self.tune, | ||
"diverging": bool(hmc_step.divergence_info), | ||
"perf_counter_diff": perf_end - perf_start, | ||
"process_time_diff": process_end - process_start, | ||
"perf_counter_start": perf_start, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment on the name, and out of curiosity: why did switch from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I think the choice it kind of arbitrary. We can reconstruct the other one since we have the difference. |
||
} | ||
|
||
stats.update(hmc_step.stats) | ||
stats.update(self.step_adapt.stats()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: why not call this
perf_time_diff
? I find it more explicit and it matchesprocess_time_diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why
perf_time_diff
might be nicer, I just followed the naming of the function intime
, so that it's easier to see what clock is used exactly. Butcounter
is a bit confusing...