You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ParallelReverseAutoDiff (PRAD) is a thread-safe C# library designed for reverse mode automatic differentiation, optimized for parallel computation and primed for the demands of modern machine learning applications and neural network training. It leverages semaphores and locks to orchestrate between threads, ensuring precision during gradient accumulation.
11
30
12
31
Upon the realm of code, a gem does shine,
@@ -42,6 +61,8 @@ Etched forever in code's vast story.
Each operation in PRAD is embodied as a node with forward and backward functions, facilitating the efficient calculation of derivatives. This design is particularly beneficial for large-scale problems and complex neural network architectures, where computational efficiency is paramount.
46
67
47
68
A standout feature of PRAD is its innovative use of the visitor pattern. The library includes a specialized 'Neural Network Visitor' which traverses neural network nodes across different threads. This visitor is tasked with gradient accumulation on nodes shared across multiple threads, allowing for parallelized computations while maintaining consistency and avoiding race conditions.
@@ -50,11 +71,9 @@ Moreover, PRAD introduces a data-driven approach to neural network architecture
50
71
51
72
PRAD's dynamic computational graph, constructed from JSON architecture, allows for the efficient computation of gradients, a crucial aspect of the backpropagation process used in training neural networks. This unique blend of features makes PRAD an efficient, scalable, and groundbreaking automatic differentiation solution.
52
73
53
-
## Prerequisites
74
+
###Prerequisites
54
75
Download and install the [Cuda Toolkit 12.0](https://developer.nvidia.com/cuda-12-0-0-download-archive) if you want to use the CudaMatrixMultiplyOperation.
55
76
56
-
## Supported Operations
57
-
58
77
### Regular Operations
59
78
AddGaussianNoiseOperation
60
79
@@ -140,7 +159,7 @@ DeepScaleAndShiftOperation
140
159
141
160
FlattenOperation
142
161
143
-
## Neural Network Parameters
162
+
###Neural Network Parameters
144
163
145
164
Each neural network base class has a set of parameters that can be used to configure the neural network. They are as follows:
@@ -287,7 +306,7 @@ The model element group's elements are stored in a matrix whose size is specifie
287
306
288
307
In this example, for the hidden layer, the first dimension is the number of layers and the second and third dimensions are the row and column sizes respectively.
289
308
290
-
### Create an architecture JSON file
309
+
### Understanding the JSON Architecture
291
310
292
311
Here is an example:
293
312
```json
@@ -636,15 +655,15 @@ The JSON defines the steps in a machine learning model's forward pass and also s
636
655
637
656
By defining the operations and their connections in a JSON file, the graph can be easily constructed and modified, and the computations can be automatically differentiated and parallelized. This representation makes it possible to define a wide variety of models in a modular way, using the building blocks provided by the library.
638
657
639
-
### Instantiate the architecture
658
+
### Instantiating the Architecture
640
659
641
660
Use a JSON serialization library like Newtonsoft.JSON to deserialize the JSON file to a JsonArchitecture object.
642
661
643
662
There are other JSON architectures available as well.
644
663
645
664
These include the 'NestedLayersJsonArchitecture', 'DualLayersJsonArchitecture', and 'TripleLayersJsonArchitecture'.
646
665
647
-
### Instantiate the computational graph
666
+
### Instantiating the Computational Graph
648
667
649
668
```c#
650
669
// Retrieve the matrices from the model layers created by the model layer builder.
@@ -740,7 +759,7 @@ this.computationGraph
740
759
741
760
Operation finders are a key component used to define and locate different operations in a neural network's computational graph. They're essentially functions that link to specific operations at different layers or time steps within the network. This is achieved by mapping string identifiers (IDs) to these operations, which are then used within a JSON architecture to establish the network's structure and sequence of computations. For example, an operation finder could link to a matrix multiplication operation in a specific layer of the network. By using these operation finders, developers can effectively manage complex computational graphs.
742
761
743
-
### Populate the backward dependency counts
762
+
### Populating the Backward Dependency Counts
744
763
745
764
Then populate the backward dependency counts by running the following code. It only has to be run once to set up the backward dependency counts.
746
765
```c#
@@ -754,7 +773,7 @@ for (int t = this.Parameters.NumTimeSteps - 1; t >= 0; t--)
754
773
}
755
774
```
756
775
757
-
### Run the forward pass
776
+
### Running the Forward Pass
758
777
```c#
759
778
varop=this.computationGraph.StartOperation??thrownewException("Start operation should not be null.");
760
779
IOperationBase?currOp=null;
@@ -779,14 +798,14 @@ do
779
798
while (currOp.Next!=null);
780
799
```
781
800
782
-
### Create a loss function
801
+
### Creating a Loss Function
783
802
Create a loss function like mean squared error, cross-entropy loss or using policy gradient methods.
784
803
785
804
Then calculate the gradient of the loss with respect to the output.
786
805
787
806
Plug the result in as the backward input for the backward start operation.
788
807
789
-
### Run the backward pass utilizing inherent parallelization
808
+
### Running the Backward Pass
790
809
```c#
791
810
IOperationBase?backwardStartOperation=null;
792
811
for (intt=this.Parameters.NumTimeSteps-1; t>=0; t--)
@@ -805,19 +824,19 @@ for (int t = this.Parameters.NumTimeSteps - 1; t >= 0; t--)
Cudablas.Instance.DeviceId=0; // set the GPU to use, defaults to 0
823
842
Cudablas.Instance.Initialize(); // initialize the CUDA library
@@ -894,14 +913,14 @@ In this example, the Forward method calculates the average of the features for e
894
913
895
914
This level of customization allows PRAD to be a versatile tool in the field of machine learning, capable of being tailored to a wide range of tasks, datasets, and innovative architectures.
896
915
897
-
## Support developer
916
+
## Support Developer
898
917
[](https://www.buymeacoffee.com/ameritusweb)
899
918
900
-
## Like the project?
919
+
## Star the Project
901
920
902
921
Give it a :star: Star!
903
922
904
-
## Found a bug?
923
+
## Reporting Bugs
905
924
906
925
Drop to [Issues](https://github.com/ameritusweb/ParallelReverseAutoDiff/issues)
0 commit comments