MultiTaskGaussianProcessRegressionModel issue with tf.function
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python, tensorflow
调研方向
首先使用 tf.function 和形状为 [None, 1] 的 input_signature 重现该示例。检查 tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model.py,尤其是 _compute_flattened_covariance 以及报告的维度处理,然后验证该示例对于未知维度不再引发 UnboundLocalError。
由索引模型根据 Issue 内容生成。
描述
Hi, I have encountered an error when using tf.function decorator on a function calling MultiTaskGaussianProcessRegressionModel from the experimental package. The error occurs specifically when passing input_signature of unknown dimension to tf.function. Below are the details. Thanks!
Code
import tensorflow as tf
import tensorflow_probability as tfp
tfde = tfp.experimental.distributions
tfk = tfp.math.psd_kernels
tfke = tfp.experimental.psd_kernels
base_kernel = tfk.ExponentiatedQuadratic(
amplitude=tf.convert_to_tensor(0.6, tf.float64),
length_scale=tf.convert_to_tensor(0.5, tf.float64),
)
kernel = tfke.Independent(num_tasks=2, base_kernel=base_kernel)
observations = tf.constant([[0., 1.],[-0.5, -1.0]], tf.float64)
observation_index_points = tf.constant([[0],[1.0]], tf.float64)
@tf.function(input_signature=[tf.TensorSpec(shape=[None, 1], dtype=tf.float64)])
def predict(index_points):
gp = tfde.MultiTaskGaussianProcessRegressionModel(
kernel=kernel,
observations=observations,
observation_index_points=observation_index_points,
index_points=index_points,
)
return gp.mean()
predict(tf.constant([[0.2],[0.4],[0.6]], tf.float64))
The code above works:
- if we remove
tf.function, or - if we remove
input_signatureinside withtf.function
We get the following error if we set shape=[None, 1] inside tf.TensorSpec:
UnboundLocalError: in user code:
File "/tmp/ipykernel_299029/1064227357.py", line 24, in predict *
return gp.mean()
File "/usr/.local/lib/python3.12/site-packages/tensorflow_probability/python/distributions/distribution.py", line 1536, in mean **
return self._mean(**kwargs)
File "/usr/.local/lib/python3.12/site-packages/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model.py", line 852, in _mean
self._get_flattened_marginal_distribution(
File "/usr/.local/lib/python3.12/site-packages/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model.py", line 831, in _get_flattened_marginal_distribution
covariance = self._compute_flattened_covariance(index_points)
File "/usr/.local/lib/python3.12/site-packages/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model.py", line 811, in _compute_flattened_covariance
cholinv_kzx = observation_scale.solve(kxz, adjoint_arg=True)
UnboundLocalError: cannot access local variable 'dim' where it is not associated with a value
- 主要语言
- Jupyter Notebook
- 星标
- 4.4k
- 派生
- 1.1k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/probability 的其他 Issue
-
KL divergence between two `TransformedDistribution`s with a shared non-injective bijector (`AbsoluteValue`) returns the base KL可能已有人在做 @Andreas-Hum 于 8 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
tensorflow/probability#2036 ·
-
难度 3/5 1-2 天 新手友好度 68/100
tensorflow/probability#2034 ·
-
难度 5/5 一周以上 新手友好度 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 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
instadeepai/InstaNovo-FM#50 ·