From 3461e26066eb1e26ad8be3abf6fb8197c17974f4 Mon Sep 17 00:00:00 2001 From: Alejandro Armas Date: Sun, 15 May 2022 09:30:03 -0700 Subject: [PATCH] Implemented added compilation units for new computational graph. --- Makefile | 2 +- main.cpp | 38 +++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index ce572e1..ed95b7c 100644 --- a/Makefile +++ b/Makefile @@ -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))) diff --git a/main.cpp b/main.cpp index 2759d68..94e0439 100644 --- a/main.cpp +++ b/main.cpp @@ -1,35 +1,26 @@ #include #include -#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(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; @@ -42,12 +33,17 @@ int main(void) { std::make_unique(Matrix::Rows(1000), Matrix::Columns(10)), std::make_unique(Matrix::Columns(10)) )); - model.add(std::make_unique()); + model.add(std::make_unique()); + 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();