neural-fortran

A parallel framework for deep learning

https://github.com/modern-fortran/neural-fortran

Science Score: 64.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org, scholar.google
  • Committers with academic emails
    2 of 12 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.3%) to scientific vocabulary

Keywords

cnn deep-learning fortran machine-learning neural-network parallel
Last synced: 4 months ago · JSON representation ·

Repository

A parallel framework for deep learning

Basic Info
  • Host: GitHub
  • Owner: modern-fortran
  • License: mit
  • Language: Fortran
  • Default Branch: main
  • Homepage:
  • Size: 19.6 MB
Statistics
  • Stars: 446
  • Watchers: 25
  • Forks: 92
  • Open Issues: 39
  • Releases: 24
Topics
cnn deep-learning fortran machine-learning neural-network parallel
Created over 7 years ago · Last pushed 5 months ago
Metadata Files
Readme Contributing License Citation

README.md

neural-fortran

A parallel framework for deep learning. Read the paper here.

Features

  • Training and inference of dense (fully connected), convolutional (1-d and 2-d), and transformer neural networks
  • Stochastic gradient descent optimizers: Classic, momentum, Nesterov momentum, RMSProp, Adagrad, Adam, AdamW
  • More than a dozen activation functions and their derivatives
  • Loss functions and metrics: Quadratic, Mean Squared Error, Pearson Correlation etc.
  • Data-based parallelism
  • Loading dense and convolutional models from Keras HDF5 (.h5) files (see the nf-keras-hdf5 add-on)

Available layers

| Layer type | Constructor name | Supported input layers | Rank of output array | Forward pass | Backward pass | |------------|------------------|------------------------|----------------------|--------------|---------------| | Input | input | n/a | 1, 2, 3 | n/a | n/a | | Embedding | embedding | n/a | 2 | ✅ | ✅ | | Dense (fully-connected) | dense | input1d, dense, dropout, flatten | 1 | ✅ | ✅ | | Dropout | dropout | dense, flatten, input1d | 1 | ✅ | ✅ | | Locally connected (2-d) | locally_connected | input, locally_connected, conv, maxpool, reshape | 2 | ✅ | ✅ | | Convolutional (1-d and 2-d) | conv | input, conv, maxpool, reshape | 2, 3 | ✅ | ✅ | | Max-pooling (1-d and 2-d) | maxpool | input, conv, maxpool, reshape | 2, 3 | ✅ | ✅ | | Linear (2-d) | linear2d | input2d, layernorm, linear2d, self_attention | 2 | ✅ | ✅ | | Self-attention | self_attention | input2d, layernorm, linear2d, self_attention | 2 | ✅ | ✅ | | Layer Normalization | layernorm | linear2d, self_attention | 2 | ✅ | ✅ | | Flatten | flatten | input2d, input3d, conv1d, conv2d, maxpool1d, maxpool2d, reshape | 1 | ✅ | ✅ | | Reshape (1-d to 2-d or 3-d) | reshape | dense, dropout, flatten, input1d | 2, 3 | ✅ | ✅ |

Getting started

Get the code:

git clone https://github.com/modern-fortran/neural-fortran cd neural-fortran

Dependencies

Required dependencies are:

  • A Fortran compiler
  • fpm or CMake to build the code

Optional dependencies are:

  • OpenCoarrays (for parallel execution with GFortran)
  • BLAS, MKL, or similar (for offloading matmul and dot_product calls)
  • curl (for downloading testing and example datasets)

Compilers tested include:

  • flang-new 20.0.0
  • gfortran 13.2.0, 14.0.1
  • ifort 2021.13.1
  • ifx 2024.2.1

Building with fpm

Building in serial mode

With gfortran, the following will create an optimized build of neural-fortran:

fpm build --profile release

Building in parallel mode

If you use GFortran and want to run neural-fortran in parallel, you must first install OpenCoarrays. Once installed, use the compiler wrappers caf and cafrun to build and execute in parallel, respectively:

fpm build --compiler caf --profile release --flag "-cpp -DPARALLEL"

Testing with fpm

fpm test --profile release

For the time being, you need to specify the same compiler flags to fpm test as you did in fpm build so that fpm knows it should use the same build profile.

See the Fortran Package Manager for more info on fpm.

Building with CMake

Building in serial mode

mkdir build cd build cmake .. make

