code: def get_weights_posterior(
      X: Tensor, y: Tensor, sigma_sq: Tensor
  ) -> MultivariateNormal:
      r"""Sample bayesian linear regression weights.
  
      Args:
          X: A tensor of inputs with shape `(*batch_shape, n num_rff_features)`.
          y: A tensor of outcomes with shape `(*batch_shape, n)`.
          sigma_sq: The likelihood noise variance. This should be a tensor with
              shape `kernel_batch_shape, 1, 1` if using a batched kernel.
              Otherwise, it should be a scalar tensor.
  
      Returns:
          The posterior distribution over the weights.
      """
      with torch.no_grad():
          X_trans = X.transpose(-2, -1)
          A = X_trans @ X + sigma_sq * torch.eye(
              X.shape[-1], dtype=X.dtype, device=X.device
          )
          # mean is given by: m = S @ x.T @ y, where S = A_inv
          # compute inverse of A using solves
          # covariance is A_inv * sigma
          L_A = psd_safe_cholesky(A)
          # solve L_A @ u = I
          Iw = torch.eye(L_A.shape[-1], dtype=X.dtype, device=X.device)
          u = torch.linalg.solve_triangular(L_A, Iw, upper=False)
  
          # solve L_A^T @ S = u
          A_inv = torch.linalg.solve_triangular(
              L_A.transpose(-2, -1), u, upper=True
          )
          m = (A_inv @ X_trans @ y.unsqueeze(-1)).squeeze(-1)
          L = psd_safe_cholesky(A_inv * sigma_sq)
          return MultivariateNormal(loc=m, scale_tril=L)
  
imports: from __future__ import annotations
  from copy import deepcopy
  from math import pi
  from typing import List, Optional
  import torch
  from botorch.models.converter import batched_to_model_list
  from botorch.models.deterministic import GenericDeterministicModel
  from botorch.models.model import Model, ModelList
  from botorch.models.model_list_gp_regression import ModelListGP
  from botorch.models.multitask import MultiTaskGP
  from botorch.utils.sampling import manual_seed
  from botorch.utils.transforms import is_ensemble
  from gpytorch.kernels import Kernel, MaternKernel, RBFKernel, ScaleKernel
  from linear_operator.utils.cholesky import psd_safe_cholesky
  from torch import Tensor
  from torch.distributions import MultivariateNormal
  from torch.nn import Module
label_desc: Use image node_id 5 for calling a global function with example usage: get_weights_posterior(X, y, sigma_sq) and returns: MultivariateNormal