class_docstr: Model and training loop for the DVC model.
  
  Combines a pre-defined DVC model with its training loop for use with
  PyTorch Lightning.
  
  Args:
      model: The DVC model to train.
      training_stage: Current stage of training process. One of
          ``("1_motion_estimation", "2_motion_compression",
          "3_motion_compensation", "4_total")``. See DVC paper for details.
      pretrained_model_name: Name of model from CompressAI model zoo to use
          for compressing I-frames.
      pretrained_model_quality_level: Quality level of model from CompressAI.
      num_pframes: Number of P-frames to process for training.
      distortion_type: Type of distortion loss function. Must be from
          ``("MSE")``.
      distortion_lambda: A scaling factor for the distortion term of the
          loss.
      learning_rate: passed to the main network optimizer (i.e. the one that
          adjusts the analysis and synthesis parameters).
      aux_learning_rate: passed to the optimizer that learns the quantiles
          used to build the CDF table for the entropy codder.
      lr_scheduler_params: Used for ``StepLR``, specify ``step_size`` and
          ``gamma``.
class_docstr_tok: ["Model","and","training","loop","for","the","DVC","model",".","Combines","a","pre-defined","DVC","model","with","its","training","loop","for","use","with","PyTorch","Lightning",".","Args",":","model",":","The","DVC","model","to","train",".","training_stage",":","Current","stage","of","training","process",".","One","of","``","(","``","1_motion_estimation","''",",","``","2_motion_compression","''",",","``","3_motion_compensation","''",",","``","4_total","''",")","``",".","See","DVC","paper","for","details",".","pretrained_model_name",":","Name","of","model","from","CompressAI","model","zoo","to","use","for","compressing","I-frames",".","pretrained_model_quality_level",":","Quality","level","of","model","from","CompressAI",".","num_pframes",":","Number","of","P-frames","to","process","for","training",".","distortion_type",":","Type","of","distortion","loss","function",".","Must","be","from","``","(","``","MSE","''",")","``",".","distortion_lambda",":","A","scaling","factor","for","the","distortion","term","of","the","loss",".","learning_rate",":","passed","to","the","main","network","optimizer","(","i.e",".","the","one","that","adjusts","the","analysis","and","synthesis","parameters",")",".","aux_learning_rate",":","passed","to","the","optimizer","that","learns","the","quantiles","used","to","build","the","CDF","table","for","the","entropy","codder",".","lr_scheduler_params",":","Used","for","``","StepLR","``",",","specify","``","step_size","``","and","``","gamma","``","."]
code: def compute_loss_and_metrics(self, loss_values, current_metrics):
      # loss function collection
      combined_bpp = 0
      loss = loss_values.distortion_loss
      gop_distortion_loss = (
          current_metrics.gop_distortion_loss
          + loss_values.distortion_loss.detach()
      )
  
      if loss_values.flow_entropy_loss is not None:
          loss = loss + loss_values.flow_entropy_loss
          combined_bpp = (
              combined_bpp + loss_values.flow_entropy_loss.detach()
          )
          gop_flow_bpp: Optional[Tensor] = (
              current_metrics.gop_flow_bpp
              + loss_values.flow_entropy_loss.detach()
          )
      else:
          gop_flow_bpp = None
  
      if loss_values.resid_entropy_loss is not None:
          loss = loss + loss_values.resid_entropy_loss
          combined_bpp = (
              combined_bpp + loss_values.resid_entropy_loss.detach()
          )
          gop_residual_bpp: Optional[Tensor] = (
              current_metrics.gop_residual_bpp
              + loss_values.resid_entropy_loss.detach()
          )
      else:
          gop_residual_bpp = None
  
      gop_total_loss = current_metrics.gop_total_loss + loss.detach()
      gop_bpp = current_metrics.gop_bpp + combined_bpp
  
      return loss, LoggingMetrics(
          gop_total_loss=gop_total_loss,
          gop_distortion_loss=gop_distortion_loss,
          gop_bpp=gop_bpp,
          gop_flow_bpp=gop_flow_bpp,
          gop_residual_bpp=gop_residual_bpp,
      )
  
imports: from typing import NamedTuple, Optional, Tuple
  import torch
  import torch.optim
  import torchmetrics
  from _utils import DvcStage, DvcStage1, DvcStage2, DvcStage3, DvcStage4and5, LossFunctions
  from compressai.zoo import models
  from pytorch_lightning import LightningModule
  from torch import Tensor
  import neuralcompression.functional
  from neuralcompression.models import DVC
label_desc: Use image node_id 6 for calling the DvcModule obj's underlying member method code with example usage: obj.compute_loss_and_metrics(loss_values, current_metrics) and returns: loss,  LoggingMetrics