code: def torch_softmax_with_temperature(
      model: Model, X: Floats2d, targets: Ints1d
  ) -> Tuple[Floats2d, Floats2d]:
      import torch
  
      Wt = xp2torch(model.get_param("W"))
      bt = xp2torch(model.get_param("b"))
      temperature = model.attrs["softmax_temperature"]
  
      Xt = xp2torch(X, requires_grad=True)
      Yt_gold = xp2torch(targets).long()
  
      XWbt = (Xt @ Wt) + bt
      XWbt_temp = XWbt / temperature
  
      loss = torch.nn.CrossEntropyLoss()
      output = loss(XWbt_temp, Yt_gold)
      output.backward()
  
      return cast(
          Floats2d,
          torch2xp(torch.nn.functional.softmax(XWbt_temp, dim=-1)),
      ), cast(Floats2d, torch2xp(cast(torch.Tensor, Xt.grad)))
  
file_path: thinc/thinc/tests/layers/test_softmax.py
imports: from typing import Tuple, cast
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from thinc.api import Model, NumpyOps, Softmax_v2
  from thinc.types import Floats2d, Ints1d
  from thinc.util import has_torch, torch2xp, xp2torch
label_desc: Use image node_id 2 for calling a global function with example usage: torch_softmax_with_temperature(model, X, targets) and returns: cast,  cast