title: Different results after converting pytorch to torchscript? Converting NSnumber to Float cause any loss?
body: <p>I converted the pytorch pretrained-model(.pt) to torchscript model(.pt) for using it in Swift 5(ios-iphone6s, xcode 11). In Swift, the “predict” function of the model gave me its embedding values(Tensor). Since it returned the NSNumber array as a result of prediction, I used type casting [NSNumber] to both [Double] or [Float] to calculate the distance between two embedding values. L2 normalization, dot product, etc.</p>
  
  <p>However, <strong>while the pytorch version got the correct answers, the torchscript model got so many wrong answers.</strong> Not only the answers are different, the distance calculations of the two embedding pairs in torchscript are also different from the results of the pytorch model on the PC(CPU, Pycharm). In fact, before using type casting for distance calculations, the embedding values in NSNumber(Swift) are so different from the values ​​in float32(pytorch). I used same input images.</p>
  
  <p>I tried to find the reason.. Once, I copied the embedding values( [NSNumber] ) ​​from swift-torchscript and calculated the distance between two embeddings in pytorch, to check if there was a problem with my distance calculation implementation in Swift. I used torch.FloatTensor to use type casting [NSNumber] -> [Float]. I also tried [Double]. As a result of this, I found many infinite numbers. Is this infinite numbers related to the wrong answer?</p>
  
  <p>What does this “inf” mean? Is it a calculation or type casting error? Did I lost information while casting from NSNumber to Float or Double? How could I get the correct value from the torchscript model in swift? <strong>What should I check?</strong></p>
  
  <p>I used the following codes to convert. pytorch -> torchscript.</p>
  
  <pre><code>import torch
  
  from models.inception_resnet_v1 import InceptionResnetV1
  
  device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
  
  resnet = InceptionResnetV1(pretrained='vggface2').eval().to(device)
  
  example = torch.rand(1, 3, 160, 160)
  traced_script_module = torch.jit.trace(resnet, example)
  traced_script_module.save("mobile_model.pt")
  </code></pre>