2. Environment Setup
First check whether the current system environment meets ubuntu 22.04 and python 3.10. If not, please proceed to the next section Basic Environment Configuration; if satisfied, jump directly to Install tpu_mlir.
2.1. Basic Environment Configuration
If you do not meet the above system environment, you need to use Docker, download the required image file from DockerHub https://hub.docker.com/r/sophgo/tpuc_dev, or use the following command to pull the image directly:
1$ docker pull sophgo/tpuc_dev:v3.4
If the pulling fails, you can download the required image file from the official website development materials https://developer.sophgo.com/site/index/material/86/all.html, or use the following command to download and load the image:
1$ wget https://sophon-assets.sophon.cn/sophon-prod-s3/drive/25/04/15/16/tpuc_dev_v3.4.tar.gz
2$ docker load -i tpuc_dev_v3.4.tar.gz
If you are using docker for the first time, you can execute the following commands to install and configure it (only for the first time):
1$ sudo apt install docker.io
2$ sudo systemctl start docker
3$ sudo systemctl enable docker
4$ sudo groupadd docker
5$ sudo usermod -aG docker $USER
6$ newgrp docker
If you download the image file, make sure the image file is in the current directory, and then create a container in the current directory as follows:
# use --privileged to get root permission, if you don't need root permission, please remove this parameter
$ docker run --privileged --name myname -v $PWD:/workspace -it sophgo/tpuc_dev:v3.4
where myname
is the name of the container, which can be customized; $PWD
is the current directory, synchronized with the container’s /workspace
directory.
Subsequent chapters assume that the user is already in the /workspace
directory inside docker.
2.2. Install tpu_mlir
Currently supported 2 methods to install, which are online and offline installation.
Online installation
Download and install directly from pypi, the latest version will be installed by default:
$ pip install tpu_mlir
Offline installation
Download tpu_mlir-*-py3-none-any.whl from Assets on Github, then install with pip:
$ pip install tpu_mlir-*-py3-none-any.whl
2.3. Install the dependency of tpu_mlir
tpu_mlir requires different dependencies when processing models of different frameworks, Both the online and offline installation methods require additional dependencies to be installed.
Online installation
For model files generated by onnx
or torch
when online installation, use the following command to install additional dependency environments:
# install onnx dependency
$ pip install tpu_mlir[onnx]
# install torch dependency
$ pip install tpu_mlir[torch]
There are 5 config currently supported:
onnx, torch, tensorflow, caffe, paddle
You can install multiple dependency config in one command, or use all
to install all dependencies:
# install onnx, torch, caffe dependency at the same time
$ pip install tpu_mlir[onnx,torch,caffe]
# install all dependency
$ pip install tpu_mlir[all]
Offline installation
Similarly, the offline installation method allows you to install additional dependencies using the following command:
# install onnx dependency
$ pip install tpu_mlir-*-py3-none-any.whl[onnx]
# install all dependency
$ pip install tpu_mlir-*-py3-none-any.whl[all]