pytorch-riscv64


Namepytorch-riscv64 JSON
Version 2.3.0a1 PyPI version JSON
download
home_pagehttps://pytorch.org/
SummaryTensors and Dynamic neural networks in Python
upload_time2024-07-01 11:56:04
maintainerNone
docs_urlNone
authorRongchang Lu
requires_python>=3.8.0
licenseBSD-3
keywords pytorch machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # PyTorch for RISC-V Architecture

PyTorch is a popular open-source machine learning framework that provides a wide range of tools for building neural networks. It is widely used in academic and industry research, and is also used in production applications.

The following is the steps to build and install PyTorch for RISC-V architecture on OpenEuler 24.03.

It is more convenient to view the tutorial in GitHub and Gitee repository, which can be accessed through the following links:

- GitHub: https://github.com/xforcevesa/pytorch-riscv64-oe24
- Gitee: https://gitee.com/xforcevesa/pytorch-riscv64-oe24

## Introduction
The RISC-V software ecosystem is still under construction, and it is common to encounter difficulties when trying to use popular software packages. This article provides a guide on how to install PyTorch in a RISC-V environment.

The system environment is shown in the image below:
![System Environment](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/0d8af7fa06064de7a3ddfc25abf356c6.png)

The CPU model is SOPHON SG2042, RV64GC architecture, with V extension, 64 cores, and a clock speed of 2.0GHz. The toolchain versions are as shown:
![Toolchain Versions](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/2bf27850153048b99684c642edbc92bf.png)

## Steps
### Step 1: Install Packages
Use OpenEuler's dnf package manager to install the necessary packages with the following command:
```bash
sudo dnf install python3-{hypothesis,psutil,pyyaml,requests,sympy,filelock,networkx,jinja2,fsspec,packaging,numpy,venv}
```

### Step 2: Create a Virtual Environment
Create a virtual environment with the following command:
```bash
cd; python3 -m venv --system-site-packages venv
```
The `--system-site-packages` option allows the virtual environment to inherit the system Python environment, thus using the global PyPI packages.

Activate the created environment with:
```bash
source ~/venv/bin/activate
```
Alternatively, add this command to `~/.bashrc` to activate the environment automatically upon login.

### Step 3: Install Other Dependencies

**Activate the venv environment**.

#### Install with **pip**

- Now if you use `riscv64` as the platform, you can install PyTorch with the following command:
```bash
pip install pytorch-riscv64
```

- And then skip directly to the next step.
- If you would like to install PyTorch with other options, you can see the steps below.

#### Install from PyPI Wheel

Download the:

- GitHub Release:https://github.com/xforcevesa/pytorch-riscv64-oe24/releases/tag/2.3.0-alpha
- Gitee Release:https://gitee.com/xforcevesa/pytorch-riscv64-oe24/releases/tag/2.3.0-alpha

After downloading the wheel file, install it with the following command:
```bash
source ~/venv/bin/activate
pip install torch-2.3.0a1+gitunknown-cp311-cp311-linux_riscv64.whl
```

The following is the steps to install PyTorch from source code.

If you have already installed PyTorch from PyPI, you can skip this step.


#### Install from Source

We recommend installing PyTorch version 2.3.0. First, download the source code (this process can be done locally and then uploaded to the server):
```bash
wget https://github.com/pytorch/pytorch/releases/download/v2.3.0/pytorch-v2.3.0.tar.gz
```
Extract it:
```bash
tar xvf pytorch-v2.3.0.tar.gz
cd pytorch-v2.3.0/
```
Update `cpuinfo` by executing the following:
```bash
cd third_party/
rm -rf cpuinfo/
git clone https://github.com/sophgo/cpuinfo.git
cd ..
```

Then, make the following changes:
1. In `aten/src/ATen/CMakeLists.txt`, replace the line:
    ```cmake
    if(NOT MSVC AND NOT EMSCRIPTEN AND NOT INTERN_BUILD_MOBILE)
    ```
    with:
    ```cmake
    if(FALSE)
    ```

2. In `caffe2/CMakeLists.txt`, replace the line:
    ```cmake
    target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 sleef gtest_main)
    ```
    with:
    ```cmake
    target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 gtest_main)
    ```

3. In `test/cpp/api/CMakeLists.txt`, add the following line after:
    ```cmake
    add_executable(test_api ${TORCH_API_TEST_SOURCES})
    ```
    ```cmake
    target_compile_options(test_api PUBLIC -Wno-nonnull)
    ```

Save the changes. If the modifications were done locally, upload the modified source code to the server.

Create a build script:
```bash
#!/bin/bash
source ~/venv/bin/activate
export USE_CUDA=0 # CUDA is not available on RISC-V architecture servers
export USE_DISTRIBUTED=0 # Distributed support is not available
export USE_MKLDNN=0 # MKL is not supported as it is not an Intel processor
export MAX_JOBS=5 # Number of compile processes, adjust as needed
python3 setup.py develop --cmake
```
Save it as `build.sh` in the `pytorch-v2.3.0/` directory on the server. Execute the script with:
```bash
bash build.sh
```
This will automatically complete the build process. The build time is quite long; in my case, using 5 processes, it took two to three hours. Consider using `tmux` or `screen` for a persistent session. If needed, install these tools using the dnf package manager.

### Step 4: Verify Installation
If no errors occurred during the installation, the process is complete. The following shows a verification test:
![Verification](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/2bf27850153048b99684c642edbc92bf.png)

If you get the corresponding output as shown in the image, PyTorch has been successfully installed.

## References
- [AI Framework (Pytorch) Adaptation Based on RISC-V Architecture (Chinese)](https://blog.csdn.net/m0_49267873/article/details/135670989)


            

Raw data

            {
    "_id": null,
    "home_page": "https://pytorch.org/",
    "name": "pytorch-riscv64",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.0",
    "maintainer_email": null,
    "keywords": "pytorch, machine learning",
    "author": "Rongchang Lu",
    "author_email": "nomodeset@qq.com",
    "download_url": "https://github.com/pytorch/pytorch/tags",
    "platform": null,
    "description": "# PyTorch for RISC-V Architecture\n\nPyTorch is a popular open-source machine learning framework that provides a wide range of tools for building neural networks. It is widely used in academic and industry research, and is also used in production applications.\n\nThe following is the steps to build and install PyTorch for RISC-V architecture on OpenEuler 24.03.\n\nIt is more convenient to view the tutorial in GitHub and Gitee repository, which can be accessed through the following links:\n\n- GitHub: https://github.com/xforcevesa/pytorch-riscv64-oe24\n- Gitee: https://gitee.com/xforcevesa/pytorch-riscv64-oe24\n\n## Introduction\nThe RISC-V software ecosystem is still under construction, and it is common to encounter difficulties when trying to use popular software packages. This article provides a guide on how to install PyTorch in a RISC-V environment.\n\nThe system environment is shown in the image below:\n![System Environment](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/0d8af7fa06064de7a3ddfc25abf356c6.png)\n\nThe CPU model is SOPHON SG2042, RV64GC architecture, with V extension, 64 cores, and a clock speed of 2.0GHz. The toolchain versions are as shown:\n![Toolchain Versions](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/2bf27850153048b99684c642edbc92bf.png)\n\n## Steps\n### Step 1: Install Packages\nUse OpenEuler's dnf package manager to install the necessary packages with the following command:\n```bash\nsudo dnf install python3-{hypothesis,psutil,pyyaml,requests,sympy,filelock,networkx,jinja2,fsspec,packaging,numpy,venv}\n```\n\n### Step 2: Create a Virtual Environment\nCreate a virtual environment with the following command:\n```bash\ncd; python3 -m venv --system-site-packages venv\n```\nThe `--system-site-packages` option allows the virtual environment to inherit the system Python environment, thus using the global PyPI packages.\n\nActivate the created environment with:\n```bash\nsource ~/venv/bin/activate\n```\nAlternatively, add this command to `~/.bashrc` to activate the environment automatically upon login.\n\n### Step 3: Install Other Dependencies\n\n**Activate the venv environment**.\n\n#### Install with **pip**\n\n- Now if you use `riscv64` as the platform, you can install PyTorch with the following command:\n```bash\npip install pytorch-riscv64\n```\n\n- And then skip directly to the next step.\n- If you would like to install PyTorch with other options, you can see the steps below.\n\n#### Install from PyPI Wheel\n\nDownload the\uff1a\n\n- GitHub Release\uff1ahttps://github.com/xforcevesa/pytorch-riscv64-oe24/releases/tag/2.3.0-alpha\n- Gitee Release\uff1ahttps://gitee.com/xforcevesa/pytorch-riscv64-oe24/releases/tag/2.3.0-alpha\n\nAfter downloading the wheel file, install it with the following command\uff1a\n```bash\nsource ~/venv/bin/activate\npip install torch-2.3.0a1+gitunknown-cp311-cp311-linux_riscv64.whl\n```\n\nThe following is the steps to install PyTorch from source code.\n\nIf you have already installed PyTorch from PyPI, you can skip this step.\n\n\n#### Install from Source\n\nWe recommend installing PyTorch version 2.3.0. First, download the source code (this process can be done locally and then uploaded to the server):\n```bash\nwget https://github.com/pytorch/pytorch/releases/download/v2.3.0/pytorch-v2.3.0.tar.gz\n```\nExtract it:\n```bash\ntar xvf pytorch-v2.3.0.tar.gz\ncd pytorch-v2.3.0/\n```\nUpdate `cpuinfo` by executing the following:\n```bash\ncd third_party/\nrm -rf cpuinfo/\ngit clone https://github.com/sophgo/cpuinfo.git\ncd ..\n```\n\nThen, make the following changes:\n1. In `aten/src/ATen/CMakeLists.txt`, replace the line:\n    ```cmake\n    if(NOT MSVC AND NOT EMSCRIPTEN AND NOT INTERN_BUILD_MOBILE)\n    ```\n    with:\n    ```cmake\n    if(FALSE)\n    ```\n\n2. In `caffe2/CMakeLists.txt`, replace the line:\n    ```cmake\n    target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 sleef gtest_main)\n    ```\n    with:\n    ```cmake\n    target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 gtest_main)\n    ```\n\n3. In `test/cpp/api/CMakeLists.txt`, add the following line after:\n    ```cmake\n    add_executable(test_api ${TORCH_API_TEST_SOURCES})\n    ```\n    ```cmake\n    target_compile_options(test_api PUBLIC -Wno-nonnull)\n    ```\n\nSave the changes. If the modifications were done locally, upload the modified source code to the server.\n\nCreate a build script:\n```bash\n#!/bin/bash\nsource ~/venv/bin/activate\nexport USE_CUDA=0 # CUDA is not available on RISC-V architecture servers\nexport USE_DISTRIBUTED=0 # Distributed support is not available\nexport USE_MKLDNN=0 # MKL is not supported as it is not an Intel processor\nexport MAX_JOBS=5 # Number of compile processes, adjust as needed\npython3 setup.py develop --cmake\n```\nSave it as `build.sh` in the `pytorch-v2.3.0/` directory on the server. Execute the script with:\n```bash\nbash build.sh\n```\nThis will automatically complete the build process. The build time is quite long; in my case, using 5 processes, it took two to three hours. Consider using `tmux` or `screen` for a persistent session. If needed, install these tools using the dnf package manager.\n\n### Step 4: Verify Installation\nIf no errors occurred during the installation, the process is complete. The following shows a verification test:\n![Verification](https://gitee.com/xforcevesa/pytorch-riscv64-oe24/raw/main/docs/images/2bf27850153048b99684c642edbc92bf.png)\n\nIf you get the corresponding output as shown in the image, PyTorch has been successfully installed.\n\n## References\n- [AI Framework (Pytorch) Adaptation Based on RISC-V Architecture (Chinese)](https://blog.csdn.net/m0_49267873/article/details/135670989)\n\n",
    "bugtrack_url": null,
    "license": "BSD-3",
    "summary": "Tensors and Dynamic neural networks in Python",
    "version": "2.3.0a1",
    "project_urls": {
        "Download": "https://github.com/pytorch/pytorch/tags",
        "Homepage": "https://pytorch.org/"
    },
    "split_keywords": [
        "pytorch",
        " machine learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cc53cb69a9fc791ed71782e874f9ddb43b1911f3d05bdd142ed432ef99fbcef",
                "md5": "585064c4432a8bb49d167acb793d22e6",
                "sha256": "ef8c1c6de94f98fb67dfc86308e28ac52ba413779723f23c19e1277e3866975e"
            },
            "downloads": -1,
            "filename": "pytorch_riscv64-2.3.0a1-cp311-none-any.whl",
            "has_sig": false,
            "md5_digest": "585064c4432a8bb49d167acb793d22e6",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.8.0",
            "size": 93692416,
            "upload_time": "2024-07-01T11:56:04",
            "upload_time_iso_8601": "2024-07-01T11:56:04.556382Z",
            "url": "https://files.pythonhosted.org/packages/6c/c5/3cb69a9fc791ed71782e874f9ddb43b1911f3d05bdd142ed432ef99fbcef/pytorch_riscv64-2.3.0a1-cp311-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-01 11:56:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytorch",
    "github_project": "pytorch",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "pytorch-riscv64"
}
        
Elapsed time: 0.40004s