Error in HamiltonianMonteCarlo when using gather in log_prob function
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python, tensorflow
調査の方向性
提供された sample_hmc と logprob の再現から始め、tfp.mcmc.sample_chain、HamiltonianMonteCarlo、@tf.function の境界に焦点を当てます。tf.gather のケースと reduction のみのケースを比較し、グラフ実行を有効にしたまま、報告された構造エラーが解消され、サンプリングが引き続きサンプルと受理値を返すことを確認します。
索引モデルが issue の本文から書いたものです。
説明
I am trying to run a Hamiltonian MCMC on a target distribution whose implementation involves a call to tf.gather. The following code:
import tensorflow as tf
import tensorflow_probability as tfp
def sample_hmc(
target_log_prob_fn,
current_state,
num_results=1000,
num_burnin_steps=500,
adaptation_frac=0.8,
num_leapfrog_steps=3,
step_size=1.,
):
hmc = tfp.mcmc.SimpleStepSizeAdaptation(
tfp.mcmc.HamiltonianMonteCarlo(
target_log_prob_fn=target_log_prob_fn,
num_leapfrog_steps=num_leapfrog_steps,
step_size=step_size,
),
num_adaptation_steps=int(num_burnin_steps * adaptation_frac))
@tf.function
def run_chain():
samples, is_accepted = tfp.mcmc.sample_chain(
num_results=num_results,
num_burnin_steps=num_burnin_steps,
current_state=current_state,
kernel=hmc,
trace_fn=lambda _, pkr: pkr.inner_results.is_accepted,
)
return samples, is_accepted
return run_chain()
def logprob(alpha):
indices = tf.constant([2, 0, 1], dtype=tf.int32)
return -tf.math.reduce_sum(tf.gather(alpha**2, indices))
# return -tf.math.reduce_sum(alpha**2)
alpha = tf.constant([1.0, 1.0, 1.0])
sample_hmc(
logprob,
current_state=alpha,
num_results=10,
num_burnin_steps=5,
)
raises ValueError: The two structures don't have the same nested structure. followed by a very long and (to me) cryptic message. Replacing the return statement in the logprob function with the commented line gets rid of the error. The error seems to appear whenever the result of logprob contains a tf.gather subexpression.
The error also disappears when I remove the @tf.function decorator from the definition of run_chain. However, this comes at a huge performance cost.
How can I efficiently sample from a distribution whose log-probability involves a tf.gather expression?
- 主要言語
- Jupyter Notebook
- スター
- 4.4k
- フォーク
- 1.1k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tensorflow/probability のほかの issue
-
KL divergence between two `TransformedDistribution`s with a shared non-injective bijector (`AbsoluteValue`) returns the base KL対応中かも @Andreas-Hum が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
tensorflow/probability#2036 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
tensorflow/probability#2034 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
tensorflow/probability#2021 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
tensorflow/probability#2015 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
tensorflow/probability#2013 ·
tensorflow/probability の issue をすべて見る
似ている issue
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex fails対応中かも @vrjdev が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
DoubleML/doubleml-for-py#455 ·
メンテナーはふだん 1 日以内に返信
-
Install page: spectarf's CUDA engine fails with PyTorch for CUDA 13.0 (nvvmError: ERROR_INVALID_IR)対応中かも @lukepolson が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
PyTomography/PyTomography#435 ·
メンテナーはふだん 1 日以内に返信
-
beginner friendly
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
aws-samples/sample-per-model-bedrock#821 ·
メンテナーはふだん 1 日以内に返信
-
Strain created without dtype promotes the conservative+stress path to float64 under jax_enable_x64オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100