code: def label_smoothing_raw(x, target, padding_idx, smoothing):
      logprobs = torch.nn.functional.log_softmax(
          x, dim=-1, dtype=torch.float32
      )
  
      non_pad_mask = target != padding_idx
      nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1))
      nll_loss = nll_loss.squeeze(1)[non_pad_mask]
      smooth_loss = -logprobs.mean(dim=-1)[non_pad_mask]
      loss = (1.0 - smoothing) * nll_loss + smoothing * smooth_loss
      return loss
  
file_path: apex/apex/contrib/test/xentropy/test_label_smoothing.py
imports: import unittest
  import random
  import time
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: label_smoothing_raw(x, target, padding_idx, smoothing) and returns: loss