# Torch::jit::load fails with Unknown Type Name Error

**URL:** <https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257>\
**Category:** Mobile\
**Created:** [January 19, 2021, 1:29am UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257 "2021-01-19T01:29:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangrymangry](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hangrymangry/32/33564_2.png) [@hangrymangry](https://discuss.pytorch.org/u/hangrymangry)\
**Post date:** [January 19, 2021, 1:29am UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/1 "2021-01-19T01:29:34Z")

</div>

I am trying to implement Fast Neural Style Transfer on iOS application. To do that, I started with an implemented version of Fast Neural Style Transfer from [here](https://github.com/rrmina/fast-neural-style-pytorch) and attempt to follow [Pytorch Mobile tutorial](https://pytorch.org/mobile/ios/) by @xta0 to run the model on my device.

After generating the model.pt file, I tried to load it following the tutorial code using TorchModule. However, I got this error when loading the module.

> Unknown type name ‘ **torch**.torch.classes.xnnpack.TransposeConv2dOpContext’: Serialized File “code/ **torch** /transformer/\_\_\_torch\_mangle\_391.py”, line 18  
> **annotations** [“prepack\_folding.\_jit\_pass\_packed\_weight\_11”] = **torch**.torch.classes.xnnpack.Conv2dOpContext **annotations** [“prepack\_folding.\_jit\_pass\_packed\_weight\_12”] = **torch**.torch.classes.xnnpack.Conv2dOpContext **annotations** [“prepack\_folding.\_jit\_pass\_packed\_weight\_13”] = **torch**.torch.classes.xnnpack.TransposeConv2dOpContext ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \<— HERE  
> **annotations** [“prepack\_folding.\_jit\_pass\_packed\_weight\_14”] = **torch**.torch.classes.xnnpack.TransposeConv2dOpContext **annotations** [“prepack\_folding.\_jit\_pass\_packed\_weight\_15”] = **torch**.torch.classes.xnnpack.Conv2dOpContext (lldb)

Within Xcode, the code fails here

```auto
    private lazy var module: TorchModule = {
    // Verified that filePath exist.
    if let filePath = Bundle.main.path(forResource: "mobile_model2", ofType: "pt"),
        // The problem is at TorchModule init setup.
        let module = TorchModule(fileAtPath: filePath) {
        return module
    } else {
        fatalError("Can't find the model file!")
    }
}()

```

Code fails specifically at torch::jit::load

```auto
- (nullable instancetype)initWithFileAtPath:(NSString*)filePath {
  self = [super init];
  if (self) {
    try {
      // CODE FAILS HERE, when trying to load!
      _impl = torch::jit::load(filePath.UTF8String);
      _impl.eval();
    } catch (const std::exception& exception) {
      NSLog(@"%s", exception.what());
      return nil;
    }
  }
  return self;
}

```

This means that the C++ load method call wasn’t able to load my model.pt. What could possibly caused this?

In order to verify that this issue is not solely caused by my model, I tried loading this with another pretrained model resnet18. And as expected, I also receive errors while attempting to load this model using TorchModule, although with a different set of errors.

```auto
**Unknown builtin op: aten::_add_relu_.**

**Could not find any similar ops to aten::_add_relu_. This op may not exist or may not be currently supported in TorchScript.**

```

---

<div class="post-metadata">

**Author:** ![Shuai\_Xing](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shuai_xing/32/39503_2.png) [@Shuai\_Xing](https://discuss.pytorch.org/u/Shuai_Xing)\
**Post date:** [June 21, 2021, 7:18am UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/2 "2021-06-21T07:18:11Z")

</div>

I have the same issue, Pytorch-android 1.8.1 build from source. model exported by pytorch 1.8.1. have you solved this problem?

---

<div class="post-metadata">

**Author:** ![kimishpatel](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kimishpatel/32/39320_2.png) [@kimishpatel](https://discuss.pytorch.org/u/kimishpatel)\
**Post date:** [June 21, 2021, 3:31pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/3 "2021-06-21T15:31:58Z")

</div>

I think the issue is with the builds. Probably ops are not linked in. @xta0 any idea what might be the issue. @IvanKobzarev on the android side.

---

<div class="post-metadata">

**Author:** ![xta0](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xta0/32/17717_2.png) [@xta0](https://discuss.pytorch.org/u/xta0)\
**Post date:** [June 21, 2021, 4:26pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/4 "2021-06-21T16:26:49Z")

</div>

@hangrymangry what’s your pytorch version? Are you using cocoapods or building from source? @kimishpatel `TransposeConv2dOpContext ` is from the xnnpack rewrite, right?

---

<div class="post-metadata">

**Author:** ![kimishpatel](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kimishpatel/32/39320_2.png) [@kimishpatel](https://discuss.pytorch.org/u/kimishpatel)\
**Post date:** [June 21, 2021, 4:38pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/5 "2021-06-21T16:38:32Z")

</div>

Yes it is from xnnpack but likely the issue with op registration since, as mentioned, even `aten::_add_relu_` cannot be found.

---

<div class="post-metadata">

**Author:** ![MeijisIrlnd](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/meijisirlnd/32/52327_2.png) [@MeijisIrlnd](https://discuss.pytorch.org/u/MeijisIrlnd)\
**Post date:** [August 12, 2022, 2:58pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/6 "2022-08-12T14:58:58Z")

</div>

Sorry to resurrect this, but is there any update on it? I built LibTorch as a static lib for arm64 Mac, and get the same thing when I build from Xcode. Weirdly, it doesn’t seem to be an issue when using the recommended CMake stuff, but that isn’t really viable for me, and for me it’s erroring on this block :

```auto
m_models = {
    {MODEL_TYPE::BASS, torch::jit::load(modelPath + "/Bass.pt")},
    {MODEL_TYPE::DRUMS, torch::jit::load(modelPath + "/Drum.pt")},
    {MODEL_TYPE::VOCALS, torch::jit::load(modelPath + "/Vocal.pt")},
     {MODEL_TYPE::OTHERS, torch::jit::load(modelPath + "/Other.pt")}
};

```

Terminal output is:  
 ![Screenshot 2022-08-12 at 15.57.12](https://discuss.pytorch.org/uploads/default/original/3X/5/a/5a20d648d5c2687772b8040c6bdb2765d949e0a2.png)

---

<div class="post-metadata">

**Author:** ![kimishpatel](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kimishpatel/32/39320_2.png) [@kimishpatel](https://discuss.pytorch.org/u/kimishpatel)\
**Post date:** [August 12, 2022, 4:55pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/7 "2022-08-12T16:55:58Z")

</div>

Sorry but if did not mention repro steps, can you please do so. I can try to look at it later.

---

<div class="post-metadata">

**Author:** ![MeijisIrlnd](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/meijisirlnd/32/52327_2.png) [@MeijisIrlnd](https://discuss.pytorch.org/u/MeijisIrlnd)\
**Post date:** [August 12, 2022, 4:59pm UTC](https://discuss.pytorch.org/t/torch-load-fails-with-unknown-type-name-error/109257/8 "2022-08-12T16:59:11Z")

</div>

My bad, I actually managed to fix it by linking with  
`-Wl,-force_load,/path/to/libtorch.a`  
`-Wl,-force_load,/path/to/libtorch_cpu.a`  
after I just started trying to brute force it after googling for 3 hours haha