Tests and examples will be built in the bin/ directory.

Building in parallel mode

If you use GFortran and want to run neural-fortran in parallel, you must first install OpenCoarrays. Once installed, use the compiler wrappers caf and cafrun to build and execute in parallel, respectively:

FC=caf cmake .. -DPARALLEL make cafrun -n 4 bin/mnist # run MNIST example on 4 cores

Building with a different compiler

If you want to build with a different compiler, such as Intel Fortran, specify FC when issuing cmake:

FC=ifort cmake ..

for a parallel build of neural-fortran, or

FC=ifort cmake ..

for a serial build.

Building with BLAS or MKL

To use an external BLAS or MKL library for matmul calls, run cmake like this:

cmake .. -DBLAS=-lblas

where the value of -DBLAS should point to the desired BLAS implementation, which has to be available in the linking path. This option is currently available only with gfortran.

Building in debug mode

To build with debugging flags enabled, type:

cmake .. -DCMAKE_BUILD_TYPE=debug

Running tests with CMake

Type:

ctest

to run the tests.

Using neural-fortran in your project

You can use the CMake module available here to find or fetch an installation of this project while configuring your project. This module makes sure that the neural-fortran::neural-fortran target is always generated regardless of how the neural-fortran is included in the project.

First, either copy Findneural-fortran.cmake to, say, your project's cmake directory and then include it in your CMakeLists.txt file:

cmake list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") or use the CMAKE_MODULE_PATH variable to point to the directory where it is installed.

Next you need to set neural-fortran_ROOT_DIR to the directory where neural-fortran is installed such that neural-fortran_ROOT_DIR/lib/libneural-fortran.a exists.

The following should be added in the CMake file of your directory:

cmake if(NOT TARGET neural-fortran::neural-fortran) find_package(neural-fortran REQUIRED) endif()

and then to use the target in your project:

cmake target_link_libraries(your_target PRIVATE neural-fortran::neural-fortran)

Examples

The easiest way to get a sense of how to use neural-fortran is to look at examples, in increasing level of complexity:

  1. simple: Approximating a simple, constant data relationship
  2. sine: Approximating a sine function
  3. dense_mnist: Hand-written digit recognition (MNIST dataset) using a dense (fully-connected) network
  4. cnn_mnist: Training a CNN on the MNIST dataset
  5. getsetnetwork_params: Getting and setting hyperparameters of a network.

The examples also show you the extent of the public API that's meant to be used in applications, i.e. anything from the nf module.

Examples 3-6 rely on curl to download the needed datasets, so make sure you have it installed on your system. Most Linux OSs have it out of the box. The dataset will be downloaded only the first time you run the example in any given directory.

If you're using Windows OS or don't have curl for any other reason, download mnist.tar.gz directly and unpack in the directory in which you will run the example program.

API documentation

API documentation can be generated with FORD. Assuming you have FORD installed on your system, run

ford ford.md

from the neural-fortran top-level directory to generate the API documentation in doc/html. Point your browser to doc/html/index.html to read it.

Contributing

This Contributing guide briefly describes the code organization. It may be useful to read if you want to contribute a new feature to neural-fortran.

Acknowledgement

Thanks to all open-source contributors to neural-fortran: awvwgk, certik, ggoyman, ivan-pi, jacobwilliams, jvdp1, jvo203, mathomp4, milancurcic, OneAdder, pirpyn, rico07, rouson, rweed, Spnetic-5, and scivision.

Development of convolutional networks and Keras HDF5 adapters in neural-fortran was funded by a contract from NASA Goddard Space Flight Center to the University of Miami. Development of optimizers is supported by the Google Summer of Code 2023 project awarded to Fortran-lang.

NASA logo GSoC logo

Related projects

  • Fortran Keras Bridge (FKB) by Jordan Ott provides a Python bridge between old (v0.1.0) neural-fortran style save files and Keras's HDF5 models. As of v0.9.0, neural-fortran implements the full feature set of FKB in pure Fortran, and in addition supports training and inference of convolutional networks.
  • rte-rrtmgp-nn by Peter Ukkonen is an implementation based on old (v0.1.0) neural-fortran which optimizes for speed and running on GPUs the memory layout and forward and backward passes of dense layers.
  • Inference Engine developed at the Berkeley Lab by the Computer Languages and Systems Software (CLaSS) group.

Impact

Neural-fortran has been used successfully in over a dozen published studies. See all papers that cite it here.

Owner

  • Name: Modern Fortran
  • Login: modern-fortran
  • Kind: organization

Companion code for Modern Fortran: Building Efficient Parallel Applications

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use neural-fortran, please cite it as below."
authors:
- family-names: "Curcic"
  given-names: "Milan"
  orcid: "https://orcid.org/0000-0002-8822-7749"
title: "neural-fortran"
version: 0.5.0
date-released: 2022-06-10
url: "https://github.com/modern-fortran/neural-fortran"
preferred-citation:
  type: article
  authors:
  - family-names: "Curcic"
    given-names: "Milan"
    orcid: "https://orcid.org/0000-0002-8822-7749"
  doi: "10.1145/3323057.3323059"
  journal: "ACM SIGPLAN Fortran Forum"
  month: 3
  start: 4 # First page number
  end: 21 # Last page number
  title: "A parallel Fortran framework for neural networks and deep learning"
  issue: 1
  volume: 38
  year: 2019

GitHub Events

Total
  • Create event: 5
  • Release event: 3
  • Issues event: 19
  • Watch event: 41
  • Delete event: 1
  • Member event: 2
  • Issue comment event: 154
  • Push event: 13
  • Pull request review comment event: 85
  • Pull request review event: 98
  • Pull request event: 33
  • Fork event: 17
Last Year
  • Create event: 5
  • Release event: 3
  • Issues event: 19
  • Watch event: 41
  • Delete event: 1
  • Member event: 2
  • Issue comment event: 154
  • Push event: 13
  • Pull request review comment event: 85
  • Pull request review event: 98
  • Pull request event: 33
  • Fork event: 17

Committers

Last synced: almost 2 years ago

All Time
  • Total Commits: 260
  • Total Committers: 12
  • Avg Commits per committer: 21.667
  • Development Distribution Score (DDS): 0.185
Past Year
  • Commits: 29
  • Committers: 5
  • Avg Commits per committer: 5.8
  • Development Distribution Score (DDS): 0.31
Top Committers
Name Email Commits
Milan Curcic c****o@g****m 212
Damian Rouson r****n@l****v 19
Michael Hirsch s****n 9
Vandenplas, Jeremie j****s@w****l 6
Saurabh Suresh Powar 6****5 6
Ivan i****c@t****e 2
Jacob Williams j****s 1
dacarnazzola 1****a 1
Pierre Payen (pirpyn) p****e@g****m 1
Goyman Gordey 4****n 1
Damian Rouson d****n@r****t 1
Pablo del Mazo Sevillano 4****o 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 71
  • Total pull requests: 82
  • Average time to close issues: 8 months
  • Average time to close pull requests: 11 days
  • Total issue authors: 25
  • Total pull request authors: 15
  • Average comments per issue: 2.44
  • Average comments per pull request: 2.84
  • Merged pull requests: 65
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 11
  • Pull requests: 18
  • Average time to close issues: 9 days
  • Average time to close pull requests: 13 days
  • Issue authors: 6
  • Pull request authors: 4
  • Average comments per issue: 0.09
  • Average comments per pull request: 5.44
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • milancurcic (36)
  • rouson (5)
  • ricor07 (4)
  • aminiussi (4)
  • jvo203 (3)
  • ivan-pi (2)
  • Beliavsky (2)
  • jacobwilliams (1)
  • elahpeca (1)
  • acferrad (1)
  • sidmishfpl1801 (1)
  • rweed (1)
  • jeffhammond (1)
  • OneAdder (1)
  • serfcity (1)
Pull Request Authors
  • milancurcic (43)
  • jvdp1 (16)
  • OneAdder (8)
  • Spnetic-5 (6)
  • rouson (5)
  • jvo203 (3)
  • ricor07 (3)
  • mathomp4 (2)
  • certik (2)
  • Riccardo231 (1)
  • castelao (1)
  • jacobwilliams (1)
  • pablomazo (1)
  • dacarnazzola (1)
Top Labels
Issue Labels
enhancement (28) bug (7) question (5) good first issue (1)
Pull Request Labels
enhancement (27) bug (7)

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 24
proxy.golang.org: github.com/modern-fortran/neural-fortran
  • Versions: 24
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 4 months ago

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v2 composite
  • fortran-lang/setup-fpm v4 composite