-
Notifications
You must be signed in to change notification settings - Fork 317
Open
Labels
Description
When working with the model, we needed to repeatedly request predictions of the model's factor contributions using sample_posterior_predictive
. The exact code used was:
samples = model.sample_posterior_predictive(
X_pred=X_test,
extend_idata=False,
include_last_observations=True,
original_scale=True,
var_names=["channel_contributions", "control_contributions", "yearly_seasonality_contribution"],
progressbar=False,
)
Each calculation took approximately 1.5 minutes, despite X_test containing only 52 rows. Attempts to speed up the transformations using compile_kwargs={'mode':'NUMBA'}
or compile_kwargs={'mode':'JAX'}
didn't result in any performance improvement.
However, when we modified the code to:
samples = model.sample_posterior_predictive(
X_pred=X_test,
extend_idata=False,
include_last_observations=True,
original_scale=False,
var_names=["channel_contributions", "control_contributions", "yearly_seasonality_contribution"],
progressbar=False,
)
contributions_over_time_test = pd.DataFrame(samples["channel_contributions"].mean(dim=["sample"]).values * model.get_target_transformer()["scaler"].scale_, columns=channel_columns, index=X_test.date)
The computation time was reduced to just 2 seconds. The experiments were conducted on versions 0.14.0 and 0.15.1