code: def torch_cross_entropy(
      batch_size: int,
      seq_length: int,
      vocab_size: int,
      logits_scale: float,
      seed: int,
      label_smoothing: float = 0.0,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      set_random_seed(seed)
      identity = IdentityLayer(
          (batch_size, seq_length, vocab_size), scale=logits_scale
      ).cuda()
      logits = identity()
      target = torch.cuda.LongTensor(
          size=(batch_size, seq_length)
      ).random_(0, vocab_size)
      loss = (
          F.cross_entropy(
              logits.view(-1, logits.size()[-1]),
              target.view(-1),
              reduction="none",
              label_smoothing=label_smoothing,
          )
          .view_as(target)
          .mean()
      )
      loss.backward()
      return loss, identity.weight.grad
  
imports: import logging
  from typing import Tuple
  import torch
  import torch.nn.functional
  from torch.testing._internal import common_utils
  from apex.transformer import parallel_state
  from apex.transformer import tensor_parallel
  from apex.transformer.tensor_parallel import cross_entropy
  from apex.transformer.testing.commons import set_random_seed, IdentityLayer
  from apex.transformer.testing.distributed_test_base import NcclDistributedTestBase
  from apex.transformer.testing.distributed_test_base import UccDistributedTestBase
label_desc: Use image node_id 1 for calling a global function with example usage: torch_cross_entropy(batch_size, seq_length, vocab_size, logits_scale, seed, label_smoothing) and returns: loss,  identity