code: def session_ids_to_lengths(
      session_ids: torch.Tensor, device: torch.device
  ) -> torch.Tensor:
      """
      Convert session_ids to lengths tensor. It is used in all session-wise loss
      computations.
  
      Args:
          session_ids: a tensor of session_ids,
              e.g., ["1", "2", "2"]
          device: the device to put session_ids into
  
      Returns:
          session_lengths(torch.Tensor): a tensor of session lengths, e.g., tensor([1, 2])
      """
  
      session_lengths: List[int] = []
      if len(session_ids) == 0:
          return torch.zeros(1)
      length = 1
      for i in range(len(session_ids) - 1):
          if session_ids[i] == session_ids[i + 1]:
              length += 1
          else:
              session_lengths.append(length)
              length = 1
      session_lengths.append(length)
  
      return torch.tensor(
          session_lengths, dtype=torch.int, device=device
      )
  
imports: from typing import Any, cast, Dict, List, Optional, Type
  import torch
  from torch import distributed
  from torchrec.metrics.metrics_config import RecComputeMode, RecTaskInfo
  from torchrec.metrics.metrics_namespace import MetricName, MetricNamespace, MetricPrefix
  from torchrec.metrics.rec_metric import MetricComputationReport, RecMetric, RecMetricComputation, RecMetricException
label_desc: Use image node_id 1 for calling a global function with example usage: session_ids_to_lengths(session_ids, device) and returns: torch, torch