Skip to content

Ly-kc/Pitorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pitorch

The first AI framewrok designed by myself, which is the final project of class "Programming in Artificial Intelligence"

TODO ✏️

  • Data preprocessing
  • Accelerate training

Code structure

The code is orgnized as follows:

├── data
│   └── MNIST
├── lib                     # C++ and Cuda code of pitorch
│   ├── cpu_func.h          # functions working on cpu
│   ├── cpu_func.cc          
│   ├── gpu_func.h          # functions working on gpu
│   ├── gpu_func.cu          
│   ├── Tensor.h            # Tensor class
│   ├── Tensor.cu          
│   ├── tensor_func.h       # wrapped cpu/gpu functions for Tensor
│   ├── tensor_func.cu          
│   ├── utils.h             # utils for error detection
│   ├── pybind.cpp          
│   └── setup.py            # install the lib
│
├── pitorch                    # Python code of pitorch
│   ├── __init__.py
│   ├── basic_operator.py      # basic elements for Computinng Graph
│   ├── Pisor.py               # difination of Pisor and Operators
│   ├── autodiff.py            # gradient back propagation
│   ├── optimizer.py           # optimizer zone 
│   ├── Unittest.py            # validate C++/Cuda operators
│   ├── test_forward.py        
│   ├── test_backward.py       
│   ├── train_fc_net.py        # train a fully connected network
│   ├── train_conv_net.py      # train a convolution network            
│   └── utils.py               # some util function (not finished yet)
└── README.md

Usage

Installation

conda create -n pitorch python=3.9
conda activate pitorch
# install pytorch according to your cuda version.
# (We just use torch.utils.cpp_extension to conveniently bind cuda code to python, and not utilize torch to conduct any operation)
cd lib
python setup.py develop

Running demo

You can start training on MNIST as follows.

cd pitorch
# train convolution network
python train_conv_net.py
# train fully connected network
python train_fc_net.py

On the bottom of training script, you can tweak hyper-parameters, select optimizers as well as change device.

Here is an example of training log:

Image

About

The first AI framewrok designed by myself, which is the final project of class 'Programming in Artificial Intelligence'.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published