Joint Prompt Optimization of Stacked LLMs using Variational Inference