2020-03-20 11:43:35 +08:00
# Jittor: a Just-in-time(JIT) deep learning framework
2022-04-02 12:13:23 +08:00
![Jittor Logo ](https://cg.cs.tsinghua.edu.cn/jittor/favicon_package_v0/JittorLogo_Final1220.svg )
2021-09-30 16:04:29 +08:00
2022-08-11 17:53:50 +08:00
[Quickstart ](#quickstart ) | [Install ](#install ) | [Tutorial ](#tutorial ) | [简体中文 ](./README.cn.md )
2020-03-20 11:43:35 +08:00
2021-01-20 14:09:55 +08:00
Jittor is a high-performance deep learning framework based on JIT compiling and meta-operators. The whole framework and meta-operators are compiled just-in-time. A powerful op compiler and tuner are integrated into Jittor. It allowed us to generate high-performance code with specialized for your model. Jittor also contains a wealth of high-performance model libraries, including: image recognition, detection, segmentation, generation, differentiable rendering, geometric learning, reinforcement learning, etc. .
2020-03-20 11:43:35 +08:00
2021-01-20 14:09:55 +08:00
The front-end language is Python. Module Design and Dynamic Graph Execution is used in the front-end, which is the most popular design for deeplearning framework interface. The back-end is implemented by high performance language, such as CUDA,C++.
Related Links:
* [Jittor Website ](https://cg.cs.tsinghua.edu.cn/jittor/ )
* [Jittor Tutorials ](https://cg.cs.tsinghua.edu.cn/jittor/tutorial/ )
* [Jittor Models ](https://cg.cs.tsinghua.edu.cn/jittor/resources/ )
* [Jittor Documents ](https://cg.cs.tsinghua.edu.cn/jittor/assets/docs/index.html )
2021-01-20 22:44:12 +08:00
* [Github ](https://github.com/jittor/jittor ), [Gitee ](https://gitee.com/jittor/jittor )
2021-10-11 20:03:20 +08:00
* [Jittor Forum ](https://discuss.jittor.org/ )
2021-10-12 16:49:03 +08:00
* [Awesome Jittor List ](https://github.com/Jittor/jittor/blob/master/AWESOME-JITTOR-LIST.md )
2021-10-11 20:03:20 +08:00
* IM: QQ Group(761222083)
2021-01-20 14:09:55 +08:00
2020-03-20 11:43:35 +08:00
The following example shows how to model a two-layer neural network step by step and train from scratch In a few lines of Python code.
```python
import jittor as jt
from jittor import Module
from jittor import nn
2020-04-10 13:34:52 +08:00
import numpy as np
2020-03-20 11:43:35 +08:00
class Model(Module):
def __init__ (self):
self.layer1 = nn.Linear(1, 10)
self.relu = nn.Relu()
self.layer2 = nn.Linear(10, 1)
def execute (self,x) :
x = self.layer1(x)
x = self.relu(x)
x = self.layer2(x)
return x
def get_data(n): # generate random data for training test.
for i in range(n):
x = np.random.rand(batch_size, 1)
y = x*x
yield jt.float32(x), jt.float32(y)
2020-04-10 13:34:52 +08:00
2020-03-20 11:43:35 +08:00
learning_rate = 0.1
2020-04-10 13:34:52 +08:00
batch_size = 50
n = 1000
model = Model()
2020-03-20 11:43:35 +08:00
optim = nn.SGD(model.parameters(), learning_rate)
for i,(x,y) in enumerate(get_data(n)):
pred_y = model(x)
2020-04-10 13:34:52 +08:00
dy = pred_y - y
loss = dy * dy
2020-03-20 11:43:35 +08:00
loss_mean = loss.mean()
2020-03-25 11:35:35 +08:00
optim.step(loss_mean)
2020-03-20 11:43:35 +08:00
print(f"step {i}, loss = {loss_mean.data.sum()}")
```
## Contents
* [Quickstart ](#quickstart )
* [Install ](#install )
* [Tutorial ](#tutorial )
* [Contributing ](#contributing )
* [The Team ](#theteam )
* [License ](#license )
## Quickstart
We provide some jupyter notebooks to help you quick start with Jittor.
- [Example: Model definition and training][1]
- [Basics: Op, Var][2]
- [Meta-operator: Implement your own convolution with Meta-operator][3]
## Install
2021-01-20 22:44:12 +08:00
2020-03-20 11:43:35 +08:00
2020-04-22 11:09:27 +08:00
2021-10-03 23:33:50 +08:00
2020-03-23 21:56:32 +08:00
Jittor environment requirements:
2021-09-30 15:33:21 +08:00
* System: **Linux** (e.g. Ubuntu/CentOS/Arch), **macOS** , or **Windows** , enviroment requirements of **Linux** and **Mac** are list below:
2020-03-23 21:56:32 +08:00
* Python version >= 3.7
2021-01-20 22:44:12 +08:00
* CPU compiler (require at least one of the following)
* g++ (>=5.4.0)
* clang (>=8.0)
* GPU compiler (optional)
* nvcc (>=10.0 for g++ or >=10.2 for clang)
2021-01-30 13:59:12 +08:00
* GPU library: cudnn-dev (recommend tar file installation, [reference link ](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#installlinux-tar ))
2021-01-20 22:44:12 +08:00
2021-09-30 15:33:21 +08:00
**Windows** requirements atr:
2020-03-23 21:56:32 +08:00
2021-09-30 16:46:40 +08:00
* Python: version >= 3.8(recommend install from < https: // www . python . org / downloads / windows /> )
2021-09-30 15:33:21 +08:00
* x86_64 CPU processor
* Windows 10 or above
2021-06-10 17:33:57 +08:00
2021-09-30 15:33:21 +08:00
Note#1: macOS users have to install additional dependencies, see [macOS install ](#macOS-install ).
2020-04-22 11:09:27 +08:00
2021-09-30 17:39:29 +08:00
Jittor offers three ways to install: pip, docker, or manual.
2020-03-20 11:43:35 +08:00
2021-01-20 13:46:32 +08:00
## Pip install
2020-03-20 11:43:35 +08:00
```bash
2021-01-20 13:46:32 +08:00
sudo apt install python3.7-dev libomp-dev
python3.7 -m pip install jittor
# or install from github(latest version)
# python3.7 -m pip install git+https://github.com/Jittor/jittor.git
python3.7 -m jittor.test.test_example
2020-03-20 11:43:35 +08:00
```
2021-06-10 17:33:57 +08:00
2021-09-30 17:39:29 +08:00
### macOS install
2021-06-10 17:33:57 +08:00
Please first install additional dependencies with [homebrew ](https://brew.sh ).
```bash
brew install python@3.7 onednn libomp
```
Then you can install jittor through pip and run the example.
```bash
python3.7 -m pip install jittor
python3.7 -m jittor.test.test_example
```
Currently jittor only supports CPU in macOS.
2021-09-30 15:33:21 +08:00
2021-09-30 17:39:29 +08:00
### Windows install
2021-09-30 15:33:21 +08:00
```bash
# check your python version(>=3.8)
python --version
python -m pip install jittor
# if conda is used
conda install pywin32
```
In Windows, jittor will automatically detect and install CUDA, please make sure your NVIDIA driver support CUDA 10.2 or above, or you can manually let jittor install CUDA for you:
```bash
python -m jittor_utils.install_cuda
```
2021-09-30 17:39:29 +08:00
## Docker Install
We provide a Docker installation method to save you from configuring the environment. The Docker installation method is as follows:
```
# CPU only(Linux)
docker run -it --network host jittor/jittor
# CPU and CUDA(Linux)
docker run -it --network host --gpus all jittor/jittor-cuda
# CPU only(Mac and Windows)
docker run -it -p 8888:8888 jittor/jittor
```
2020-03-20 11:43:35 +08:00
## manual install
We will show how to install Jittor in Ubuntu 16.04 step by step, Other Linux distributions may have similar commands.
### Step 1: Choose your back-end compiler
```bash
# g++
sudo apt install g++ build-essential libomp-dev
# OR clang++-8
2020-04-24 12:12:50 +08:00
wget -O - https://raw.githubusercontent.com/Jittor/jittor/master/script/install_llvm.sh > /tmp/llvm.sh
2020-03-20 11:43:35 +08:00
bash /tmp/llvm.sh 8
```
### Step 2: Install Python and python-dev
Jittor need python version >= 3.7.
```bash
sudo apt install python3.7 python3.7-dev
```
### Step 3: Run Jittor
The whole framework is compiled Just-in-time. Let's install jittor via pip
```bash
git clone https://github.com/Jittor/jittor.git
sudo pip3.7 install ./jittor
export cc_path="clang++-8"
# if other compiler is used, change cc_path
# export cc_path="g++"
# export cc_path="icc"
# run a simple test
python3.7 -m jittor.test.test_example
```
if the test is passed, your Jittor is ready.
### Optional Step 4: Enable CUDA
Using CUDA in Jittor is very simple, Just setup environment value `nvcc_path`
```bash
# replace this var with your nvcc location
export nvcc_path="/usr/local/cuda/bin/nvcc"
# run a simple cuda test
python3.7 -m jittor.test.test_cuda
```
if the test is passed, your can use Jittor with CUDA by setting `use_cuda` flag.
```python
import jittor as jt
jt.flags.use_cuda = 1
```
2020-12-08 22:47:38 +08:00
### Optional Step 5: Test Resnet18 training
2020-03-20 11:43:35 +08:00
2021-01-27 13:55:26 +08:00
To check the integrity of Jittor, you can run Resnet18 training test. Note: 6G GPU RAM is requires in this test.
2020-03-20 11:43:35 +08:00
```bash
2020-12-08 22:47:38 +08:00
python3.7 -m jittor.test.test_resnet
2020-03-20 11:43:35 +08:00
```
if those tests are failed, please report bugs for us, and feel free to contribute ^_^
## Tutorial
In the tutorial section, we will briefly explain the basic concept of Jittor.
To train your model with Jittor, there are only three main concepts you need to know:
* Var: basic data type of jittor
* Operations: Jittor'op is simular with numpy
### Var
First, let's get started with Var. Var is the basic data type of jittor. Computation process in Jittor is asynchronous for optimization. If you want to access the data, `Var.data` can be used for synchronous data accessing.
```python
import jittor as jt
a = jt.float32([1,2,3])
print (a)
print (a.data)
# Output: float32[3,]
# Output: [ 1. 2. 3.]
```
And we can give the variable a name.
```python
2021-01-30 14:11:12 +08:00
a.name('a')
print(a.name())
# Output: a
2020-03-20 11:43:35 +08:00
```
2020-05-17 23:55:18 +08:00
### Operations
2020-03-20 11:43:35 +08:00
2021-05-13 21:25:13 +08:00
Jittor'op is simular with numpy. Let's try some operations. We create Var `a` and `b` via operation `jt.float32` , and add them. Printing those variables shows they have the same shape and dtype.
2020-03-20 11:43:35 +08:00
```python
import jittor as jt
a = jt.float32([1,2,3])
b = jt.float32([4,5,6])
c = a*b
print(a,b,c)
print(type(a), type(b), type(c))
# Output: float32[3,] float32[3,] float32[3,]
# Output: <class 'jittor_core.Var'> <class 'jittor_core.Var'> <class 'jittor_core.Var'>
```
Beside that, All the operators we used `jt.xxx(Var, ...)` have alias `Var.xxx(...)` . For example:
```python
2020-04-06 10:37:17 +08:00
c.max() # alias of jt.max(c)
2020-03-20 11:43:35 +08:00
c.add(a) # alias of jt.add(c, a)
c.min(keepdims=True) # alias of jt.min(c, keepdims=True)
```
if you want to know all the operation which Jittor supports. try `help(jt.ops)` . All the operation you found in `jt.ops.xxx` , can be used via alias `jt.xxx` .
```python
help(jt.ops)
# Output:
# abs(x: core.Var) -> core.Var
# add(x: core.Var, y: core.Var) -> core.Var
# array(data: array) -> core.Var
# binary(x: core.Var, y: core.Var, op: str) -> core.Var
# ......
```
### More
If you want to know more about Jittor, please check out the notebooks below:
* Quickstart
- [Example: Model definition and training][1]
- [Basics: Op, Var][2]
- [Meta-operator: Implement your own convolution with Meta-operator][3]
* Advanced
- [Custom Op: write your operator with C++ and CUDA and JIT compile it][4]
- [Profiler: Profiling your model][5]
- Jtune: Tool for performance tuning
2021-06-21 17:38:23 +08:00
[1]: python/jittor/notebook/example.src.md "example"
[2]: python/jittor/notebook/basics.src.md "basics"
[3]: python/jittor/notebook/meta_op.src.md "meta_op"
[4]: python/jittor/notebook/custom_op.src.md "custom_op"
[5]: python/jittor/notebook/profiler.src.md "profiler"
2020-03-20 11:43:35 +08:00
Those notebooks can be started in your own computer by `python3.7 -m jittor.notebook`
## Contributing
Jittor is still young. It may contain bugs and issues. Please report them in our bug track system. Contributions are welcome. Besides, if you have any ideas about Jittor, please let us know.
2020-03-25 11:58:39 +08:00
You can help Jittor in the following ways:
* Citing Jittor in your paper
* recommend Jittor to your friends
* Contributing code
* Contributed tutorials and documentation
* File an issue
* Answer jittor related questions
* Light up the stars
* Keep an eye on jittor
* ......
## Contact Us
Website: http://cg.cs.tsinghua.edu.cn/jittor/
Email: jittor@qq.com
File an issue: https://github.com/Jittor/jittor/issues
2020-12-08 22:47:38 +08:00
QQ Group: 761222083
< img src = "https://cg.cs.tsinghua.edu.cn/jittor/images/news/2020-12-8-21-19-1_2_2/fig4.png" width = "200" / >
2020-03-20 11:43:35 +08:00
## The Team
2020-12-09 16:15:08 +08:00
Jittor is currently maintained by the [Tsinghua CSCG Group ](https://cg.cs.tsinghua.edu.cn/ ). If you are also interested in Jittor and want to improve it, Please join us!
2020-03-20 11:43:35 +08:00
2020-12-08 22:47:38 +08:00
## Citation
```
@article {hu2020jittor,
title={Jittor: a novel deep learning framework with meta-operators and unified graph execution},
author={Hu, Shi-Min and Liang, Dun and Yang, Guo-Ye and Yang, Guo-Wei and Zhou, Wen-Yang},
2021-06-30 10:07:16 +08:00
journal={Science China Information Sciences},
2020-12-08 22:47:38 +08:00
volume={63},
number={222103},
2021-01-20 23:07:53 +08:00
pages={1--21},
2020-12-08 22:47:38 +08:00
year={2020}
}
```
2020-03-20 11:43:35 +08:00
## License
Jittor is Apache 2.0 licensed, as found in the LICENSE.txt file.