WillianFuks / tfcausalimpact

Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.
Apache License 2.0
593 stars 70 forks source link

Problems with the tensorflow_probability #61

Closed FlavioZanette closed 1 year ago

FlavioZanette commented 1 year ago

Hi @WillianFuks, after some months using your lib, today I tried to execuse a old notebook that was working 2 week ago and this error is show: "AttributeError: module 'tensorflow_probability.python.sts' has no attribute 'regularize_series'"

I saw this problem is similar to the issue 29 ( Getting an error #29 ) closed in 2021. Maybe it is a new update of the tensorflow lib?

WillianFuks commented 1 year ago

Hi @FlavioZanette ,

I just checked here the latest released version of TFP and regularize_series is still defined. There were no backwards incompatible changes.

What version of TFP and tfcausalimpact do you have installed on your machine? If you run pip install -U tfcausalimpact does it work?

FlavioZanette commented 1 year ago

I restarted my cluster and ran again, checked the versions: tensorflow==2.10.0 tensorflow-probability==0.14.0 tfcausalimpact==0.0.11

Now, this is the error message:

"WARNING:tensorflow:From /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py:458: StructuralTimeSeries.joint_log_prob (from tensorflow_probability.python.sts.structural_time_series) is deprecated and will be removed after 2022-03-01. Instructions for updating: Please use StructuralTimeSeries.joint_distribution(observed_time_series).log_prob WARNING:tensorflow:From /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/distributions/distribution.py:345: calling MultivariateNormalDiag.init (from tensorflow_probability.python.distributions.mvn_diag) with scale_identity_multiplier is deprecated and will be removed after 2020-01-01. Instructions for updating: scale_identity_multiplier is deprecated; please combine it into scale_diag directly instead. TypeError: in user code:

File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/causalimpact/model.py", line 368, in _run_vi  *
    tfp.vi.fit_surrogate_posterior(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/vi/optimization.py", line 301, in fit_surrogate_posterior  **
    return tfp_math.minimize(complete_variational_loss_fn,
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/math/minimize.py", line 346, in minimize
    initial_loss, initial_grads, initial_parameters = optimizer_step_fn(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/math/minimize.py", line 86, in optimizer_step
    loss = loss_fn()
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/vi/optimization.py", line 295, in complete_variational_loss_fn
    return variational_loss_fn(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/vi/csiszar_divergence.py", line 969, in monte_carlo_variational_loss
    return monte_carlo.expectation(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/monte_carlo/expectation.py", line 166, in expectation
    return tf.reduce_mean(f(samples), axis=axis, keepdims=keepdims)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/vi/csiszar_divergence.py", line 954, in divergence_fn
    target_log_prob = nest_util.call_fn(target_log_prob_fn, q_samples)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/internal/nest_util.py", line 286, in call_fn
    return fn(**args)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/structural_time_series.py", line 501, in log_joint_fn
    lgssm = self.make_state_space_model(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/structural_time_series.py", line 240, in make_state_space_model
    return self._make_state_space_model(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/components/sum.py", line 548, in _make_state_space_model
    component_ssms = self.make_component_state_space_models(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/components/sum.py", line 530, in make_component_state_space_models
    component.make_state_space_model(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/structural_time_series.py", line 240, in make_state_space_model
    return self._make_state_space_model(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/sts/components/regression.py", line 508, in _make_state_space_model
    predicted_timeseries = distribution_util.move_dimension(
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/internal/distribution_util.py", line 427, in move_dimension
    return ps.cond(ps.equal(source_idx, dest_idx), lambda: x, x_permuted)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/internal/prefer_static.py", line 252, in cond
    pred_value = _get_static_predicate(pred)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/internal/prefer_static.py", line 126, in _get_static_predicate
    pred_value = _get_static_value(pred)
File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/tensorflow_probability/python/internal/prefer_static.py", line 117, in _get_static_value
    pred_value = c_api.TF_TryEvaluateConstant_wrapper(pred.graph._c_graph,

TypeError: TF_TryEvaluateConstant_wrapper(): incompatible function arguments. The following argument types are supported:
    1. (arg0: tensorflow.python.client._pywrap_tf_session.TF_Graph, arg1: tensorflow.python.client._pywrap_tf_session.TF_Output) -> object

Invoked with: , 

"

WillianFuks commented 1 year ago

The error became even worse! Unfortunately it's outside of the causal package and I have no idea of what might be going on. It does seem to be something related to how tf was compiled on the cluster but it's just a wild guess.

Just wondering, does your script runs normally on another environment other than your cluster? This might indicate if it's something related to the cluster settings.

nicholas-miles-brex commented 1 year ago

I'm also seeing the same error TF_TryEvaluateConstant_wrapper(): incompatible function arguments. on a code that was previously running.

Is this a question to tensorflow?

nicholas-miles-brex commented 1 year ago

downgrading to tensorflow 2.9.2 fixed this issue for me

WillianFuks commented 1 year ago

Thanks @nicholas-miles-brex for the input. @FlavioZanette , does nicolas suggestion solves your issue?

I've been trying to replicate this error on my side but to no avail so far, it still seems to be something related to environment.

FlavioZanette commented 1 year ago

For me I was able to resolve the error by installing the tensorflow-probability==0.18.0 version. I still haven't been able to identify the cause, but for now, everything continues to work normally.