pyro-ppl/pyro

[FR] Predictive with deterministic site in the guide

Open

#3,358 建立於 2024年4月19日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)Python (981 fork)batch import
enhancementhelp wanted

倉庫指標

Star
 (8,211 star)
PR 合併指標
 (平均合併 10天 19小時) (30 天內合併 1 個 PR)

描述

Hi,

I'm working on a project where we would like to access the output of an NN in the guide when using Predictive. We've implemented it using a deterministic site in the guide. The program boils down to the following.

import pyro
from pyro.infer import Predictive
from pyro.distributions import Normal
import torch

def model():
    pyro.deterministic('m_deter', torch.tensor(1.))
    pyro.sample('x', Normal(torch.zeros(()), torch.ones(())))

def guide():
    pyro.deterministic('g_deter', torch.tensor(1.))
    pyro.sample('x', Normal(torch.zeros(()), torch.ones(())))


Predictive(
  model=model, 
  guide=guide, 
  return_sites=('model_site', 'guide_site', 'x'), 
  num_samples=1)() # Includes m_deter but not g_deter

We would like for both m_deter and g_deter to be included. It looks like Predictive currently only considers model sites for return sites. Would it be possible to expand it so we can include deterministic sites from the guide?

貢獻者指南