I used -O2 optimization。The following is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yy_trainer)

set(CMAKE_PREFIX_PATH /mnt/e/libtorch/libtorch)

include_directories(include)

list(APPEND SRCS src/trainer.cpp)
list(APPEND SRCS src/YYDataSet.cpp)

set(CMAKE_CXX_FLAGS "-g -O2")

find_package(Torch REQUIRED)
add_executable(yy_trainer ${SRCS})
target_link_libraries(yy_trainer "${TORCH_LIBRARIES}")
set_property(TARGET yy_trainer PROPERTY CXX_STANDARD 11)