-
Notifications
You must be signed in to change notification settings - Fork 2.2k
attempt to fix warmup bookkeeping: dropped the tune stat #8015
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -92,6 +92,10 @@ def infer_warn_stats_info( | |
| sds[sname] = (dtype, None) | ||
| elif sds: | ||
| stats_dtypes.append({sname: dtype for sname, (dtype, _) in sds.items()}) | ||
|
|
||
| # Even when a step method does not emit any stats, downstream components still assume one stats "slot" per step method. represent that with a single empty dict. | ||
| if not stats_dtypes: | ||
| stats_dtypes.append({}) | ||
| return stats_dtypes, sds | ||
|
|
||
|
|
||
|
|
@@ -352,12 +356,6 @@ def flatten_steps(step: BlockedStep | CompoundStep) -> list[BlockedStep]: | |
|
|
||
|
|
||
| def check_step_emits_tune(step: CompoundStep | BlockedStep): | ||
|
Member
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. If this ends up working without tune, remove this function as well |
||
| if isinstance(step, BlockedStep) and "tune" not in step.stats_dtypes_shapes: | ||
| raise TypeError(f"{type(step)} does not emit the required 'tune' stat.") | ||
| elif isinstance(step, CompoundStep): | ||
| for sstep in step.methods: | ||
| if "tune" not in sstep.stats_dtypes_shapes: | ||
| raise TypeError(f"{type(sstep)} does not emit the required 'tune' stat.") | ||
| return | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,6 @@ class Metropolis(ArrayStepShared): | |
| stats_dtypes_shapes = { | ||
| "accept": (np.float64, []), | ||
| "accepted": (np.float64, []), | ||
| "tune": (bool, []), | ||
| "scaling": (np.float64, []), | ||
| } | ||
|
|
||
|
|
@@ -316,7 +315,6 @@ def astep(self, q0: RaveledVars) -> tuple[RaveledVars, StatsType]: | |
| self.steps_until_tune -= 1 | ||
|
|
||
| stats = { | ||
| "tune": self.tune, | ||
| "scaling": np.mean(self.scaling), | ||
| "accept": np.mean(np.exp(self.accept_rate_iter)), | ||
| "accepted": np.mean(self.accepted_iter), | ||
|
|
@@ -331,15 +329,13 @@ def competence(var, has_grad): | |
| @staticmethod | ||
| def _progressbar_config(n_chains=1): | ||
| columns = [ | ||
| TextColumn("{task.fields[tune]}", table_column=Column("Tuning", ratio=1)), | ||
|
Member
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. We'll need a work-around for this, as we still want to show whether we're in tuning or not in the progressbar |
||
| TextColumn("{task.fields[scaling]:0.2f}", table_column=Column("Scaling", ratio=1)), | ||
| TextColumn( | ||
| "{task.fields[accept_rate]:0.2f}", table_column=Column("Accept Rate", ratio=1) | ||
| ), | ||
| ] | ||
|
|
||
| stats = { | ||
| "tune": [True] * n_chains, | ||
| "scaling": [0] * n_chains, | ||
| "accept_rate": [0.0] * n_chains, | ||
| } | ||
|
|
@@ -351,7 +347,7 @@ def _make_progressbar_update_functions(): | |
| def update_stats(step_stats): | ||
| return { | ||
| "accept_rate" if key == "accept" else key: step_stats[key] | ||
| for key in ("tune", "accept", "scaling") | ||
| for key in ("accept", "scaling") | ||
| } | ||
|
|
||
| return (update_stats,) | ||
|
|
@@ -448,7 +444,6 @@ class BinaryMetropolis(ArrayStep): | |
|
|
||
| stats_dtypes_shapes = { | ||
| "accept": (np.float64, []), | ||
| "tune": (bool, []), | ||
| "p_jump": (np.float64, []), | ||
| } | ||
|
|
||
|
|
@@ -505,7 +500,6 @@ def astep(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType]: | |
| self.accepted += accepted | ||
|
|
||
| stats = { | ||
| "tune": self.tune, | ||
| "accept": np.exp(accept), | ||
| "p_jump": p_jump, | ||
| } | ||
|
|
@@ -574,9 +568,7 @@ class BinaryGibbsMetropolis(ArrayStep): | |
|
|
||
| name = "binary_gibbs_metropolis" | ||
|
|
||
| stats_dtypes_shapes = { | ||
| "tune": (bool, []), | ||
| } | ||
| stats_dtypes_shapes = {} | ||
|
|
||
| _state_class = BinaryGibbsMetropolisState | ||
|
|
||
|
|
@@ -594,8 +586,6 @@ def __init__( | |
| ): | ||
| model = pm.modelcontext(model) | ||
|
|
||
| # Doesn't actually tune, but it's required to emit a sampler stat | ||
| # that indicates whether a draw was done in a tuning phase. | ||
| self.tune = True | ||
| # transition probabilities | ||
| self.transit_p = transit_p | ||
|
|
@@ -649,10 +639,7 @@ def astep(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType]: | |
| if accepted: | ||
| logp_curr = logp_prop | ||
|
|
||
| stats = { | ||
| "tune": self.tune, | ||
| } | ||
| return q, [stats] | ||
| return q, [{}] | ||
|
|
||
| @staticmethod | ||
| def competence(var): | ||
|
|
@@ -695,9 +682,7 @@ class CategoricalGibbsMetropolis(ArrayStep): | |
|
|
||
| name = "categorical_gibbs_metropolis" | ||
|
|
||
| stats_dtypes_shapes = { | ||
| "tune": (bool, []), | ||
| } | ||
| stats_dtypes_shapes = {} | ||
|
|
||
| _state_class = CategoricalGibbsMetropolisState | ||
|
|
||
|
|
@@ -793,7 +778,7 @@ def astep_unif(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType | |
| logp_curr = logp_prop | ||
|
|
||
| # This step doesn't have any tunable parameters | ||
| return q, [{"tune": False}] | ||
| return q, [{}] | ||
|
|
||
| def astep_prop(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType]: | ||
| logp = args[0] | ||
|
|
@@ -811,7 +796,7 @@ def astep_prop(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType | |
| logp_curr = self.metropolis_proportional(q, logp, logp_curr, dim, k) | ||
|
|
||
| # This step doesn't have any tunable parameters | ||
| return q, [{"tune": False}] | ||
| return q, [{}] | ||
|
|
||
| def astep(self, apoint: RaveledVars, *args) -> tuple[RaveledVars, StatsType]: | ||
| raise NotImplementedError() | ||
|
|
@@ -919,7 +904,6 @@ class DEMetropolis(PopulationArrayStepShared): | |
| stats_dtypes_shapes = { | ||
| "accept": (np.float64, []), | ||
| "accepted": (bool, []), | ||
| "tune": (bool, []), | ||
| "scaling": (np.float64, []), | ||
| "lambda": (np.float64, []), | ||
| } | ||
|
|
@@ -1011,7 +995,6 @@ def astep(self, q0: RaveledVars) -> tuple[RaveledVars, StatsType]: | |
| self.steps_until_tune -= 1 | ||
|
|
||
| stats = { | ||
| "tune": self.tune, | ||
| "scaling": self.scaling, | ||
| "lambda": self.lamb, | ||
| "accept": np.exp(accept), | ||
|
|
@@ -1090,7 +1073,6 @@ class DEMetropolisZ(ArrayStepShared): | |
| stats_dtypes_shapes = { | ||
| "accept": (np.float64, []), | ||
| "accepted": (bool, []), | ||
| "tune": (bool, []), | ||
| "scaling": (np.float64, []), | ||
| "lambda": (np.float64, []), | ||
| } | ||
|
|
@@ -1213,7 +1195,6 @@ def astep(self, q0: RaveledVars) -> tuple[RaveledVars, StatsType]: | |
| self.steps_until_tune -= 1 | ||
|
|
||
| stats = { | ||
| "tune": self.tune, | ||
| "scaling": np.mean(self.scaling), | ||
| "lambda": self.lamb, | ||
| "accept": np.exp(accept), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
@michaelosthege what's the requirement here? Can we change things on mcbackend to not expect tune info attached to the steps?
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.
No we can not change that tune info must be attached to a step. See my comment in #7997 (comment).