code: def wrap_and_call(
      fn, acts, labels, device, input_lengths=None, target_lengths=None
  ):
      if not torch.is_tensor(acts):
          acts = torch.FloatTensor(acts)
  
      if "cuda" in device:
          acts = acts.cuda()
  
      if not acts.requires_grad:
          acts.requires_grad = True
  
      labels = torch.LongTensor(labels)
  
      if input_lengths is None:
          lengths = [acts.shape[1]] * acts.shape[0]
          lengths = torch.LongTensor(lengths)
      else:
          lengths = input_lengths
  
      if target_lengths is None:
          label_lengths = [len(l) for l in labels]
          label_lengths = torch.LongTensor(label_lengths)
      else:
          label_lengths = target_lengths
  
      if "cuda" in device:
          labels = labels.cuda()
          lengths = lengths.cuda()
          label_lengths = label_lengths.cuda()
  
      costs = fn(acts, labels, lengths, label_lengths)
      cost = torch.sum(costs)
      cost.backward()
  
      if "cuda" in device:
          torch.cuda.synchronize()
  
      if acts.grad is not None:
          grad = acts.grad.data.cpu().numpy()
      else:
          grad = None
  
      return costs.data.cpu().numpy(), grad
  
file_path: NeMo/tests/collections/asr/conftest.py
imports: from dataclasses import dataclass
  from typing import Optional, Type
  import numpy
  import pytest
  import torch
label_desc: Use image node_id 1 for calling the RNNTTestHelper obj's underlying member method code with example usage: obj.wrap_and_call(fn, acts, labels, device, input_lengths, target_lengths) and returns: costs,  grad