Skip to main content

Rebellions Extension for PyTorch

Project description

PyTorch for Rebellions' NPU

This package provides PyTorch integration for Rebellions' NPU.

Getting Started (torch: Python package, rebel-compiler: Python package)

Prerequisites

  • Python 3.9 or later
  • Git
  • CMake 3.18 or later
  • Ninja build system
  • LDAP credentials for Rebellions' package repository

Update Git submodules

Clone submodules recursively. This will download required third-party libraries such as Rebel Compiler headers from third_party/rebel_compiler.

git submodule update --init ./

Create Python Virtual Environment

Create Python virtual environment. This will create a directory named .venv in the current directory.

python3 -m venv ./.venv && source ./.venv/bin/activate

Install Dependencies

Install Python package manager poetry. This will manage dependencies, building, packaging and installing.

pip3 install poetry==2.0.1

Save credentials for https://gate-keeper.rebellions.in. Authorization for https://pypi.rbln.in is required. But, this is not safe way to save credentials. See ~/.config/pypoetry/auth.toml.

export LDAP_USERNAME=daekyeong.kim     # Put your username
export LDAP_PASSWORD=mysecretpassword  # Put your password
poetry config keyring.enabled false    # Optional, if building freezes while auth
poetry config http-basic.rbln-internal $LDAP_USERNAME $LDAP_PASSWORD

NOTE During development we have to use rbln-internal instead of rbln. If you want to download rebel compiler from rbln (external pypi server of rebellions), do the following.

poetry config http-basic.rbln <rbln username> <rbln password>

Install dependencies written in poetry.lock using poetry, except the root package torch-rbln. Be careful, below command uninstall packages which is not on poetry.lock.

poetry sync --no-root

Choose Build Type (Optional)

Choose build type like below. Default is Release.

export RBLN_BUILD_TYPE=Debug

Install Editable Package

Build C++ project and install editable torch-rbln package.

poetry install --only-root

🚀 Optional: Performance Optimization Flag

To reduce runtime overhead (e.g., skipping unnecessary NaN/Inf checks), set the following environment variable:

export TORCH_RBLN_DEPLOY=ON

This enables lightweight execution for deployment scenarios.

🔒 Optional: Disable Recovery from compile error

In some cases, torch_rbln may attempt to recover from a compilation failure by falling back to CPU execution or other default paths. To enforce stricter execution (e.g., for debugging or testing device-only correctness), you can disable this behavior using the following environment variable:

export TORCH_RBLN_RECOVERY=OFF

🧪 Optional: Dynamo Cache Disable

By default, kernel caching(from dynamo) are enabled during execution. If you wish to disable for debugging or development purposes, set the following environment variables:

export TORCH_RBLN_CACHE=OFF

Install Wheel Package (Optional)

If you want to make *.whl and install that, run below command.

poetry build
pip install ./dist/torch_rbln*.whl

When you change C++ or Python source code, you just run Install Editable Package or Install Wheel Package again.

Apply Custom rebel-compiler

You have 2 choices:

  • Use built-in one
  • Use external one

Use torch-rbln built-in rebel-compiler (torch: Python package, rebel-compiler: third_party/rebel_compiler)

This way is strongly recommended. Those are same with Getting Started.

git submodule update --init ./
python3 -m venv ./.venv && source ./.venv/bin/activate
pip3 install poetry==2.0.1
export LDAP_USERNAME=daekyeong.kim     # Put your username
export LDAP_PASSWORD=mysecretpassword  # Put your password
poetry config http-basic.rbln $LDAP_USERNAME $LDAP_PASSWORD

Without poetry sync, checkout rebel-compiler where ./third_party/rebel_compiler to your custom branch.

pushd ./third_party/rebel_compiler
  git checkout my_custom_branch
popd

It will make a package and install into your environment with syncing.

./tools/apply-custom-rebel.sh

Above script edits pyproject.toml and poetry.lock files. If you want to apply custom rebel-compiler temporarily, keep your eyes on those files.

(Optional) You can choose build type like below.

RBLN_BUILD_TYPE=Debug ./tools/apply-custom-rebel.sh

Then, you can build or install torch-rbln package on the custom rebel-compiler package.

poetry install --only-root

Use external rebel-compiler (torch: Python package, rebel-compiler: external rebel_compiler)

Go to your custom rebel-comipler and finish building.

pushd "$REBEL_HOME"
  python -m venv ./.venv && source ./.venv/bin/activate

  # Assume that you build your `rebel-compiler` perfectly.

  deactivate
popd

Then, go to torch-rbln repository, and do the same things.

git submodule update --init ./
python3 -m venv ./.venv && source ./.venv/bin/activate
pip3 install poetry==2.0.1
export LDAP_USERNAME=daekyeong.kim     # Put your username
export LDAP_PASSWORD=mysecretpassword  # Put your password
poetry config http-basic.rbln $LDAP_USERNAME $LDAP_PASSWORD

You MUST include below code. It checks REBEL_HOME, adds PYTHONPATH, and declares RBLN_USE_EXTERNAL_REBEL_COMPILER.

. ./tools/activate-rebel-env

Then, you can build or install torch-rbln package on the custom rebel-compiler package.

poetry install --only-root

NOTE: That way does not install rebel-compiler Python package. If you want to install it, use built-in rebel-compiler.

Create Git Commit

Git pre-commit hook is working. So, when you create Git commit, linting would be triggered. For prepare linting, you MUST initialize lintrunner.

source ./.venv/bin/activate

lintrunner init

Once lintrunner initalized, no need to initialize again. You can commit now.

git commit

Some failures can be fixed automatically. Run below command for auto fixing.

lintrunner -m main -a

Run Tests

Assume that you are in Python virtual environment, and install torch-rbln package successfully.

C++ Tests

Making package runs in new isolated environment. Although you build your C++ project using poetry install --only-root, can't find that directory. So, for CTest you MUST build C++ project manually.

./tools/build-libtorch-rbln.sh

ctest --test-dir ./build

Python Tests

pytest ./test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torch_rbln-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (324.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

torch_rbln-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (324.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

torch_rbln-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (323.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

torch_rbln-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (323.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

Details for the file torch_rbln-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_rbln-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 626ce50e1f48ac76d4f3fbb7752071707a17ffc3701be3b7ee24a1725455d6c1
MD5 57760d4876a1cc40d5e288e63c850749
BLAKE2b-256 34657a06f425c3a620c26e08173f1bbcf7d2bf1e329217311aa8c7a8574711db

See more details on using hashes here.

File details

Details for the file torch_rbln-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_rbln-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c38362ea9de9ba4274e91e79b46255cbdd713bcd0ba49be78714f1a528c8bd92
MD5 f1345e44c838a5071e0acf7e01815417
BLAKE2b-256 e34ef9f7081340b133a084b85e491fcb58c2fed315778c48d26785acd0dff202

See more details on using hashes here.

File details

Details for the file torch_rbln-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_rbln-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3b39050e3e532ce6e27ccaa4c40e8239fdd5e26cac259c3cb7c4ee4008019e76
MD5 3d49a109888d8747d7818fe29f641024
BLAKE2b-256 c432cda4a1cfc951e973f3e6a970b007dd93e5fd2ad220faea78a0a367179819

See more details on using hashes here.

File details

Details for the file torch_rbln-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torch_rbln-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03cb7fcae40976958aa4b50e9ff7226c7f5b0e5d7a92c221e8a9201a66db8e75
MD5 3d7cde918cc749b375b22710da141455
BLAKE2b-256 ffbef54ac4e10fec8c56705c4369f2fdca3fcba9b12e2d0df002f415d4568df8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page