code: def forward(self, x, durations):
      # x: B x T x C
      out_lens = durations.sum(dim=1)
      max_len = out_lens.max()
      bsz, seq_len, dim = x.size()
      out = x.new_zeros((bsz, max_len, dim))
  
      for b in range(bsz):
          indices = []
          for t in range(seq_len):
              indices.extend([t] * utils.item(durations[b, t]))
          indices = torch.tensor(indices, dtype=torch.long).to(x.device)
          out_len = utils.item(out_lens[b])
          out[b, :out_len] = x[b].index_select(0, indices)
  
      return out, out_lens
  
imports: import logging
  import torch
  from torch import nn
  from fairseq import utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import FairseqEncoder, FairseqEncoderModel, register_model, register_model_architecture
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
  from fairseq.models.text_to_speech.tacotron2 import Postnet
  from fairseq.modules import FairseqDropout, LayerNorm, MultiheadAttention, PositionalEmbedding
label_desc: Use image node_id 1 for calling the LengthRegulator obj's underlying member method code with example usage: obj.forward(x, durations) and returns: out,  out_lens