Repository: pytorch
Issue: LibTorch Release version 2.2.2+cpu loads traced model only in Debug configuration
Labels: module: binaries,triaged

### 🐛 Describe the bug

Hello,

In my C++ application the CMakeList.txt
``` cmake
cmake_minimum_required(VERSION 3.27)
project(TorchTest)

set(CMAKE_CXX_STANDARD 17)

set(Torch_DIR "C:/Users/hofma/Downloads/libtorch-win-shared-with-deps-2.2.2+cpu/libtorch/share/cmake/Torch")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(TorchTest main.cpp)

target_link_libraries(TorchTest PRIVATE ${TORCH_LIBRARIES})
```

For testing proposes I exported the resnet18 model in python
``` Python
import torch
import torchvision

model = torchvision.models.resnet18()

example = torch.rand(1, 3, 224, 224)

traced_script_module = torch.jit.trace(model, example)

traced_script_module.save("resnet.pt")
``` 
my C++ MWE is

``` cpp
#include <iostream>
#include "torch/script.h"

int main() {

    try
    {
        torch::jit::script::Module module = torch::jit::load("resnet.pt");
    }
    catch(const c10::Error& e)
    {
        std::cerr << "error loading the model\n";
    }
    return 0;
}
``` 
I use MSVC 17 to compile and this is my build command

C:\Users\hofma\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=C:/Users/hofma/AppData/Local/Programs/CLion/bin/ninja/win/x64/ninja.exe -G Ninja -S C:\Users\hofma\Documents\CodeTest\TorchTest -B C:\Users\hofma\Documents\CodeTest\TorchTest\cmake-build-release

Unfortunately the model is only load when I use the Debug configuration. Am I missing something to load the model in Release config or is it Bug related.

### Versions

PyTorch version: 2.2.2+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 Pro
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.27.0-rc4
Libc version: N/A

Python version: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.22631-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture=9
CurrentClockSpeed=3801
DeviceID=CPU0
Family=107
L2CacheSize=4096
L2CacheSpeed=
Manufacturer=AuthenticAMD
MaxClockSpeed=3801
Name=AMD Ryzen 7 5800X 8-Core Processor
ProcessorType=3
Revision=8448

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.2.2
[pip3] torchvision==0.17.2
[conda] blas                      1.0                         mkl
[conda] mkl                       2023.1.0         h6b88ed4_46358
[conda] mkl-service               2.4.0           py311h2bbff1b_1
[conda] mkl_fft                   1.3.8           py311h2bbff1b_0
[conda] mkl_random                1.2.4           py311h59b6b97_0
[conda] numpy                     1.24.3          py311hdab7c0b_1
[conda] numpy-base                1.24.3          py311hd01c5d8_1
[conda] torch                     2.2.2                    pypi_0    pypi
[conda] torchvision               0.17.2                   pypi_0    pypi

cc @seemethere @malfet @osalpekar @atalman