Skip to content

Commit 71e6ad4

Browse files
Add optimizers to FTorch (#320)
* Optimizer functionality added to FTorch. * A new module ftorch_optim added which contains implementations of SGD, Adam, and AdamW as well as core optimizer methods. Made available at top level ftorch. * Matches as closely as possible the behaviour from PyTorch. * A new worked example training a single tensor as part of a loop is included. * Comprehensive unit tests for each optimizer and core functionalities * Detailed documentation for Optimizer API and online training added.
1 parent 6e043d7 commit 71e6ad4

101 files changed

Lines changed: 2271 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/static_analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
fortitude check src/ftorch_types.f90
111111
fortitude check src/ftorch_tensor.f90
112112
fortitude check src/ftorch_model.f90
113+
fortitude check src/ftorch_optim.f90
113114
fortitude check src/ftorch_test_utils.f90
114115
115116
# Apply C++ and C linter and formatter, clang

.github/workflows/test_suite_macos_cpu_clang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ jobs:
224224
export Torch_DIR="${VIRTUAL_ENV}/lib/python${VN}/site-packages/torch"
225225
export FTORCH_INSTALL_DIR=/tmp/ftorch-install
226226
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${VIRTUAL_ENV}/lib/python${VN}/site-packages/torch/lib:${FTORCH_BUILD_DIR}/lib
227-
export EXAMPLE_BUILD_DIR="examples/2_SimpleNet/build"
227+
export EXAMPLE_BUILD_DIR="examples/02_SimpleNet/build"
228228
mkdir "${EXAMPLE_BUILD_DIR}"
229229
cd "${EXAMPLE_BUILD_DIR}"
230230
cmake .. \

.github/workflows/test_suite_ubuntu_cpu_gnu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ jobs:
230230
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
231231
export Torch_DIR="${VIRTUAL_ENV}/lib/python${VN}/site-packages/torch"
232232
export FTORCH_INSTALL_DIR="/tmp/ftorch-install"
233-
export EXAMPLE_BUILD_DIR="examples/2_SimpleNet/build"
233+
export EXAMPLE_BUILD_DIR="examples/02_SimpleNet/build"
234234
mkdir "${EXAMPLE_BUILD_DIR}"
235235
cd "${EXAMPLE_BUILD_DIR}"
236236
cmake .. \

.github/workflows/test_suite_ubuntu_cpu_intel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
146146
export Torch_DIR="${VIRTUAL_ENV}/lib/python${VN}/site-packages/torch"
147147
export FTORCH_INSTALL_DIR="/tmp/ftorch-install"
148-
export EXAMPLE_BUILD_DIR="examples/2_SimpleNet/build"
148+
export EXAMPLE_BUILD_DIR="examples/02_SimpleNet/build"
149149
mkdir "${EXAMPLE_BUILD_DIR}"
150150
cd "${EXAMPLE_BUILD_DIR}"
151151
cmake .. \

.github/workflows/test_suite_windows_cpu_intel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
set FTORCH_INSTALL_DIR=%TEMP%\ftorch-install
117117
set PATH=%FTORCH_INSTALL_DIR%\bin;%PATH%
118118
set PATH=%TORCH_PATH%\torch\lib;%PATH%
119-
set EXAMPLE_BUILD_DIR=examples\2_SimpleNet\build
119+
set EXAMPLE_BUILD_DIR=examples\02_SimpleNet\build
120120
if not exist %EXAMPLE_BUILD_DIR% mkdir %EXAMPLE_BUILD_DIR%
121121
cd %EXAMPLE_BUILD_DIR%
122122
cmake .. ^

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,6 @@ CMakeUserPresets.json
210210

211211
# Apple Desktop Services Store
212212
**.DS_Store
213+
214+
# Example outputs
215+
*.png

CHANGELOG.md

Lines changed: 9 additions & 1 deletion

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ endif()
113113
# Library with C and Fortran bindings
114114
add_library(${LIB_NAME} src/ctorch.cpp src/ftorch.f90 src/ftorch_devices.F90
115115
src/ftorch_types.f90 src/ftorch_tensor.f90
116-
src/ftorch_model.f90 src/ftorch_test_utils.f90)
116+
src/ftorch_model.f90 src/ftorch_optim.f90
117+
src/ftorch_test_utils.f90)
117118

118119
# Define compile definitions, including GPU devices
119120
target_compile_definitions(
@@ -187,6 +188,8 @@ install(FILES "${CMAKE_Fortran_MODULE_DIRECTORY}/ftorch_tensor.mod"
187188
DESTINATION "${CMAKE_INSTALL_MODULEDIR}")
188189
install(FILES "${CMAKE_Fortran_MODULE_DIRECTORY}/ftorch_model.mod"
189190
DESTINATION "${CMAKE_INSTALL_MODULEDIR}")
191+
install(FILES "${CMAKE_Fortran_MODULE_DIRECTORY}/ftorch_optim.mod"
192+
DESTINATION "${CMAKE_INSTALL_MODULEDIR}")
190193
install(FILES "${CMAKE_Fortran_MODULE_DIRECTORY}/ftorch_test_utils.mod"
191194
DESTINATION "${CMAKE_INSTALL_MODULEDIR}")
192195

0 commit comments

Comments
 (0)