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*. .. _env setup: 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: .. code-block:: shell :linenos: $ 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: .. code-block:: shell :linenos: $ wget https://sophon-assets.sophon.cn/sophon-prod-s3/drive/25/04/15/16/tpuc_dev_v3.4.tar.gz $ 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): .. _docker configuration: .. code-block:: shell :linenos: $ sudo apt install docker.io $ sudo systemctl start docker $ sudo systemctl enable docker $ sudo groupadd docker $ sudo usermod -aG docker $USER $ newgrp docker .. _docker container_setup: 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: .. code-block:: shell # 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. 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: .. code-block:: shell $ pip install tpu_mlir **Offline installation** Download `tpu_mlir-*-py3-none-any.whl` from `Assets `_ on Github, then install with pip: .. code-block:: shell $ pip install tpu_mlir-*-py3-none-any.whl 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: .. code-block:: shell # install onnx dependency $ pip install tpu_mlir[onnx] # install torch dependency $ pip install tpu_mlir[torch] There are 5 config currently supported: .. code-block:: shell onnx, torch, tensorflow, caffe, paddle You can install multiple dependency config in one command, or use ``all`` to install all dependencies: .. code-block:: shell # 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: .. code-block:: shell # install onnx dependency $ pip install tpu_mlir-*-py3-none-any.whl[onnx] # install all dependency $ pip install tpu_mlir-*-py3-none-any.whl[all]