Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved file reader, concurrent inferences, runtime inference strategy selection #7

Merged
merged 56 commits into from
Oct 28, 2022

Conversation

rouson
Copy link
Contributor

@rouson rouson commented Oct 11, 2022

This PR will add a reader for the current network ASCII file format, including the square-bracketed array-of-array notation. The reader will detect and adapt to the size of a fully connected (dense) network with uniform layer size.

  • Read input weights
  • Read input biases
  • Read hidden layer weights
  • Read hidden layer biase
  • Read output weights
  • Read output biases
  • Example of concurrent inferences
  • A string utility that will likely be moved to the [Sourcery(https://github.com/sourceryinsitute/sourcery) library.
  • Runtime selection of inference method via the Strategy Pattern

This fills out the remainder of the truth table in the casess
tested for the XOR network.
This improves the formatting of the test output.
This commit starts the process of adding a reader for the file
formats that we currently output from PyTorch: ASCII text files
with square-bracketed arrays of arrays represented by
whitespace-delimited real values.  For example, in the current
format, an input file might represent a 2x3 input_weights array
as follows:

[[ 1.2E-06 2.5E-01]
[ 3.0E-02 6.1E-03]
[ 9.7E-04 5.4E-03]]

Future commits will add the capability to finish fully constructing
an inference_engine_t object by reading

1. Input-layer biases,
2. Hidden-layer weights and biases, and
3. Output layer weights and biases.
This commit refactors the current version of the read_network
procedure so that several code blocks become functions or
subroutines to facilitate greater reuse.
@JordanWelsman JordanWelsman added the enhancement New feature or request label Oct 14, 2022
This commit refactors the read_network subroutine so that

1. The one remaining internal function is pure,
2. All of read_network's impure procedures are internal subroutines
   that read an external file and have intent(in) arguments listed first,
   intent(out) arguments listed last, and no intent(inout) arguments.
3. Each of read_network's internal subroutines rewinds the passed
   file_unit at the beginning and end of the corresponding subroutine.
This commit adds

1. User-defined inquiry functions:
  * num_inputs
  * neurons_per_layer
  * num_hidden_layers
2. An assert_consistency subroutine that checks inference_engine_t
   component array bounds.

The new consistency check is invoked at the end of of the
read_network type-bound subroutine.
This commit adds assertions after every read statement that is not
inside a do while(io_status==0) loop.
@rouson rouson changed the title WIP: Improved file reader Improved file reader Oct 16, 2022
Rename write_after_read() test function to write_then_read() to
reflect the function's actual behavior.
This commit changes the write/read path of the write_after_read
test function's output/input file so that the file is written to
and read from the build tree in keeping with the best practice of
never modifying the source tree.  In addition to reducing the
likelihood of clobbering a user file, this change also makes it
easier to remove all build/test files with one `rm -rf build`
command.
This commit adds a string_t type so to support arrays of deferred-
length character variables and incorporates the new type into
several places where raw character variables were used previously.
This commmit matches the weights in the  write_then_read test to
those in the xor_truth_table test so that the XOR neural network
gets written (and read).  Now if that test output is copied into
four files named, for example, xor1, xor2, xor3, and xo4, then
the command

fpm run \
  --example concurrent-inference \
  -- --input-files "xor1 xor2 xor3 xor4"

will print

T T T T

indicating that each inference engine produced the expected result.
This commit introduces dynamic dispatch of inference methods via
the Strategy Pattern.  A new polymorphic inference_strategy_t
component of inference_engine_t serves as a hook on which to
hang an "infer" deferred binding.  Currently, the binding is
implemented only by a non-abstract concurrent_dot_products_t child
type that extends the inference_strategy_t parent and therefore
implements the "infer" binding.  All tests pass.  Future commits
will add one or more additional inference strategies, including a
matmul_t strategy that invokes the intrinsic matmul() function
instead of the "do concurrent"/dot_product blocks in the current
strategy.  We might then consider basing the choice of method on
real-time performance at program launch.
@rouson rouson changed the title Improved file reader and concurrent multi-inference demo Improved file reader, concurrent inferences, runtime inference strategy selection Oct 21, 2022
This commit removes the "module" keyword from the definition of
several internal functions that were non-conforming with the
keyword.
Because procedure pointer components can't be elemental, this
commit replaces activation procedure pointers with an activation
function bound to a step_t type.
This commit prepares for the the use of an activation strategy
to eliminate the current hardwiring of a step activation function.
This commit enables runtime selection of activation functions
in a way that allows for elemental execution fully and privately
encapsulated inside an inference_engine_t object.
This commit
1. Replaces one of three "do concurrent"/dot_product
   steps in matmul_t's infer procedure with a call to to the
   matmul intrinsic function.
2. Uses elemental inferrence to collapse three lines into
   one and to allow for automatic output array allocation,
   which will faciliate removal of the num_outputs argument.
This commit removes the the num_outputs, neurons_per_layer, and
num_layers arguments in the infer procedure and instead calculates
these values from the array bounds of the other arguments.
src/matmul_m.f90 Outdated Show resolved Hide resolved
Co-authored-by: Jordan Welsman <61209125+JordanWelsman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants