From 38a860eba157c2d468f9605d41b177c84e906296 Mon Sep 17 00:00:00 2001 From: lucasdelimanogueira Date: Wed, 29 May 2024 17:48:37 -0300 Subject: [PATCH 1/2] fix send to other devices and compile on cloud --- README.md | 18 ++++++++---------- build/Makefile | 2 +- examples/train.ipynb | 12 ++++++------ norch/csrc/tensor.cpp | 7 +++++++ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3524dfb..a6491be 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,9 @@ $ pip install norch or from cloning this repository ```css -$ sudo apt install nvidia-cuda-toolkit $ git clone https://github.com/lucasdelimanogueira/PyNorch.git -$ cd build -$ make -$ cd .. +$ cd PyNorch +$ pip install . -v ``` # 3 - Get started @@ -66,7 +64,7 @@ class MyModel(nn.Module): ```python import norch from norch.utils.data.dataloader import DataLoader -from norch.norchvision import transforms +from norch.norchvision import transforms as T import norch import norch.nn as nn import norch.optim as optim @@ -77,16 +75,16 @@ BATCH_SIZE = 32 device = "cuda" #cpu epochs = 10 -transform = transforms.Compose( +transform = T.Compose( [ - transforms.ToTensor(), - transforms.Reshape([-1, 784, 1]) + T.ToTensor(), + T.Reshape([-1, 784, 1]) ] ) -target_transform = transforms.Compose( +target_transform = T.Compose( [ - transforms.ToTensor() + T.ToTensor() ] ) diff --git a/build/Makefile b/build/Makefile index 5c36c07..edb67e9 100644 --- a/build/Makefile +++ b/build/Makefile @@ -13,7 +13,7 @@ CUDAFLAGS = -arch=sm_75 CUDALIBS = -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudart -lcuda # MPI flags and libraries -DISTRIBUTEDLIBS = -lmpi_cxx -lnccl +DISTRIBUTEDLIBS = -lmpi_cxx -lnccl -lmpi # Directories SRCDIR = ../norch/csrc diff --git a/examples/train.ipynb b/examples/train.ipynb index 427933a..21e61f7 100644 --- a/examples/train.ipynb +++ b/examples/train.ipynb @@ -34,7 +34,7 @@ "import norch.nn as nn\n", "import norch.optim as optim\n", "from norch.utils.data.dataloader import DataLoader\n", - "from norch.norchvision import transforms\n", + "from norch.norchvision import transforms as T\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import random\n", @@ -102,16 +102,16 @@ "device = \"cuda\" #cpu\n", "epochs = 10\n", "\n", - "transform = transforms.Compose(\n", + "transform = T.Compose(\n", " [\n", - " transforms.ToTensor(),\n", - " transforms.Reshape([-1, 784, 1])\n", + " T.ToTensor(),\n", + " T.Reshape([-1, 784, 1])\n", " ]\n", ")\n", "\n", - "target_transform = transforms.Sequential(\n", + "target_transform = T.Compose(\n", " [\n", - " transforms.ToTensor()\n", + " T.ToTensor()\n", " ]\n", ")\n", "\n", diff --git a/norch/csrc/tensor.cpp b/norch/csrc/tensor.cpp index 725b9f5..b1c9408 100644 --- a/norch/csrc/tensor.cpp +++ b/norch/csrc/tensor.cpp @@ -66,9 +66,12 @@ extern "C" { void to_device(Tensor* tensor, char* target_device) { int device_id = 0; char* endptr; + long num = strtol(target_device, &endptr, 10); if (*endptr == '\0') { device_id = (int)num; + target_device = new char[strlen("cuda") + 1]; + strcpy(target_device, "cuda"); } if ((strcmp(target_device, "cuda") == 0) && (strcmp(tensor->device, "cpu") == 0)) { @@ -78,6 +81,10 @@ extern "C" { else if ((strcmp(target_device, "cpu") == 0) && (strcmp(tensor->device, "cuda") == 0)) { cuda_to_cpu(tensor); } + + else { + printf("Could not send tensor to device %d", device_id); + } } Tensor* add_tensor(Tensor* tensor1, Tensor* tensor2) { From f3af107f3399628d6233faf1697ecb5445d5f471 Mon Sep 17 00:00:00 2001 From: lucasdelimanogueira Date: Wed, 29 May 2024 18:17:35 -0300 Subject: [PATCH 2/2] information ami test readme p3 aws --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a6491be..a1d13be 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Project details explanations can also be found on [medium](https://towardsdatasc **PyNorch** is a deep learning framework constructed using C/C++, CUDA and Python. This is a personal project with educational purpose only! `Norch` means **NOT** PyTorch, and we have **NO** claims to rivaling the already established PyTorch. The main objective of **PyNorch** was to give a brief understanding of how a deep learning framework works internally. It implements the Tensor object, GPU support and an automatic differentiation system. # 2 - Installation -Install this package from PyPi (you can test on Colab!) +Install this package from PyPi (you can test on Colab! Also tested on AWS p3 instances ami-00f1d513c2bb78c75) ```css $ pip install norch