code: def test_rnn(device_id):
      if device_id == -1:
          pytest.skip("Test only runs on GPU")
  
      batch_size = 8
      sequence_len = 100
      vocab_dim = 20
      embed_dim = 10
      hidden_dim = 7
      input = C.cast(C.sequence.input_variable(()), np.float16)
      with C.default_options(dtype=np.float16):
          embed = C.layers.Embedding(embed_dim)(
              C.one_hot(
                  input, num_classes=vocab_dim, sparse_output=False
              )
          )
          z = C.layers.Recurrence(C.layers.LSTM(hidden_dim))(embed)
  
      feed = np.floor(
          np.random.rand(batch_size, sequence_len).astype(np.float32)
          * (vocab_dim - 1)
      )
      z.grad(feed, wrt=z.parameters)
  
      num_layers = 2
      W = C.parameter(
          (C.InferredDimension, embed_dim),
          init=C.glorot_uniform(),
          dtype=np.float16,
      )
      with C.default_options(dtype=np.float16):
          z = C.optimized_rnnstack(embed, W, hidden_dim, num_layers)
  
      feed = np.floor(
          np.random.rand(batch_size, sequence_len).astype(np.float32)
          * (vocab_dim - 1)
      )
      z.grad(feed, wrt=z.parameters)
  
file_path: CNTK/bindings/python/cntk/ops/tests/fp16_test.py
imports: from __future__ import division
  import numpy
  import pytest
  from .ops_test_utils import _test_binary_op, AA, PRECISION_TO_TYPE, unittest_helper
  import cntk
label_desc: Use image node_id 5 for calling a global function with example usage: test_rnn(device_id) without return types