code: def test_sequence_unpack_backprop(device_id):
      dev = cntk_device(device_id)
      input_vocab_size = 3
      emb_dim = 2
      hidden_dim = 2
      num_labels = 2
      x_seq_input = C.sequence.input_variable(
          input_vocab_size, is_sparse=True, name="features"
      )
      label_input = C.input_variable(
          num_labels, is_sparse=True, name="labels"
      )
      with C.default_options(initial_state=0.1):
          model = C.layers.Embedding(emb_dim, name="embed")(x_seq_input)
          model = C.layers.Recurrence(
              C.layers.LSTM(hidden_dim), go_backwards=False
          )(model)
          model = C.layers.Dense(num_labels, name="classify")(model)
  
      z = C.sequence.last(C.layers.Recurrence(C.plus)(model))
      ce = C.cross_entropy_with_softmax(z, label_input)
      seq1_data = [[0, 1, 1], [0, 1, 0], [1, 0, 0]]
      seq2_data = [[0, 0, 1], [0, 1, 1]]
      label_data = _to_csr([[0, 1], [1, 0]])
      param_grads_1, loss_result_1 = ce.grad(
          {
              x_seq_input: [_to_csr(seq1_data), _to_csr(seq2_data)],
              label_input: label_data,
          },
          wrt=ce.parameters,
          outputs=[ce],
          as_numpy=False,
      )
  
      z = C.sequence.reduce_sum(model)
      ce = C.cross_entropy_with_softmax(z, label_input)
      param_grads_2, loss_result_2 = ce.grad(
          {
              x_seq_input: [_to_csr(seq1_data), _to_csr(seq2_data)],
              label_input: label_data,
          },
          wrt=ce.parameters,
          outputs=[ce],
          as_numpy=False,
      )
  
      assert np.allclose(
          loss_result_1.asarray(), loss_result_2.asarray()
      )
  
      for param in param_grads_1:
          if not param_grads_1[param].is_sparse:
              reference_grad_value = param_grads_1[param].asarray()
              grad_value = param_grads_2[param].asarray()
              assert np.allclose(reference_grad_value, grad_value)
  
imports: from __future__ import division
  import numpy
  import pytest
  import cntk
  from .ops_test_utils import cntk_device
  from cntk.tests.test_utils import _to_dense, _to_csr
  from .ops_test_utils import unittest_helper, _test_unary_op, _test_binary_op, AA, precision, PRECISION_TO_TYPE, cntk_device
  from cntk import Value
  from cntk.axis import Axis
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
label_desc: Use image node_id 14 for calling a global function with example usage: test_sequence_unpack_backprop(device_id) without return types