Skip to content

Commit

Permalink
Implemented added compilation units for new computational graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroarmas committed May 15, 2022
1 parent fe46ef7 commit 3461e26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif
VPATH = shared

MAIN = main.o
OBJS = main.o matrix.o generator.o matrix_printer.o functions.o network_layer.o m_algorithms_concepts.o m_algorithms.o m_algorithms_utilities.o m_algorithms_register.o matrix_benchmark.o activation_functions.o tensor.o tensor_forward_wrapper.o tensor_backwards_pass.o
OBJS = main.o matrix.o generator.o matrix_printer.o functions.o network_layer.o m_algorithms_concepts.o m_algorithms.o function_object_factory.o function_object_iterator.o m_algorithms_utilities.o m_algorithms_register.o matrix_benchmark.o activation_layer.o tensor.o tensor_factory.o tensor_forward_wrapper.o tensor_backwards_pass.o computational_graph_map.o
OBJS_FOR_UNIT_TEST = $(foreach obj, $(OBJS), $(filter-out $(MAIN), $(wildcard *.o)))


Expand Down
38 changes: 17 additions & 21 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
#include <memory>
#include <iostream>

#include "matrix.h"
#include "tensor_forward_wrapper.h"
#include "generator.h"
#include "matrix_printer.h"
#include "network_layer.h"
#include "activation_functions.h"
#include "activation_layer.h"
#include "m_algorithms.h"
#include "matrix_benchmark.h"
#include "context_object.h"
#include "function_object.h"


/*
model = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 512),
nn.ReLU(),
nn.Linear(512, 10),
)
X = torch.rand(1, 28, 28, device=device)
logits = model(X)
pred_probab = nn.Softmax(dim=1)(logits)
*/

int main(void) {

auto ma = std::make_shared<NeuralNetwork::Computation::Graph::Tensor>(Matrix::Rows(1), Matrix::Columns(2000));

auto ma = NeuralNetwork::Computation::Graph::TensorConstructor::create(Matrix::Rows(1), Matrix::Columns(2000));
auto ground_truth = NeuralNetwork::Computation::Graph::TensorConstructor::create(Matrix::Rows(1), Matrix::Columns(10),
NeuralNetwork::Computation::Graph::IsTrackable(true),
NeuralNetwork::Computation::Graph::IsLeaf(true),
NeuralNetwork::Computation::Graph::IsRecordable(true));

NeuralNetwork::Sequential model;

Expand All @@ -42,12 +33,17 @@ int main(void) {
std::make_unique<NeuralNetwork::MatrixMultiplyStep>(Matrix::Rows(1000), Matrix::Columns(10)),
std::make_unique<NeuralNetwork::AddStep>(Matrix::Columns(10))
));
model.add(std::make_unique<NeuralNetwork::ActivationFunctions::ReLU>());
model.add(std::make_unique<NeuralNetwork::ActivationFunctions::SoftMax>());

auto CE = NeuralNetwork::Computation::Graph::TensorOp(Matrix::Operations::Metric::CrossEntropy{});

for (int i = 0; i < 10; i++) {
auto out = model.forward(ma);
auto loss = CE(out, ground_truth);
loss->backwards();
}

auto out = model.forward(ma);

out->backwards();



Expand Down

0 comments on commit 3461e26

Please sign in to comment.