code: def sequence_length_3D(sequence: torch.Tensor) -> torch.Tensor:
      """Returns the number of non-zero elements per sequence in batch.
  
      :param sequence: (torch.Tensor) A 3D tensor of shape [batch size x max sequence length x hidden size].
  
      # Return
      :returns: (torch.Tensor) The count on non-zero elements per sequence.
      """
      used = torch.sign(torch.amax(torch.abs(sequence), dim=2))
      length = torch.sum(used, 1)
      length = length.int()
      return length
  
imports: import math
  import os
  import warnings
  from abc import abstractmethod
  from functools import lru_cache
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import Module, ModuleDict
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import ENCODER_OUTPUT
  from ludwig.utils.strings_utils import SpecialSymbol
label_desc: Use image node_id 4 for calling a global function with example usage: sequence_length_3D(sequence) and returns: length