Log metrics from a Pyro model

Hello! I have a question about logging metrics from scvi-tools. I am trying to create a model in Pyro based on the scvi-tools-skeleton, and I am wondering what is the “correct” way to log a metric?

For example, I compute a particular log probability in my Pyro “model()” as a regularization, and I want to log that as a metric. What’s the best way?

It seems like self.log("name", tensor) is only callable from a LightningModule, if I am understanding correctly. The Pyro module itself (from scvi-tools-skeleton) is a PyroBaseModuleClass, which does not seem to be a LightningModule, so I don’t think I can directly insert a self.log("name", tensor) statement into my Pyro “model()”.

Thanks so much! What a great codebase for the community!

I’m not a Pyro power user, but to make this work one would need to extract this value while the loss is being computed and then log it from within the PyroTrainingPlan.

If you find a general way to capture log probabilities from pyro we can certainly add this functionality.

Okay thanks! That definitely gets me on the right track.

I will try to give it some thought, as to whether there’s a good general way…