class_docstr: Defines the SVGDecoder model.
code: def render2cmd_v3_internal(self, features, hparams, train):
      # inputs and targets are both sequences with
      # shape = [batch, seq_len, 1, hparams.problem.feature_dim]
      targets = features["targets"]
      losses = {}
  
      sampled_bottleneck = self.pretrained_visual_encoder(
          features, hparams
      )
      if hparams.sg_bottleneck:
          sampled_bottleneck = tf.stop_gradient(sampled_bottleneck)
  
      with tf.variable_scope("render2cmd_v3_internal"):
          # override bottleneck, or return it, if requested
          if "bottleneck" in features:
              if (
                  common_layers.shape_list(features["bottleneck"])[0]
                  == 0
              ):
                  # return sampled_bottleneck,
                  # set losses['training'] = 0 so self.top() doesn't get called on it
                  return sampled_bottleneck, {"training": 0.0}
              else:
                  # we want to use the given bottleneck
                  sampled_bottleneck = features["bottleneck"]
  
          # finalize bottleneck
          unbottleneck_dim = (
              hparams.hidden_size * 2
          )  # twice because using LSTM
          if hparams.twice_decoder:
              unbottleneck_dim = unbottleneck_dim * 2
  
          # unbottleneck back to LSTMStateTuple
          dec_initial_state = []
          for hi in range(hparams.num_hidden_layers):
              unbottleneck = self.unbottleneck(
                  sampled_bottleneck,
                  unbottleneck_dim,
                  name_append="_{}".format(hi),
              )
              dec_initial_state.append(
                  rnn.LSTMStateTuple(
                      c=unbottleneck[:, : unbottleneck_dim // 2],
                      h=unbottleneck[:, unbottleneck_dim // 2 :],
                  )
              )
  
          dec_initial_state = tuple(dec_initial_state)
  
          shifted_targets = common_layers.shift_right(targets)
          # Add 1 to account for the padding added to the left from shift_right
          targets_length = (
              common_layers.length_from_embedding(shifted_targets) + 1
          )
  
          # LSTM decoder
          hparams_decoder = copy.copy(hparams)
          if hparams.twice_decoder:
              hparams_decoder.hidden_size = 2 * hparams.hidden_size
  
          if hparams.mode == tf_estimator.ModeKeys.PREDICT:
              decoder_outputs, _ = self.lstm_decoder_infer(
                  common_layers.flatten4d3d(shifted_targets),
                  targets_length,
                  hparams_decoder,
                  features["targets_cls"],
                  train,
                  initial_state=dec_initial_state,
                  bottleneck=sampled_bottleneck,
              )
          else:
              decoder_outputs, _ = self.lstm_decoder(
                  common_layers.flatten4d3d(shifted_targets),
                  targets_length,
                  hparams_decoder,
                  features["targets_cls"],
                  train,
                  initial_state=dec_initial_state,
                  bottleneck=sampled_bottleneck,
              )
  
          ret = tf.expand_dims(decoder_outputs, axis=2)
  
      return ret, losses
  
imports: import copy
  from magenta.contrib import rnn
  from magenta.models.svg_vae import image_vae
  from magenta.models.svg_vae import svg_decoder_loss
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  from tensor2tensor.utils import trainer_lib
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 3 for calling the SVGDecoder obj's underlying member method code with example usage: obj.render2cmd_v3_internal(features, hparams, train) and returns: ret,  losses, sampled_bottleneck,  dict