DragonArray docs

Install TensorFlow on DragonArray LoongArch systems

DragonArray provides native TensorFlow wheels for LoongArch processors. The LA664 release for the Loongson 3A6000 is available now and was built with LASX support. An LSX-only wheel set for the Loongson 3A5000 and 3B5000 is also available now.

Use the wheel set that matches your processor. The files under /download/664 require an LA664 processor with LASX support and cannot be installed on an LA464 (3*5000) machine.

The dedicated LASX-enabled wheel set for the Loongson 3C5000 is pending and is expected within a week. A 3C5000 can use the 3A5000 LSX wheel set in the meantime, but with reduced performance.

Both available packages contain TensorFlow 2.21.0 and all of the Python dependencies it needs on 64-bit LoongArch Linux with the standard, GIL-enabled CPython 3.13.

Check which wheel set you need

Run this command on the machine where TensorFlow will be installed:

LC_ALL=C lscpu | grep -E 'Architecture|Model name|Flags'

Confirm that Architecture is loongarch64, then use the processor model to select the archive:

Processor SIMD support Wheel set to use
Loongson 3A6000 / LA664 LASX tensorflow-3x6000.tar
Loongson 3A5000 or 3B5000 LSX only; Flags contains lsx but not lasx tensorflow-3a5000.tar
Loongson 3C5000 LASX Use tensorflow-3a5000.tar for now; it is compatible but slower. Switch to the dedicated 3C5000 build when it is released.

Do not select a package from the presence of lasx alone: both the 3A6000 and 3C5000 report LASX, but they currently use different package choices.

Build from source

To compile TensorFlow yourself, follow the TensorFlow 2.21.0 LoongArch source-build guide. It covers the complete patching workflow, native dependencies, Bazel configuration, target-specific compiler flags, and wheel validation for all three CPU profiles. The consolidated tensorflow-2.21.0-loongarch64.patch.gz is available separately for use in another build system.

Found a bug or an installation problem? Send a bug report to the DragonArray help desk. Please include your CPU model, Linux distribution, Python version, and the full error output.

1. Install the tools required to build Python

pyenv builds Python from source, so first install a compiler and Python's build dependencies.

Kylin Linux V10, Debian, or Ubuntu:

sudo apt update
sudo apt install -y \
  build-essential curl git make \
  libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
  libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev uuid-dev

RHEL, Fedora, or another RPM-based distribution:

sudo dnf install -y \
  git curl make gcc patch \
  zlib-devel bzip2-devel readline-devel sqlite-devel openssl-devel \
  xz-devel libffi-devel ncurses-devel tk-devel gdbm-devel libuuid-devel

If your system provides yum instead of dnf, replace dnf with yum in the command above.

2. Install pyenv

At the time of writing, the latest tagged pyenv release is pyenv 2.8.1. The official installer tracks the current upstream code, including newly added Python versions:

curl --fail --location https://pyenv.run | bash

Add pyenv to Bash:

printf '%s\n' \
  'export PYENV_ROOT="$HOME/.pyenv"' \
  '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' \
  'eval "$(pyenv init - bash)"' \
  >> ~/.bashrc
exec bash

If you use Zsh, put the same settings in ~/.zshrc and replace bash with zsh in the pyenv init line and the final exec command.

Confirm that pyenv works:

pyenv --version

3. Install Python 3.13

Python 3.13.14 is the current Python 3.13 maintenance release. Install the normal, GIL-enabled build, not the free-threaded 3.13t variant.

git -C "$(pyenv root)" pull --ff-only
pyenv install 3.13.14
pyenv global 3.13.14
python --version

The final command should print Python 3.13.14. These wheels were built with CPython 3.13.13 and have been tested with both 3.13.13 and 3.13.14.

4. Create and activate a virtual environment

Installing TensorFlow in a virtual environment prevents it from changing packages in the system Python:

mkdir -p ~/dragon-tensorflow
cd ~/dragon-tensorflow

python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip

When you open a new terminal later, return to the directory and activate the environment again:

cd ~/dragon-tensorflow
source .venv/bin/activate

5. Download and install the matching wheel set

Download the complete wheel bundle, extract it into a local directory, and install every wheel without using the public Python Package Index (PyPI):

For a Loongson 3A6000 with LA664 and LASX:

cd ~/dragon-tensorflow
curl --fail --location --output tensorflow.tar \
  https://dragon-array.org/download/664/tensorflow-3x6000.tar

For a Loongson 3A5000 or 3B5000 with LSX, use the LSX-only bundle. A 3C5000 may also use this bundle while its LASX-enabled build is pending, with reduced performance:

cd ~/dragon-tensorflow
curl --fail --location --output tensorflow.tar \
  https://dragon-array.org/download/3A5000/tensorflow-3a5000.tar

After downloading either archive, extract and install it:

mkdir -p wheels
tar -xf tensorflow.tar -C wheels

cd wheels/tf-wheelhouse-standard
sha256sum -c SHA256SUMS
cd ../..

python -m pip install --no-index \
  --find-links="$PWD/wheels/tf-wheelhouse-standard" \
  "$PWD"/wheels/tf-wheelhouse-standard/*.whl
python -m pip check

pip check should finish with:

No broken requirements found.

Verify the installation:

python -c 'import tensorflow as tf, numpy as np; print("TensorFlow", tf.__version__); print("NumPy", np.__version__)'

6. Optional: use the experimental DragonArray NumPy

Install the standard TensorFlow bundle first. Then replace only NumPy; all of TensorFlow's shared dependencies remain installed.

The experimental wheels are CPU-specific. Choose the wheel matching both your processor and Python version. Do not use --find-links here: both processor variants use the same linux_loongarch64 platform tag, so pip cannot choose between them safely.

Loongson 3C5000 (LA464)

Loongson 3A6000 (LA664)

The TensorFlow bundle above uses Python 3.13. On a Loongson 3C5000 (LA464), install:

python -m pip install --no-index --no-deps --force-reinstall \
  'https://dragon-array.org/wheels/numpy-2.5.0.dev0+dragon.unofficial.1-1la464-cp313-cp313-linux_loongarch64.whl'

On a Loongson 3A6000 (LA664), install:

python -m pip install --no-index --no-deps --force-reinstall \
  'https://dragon-array.org/wheels/numpy-2.5.0.dev0+dragon.unofficial.1-1la664-cp313-cp313-linux_loongarch64.whl'

Then verify the environment:

python -m pip check
python -c 'import numpy as np; print(np.__version__)'

Do not install an LA664 wheel on a 3C5000.

To restore standard NumPy, reinstall its wheel from the extracted bundle:

python -m pip install --no-index --no-deps --force-reinstall \
  "$PWD"/wheels/tf-wheelhouse-standard/numpy-2.5.1-cp313-cp313-linux_loongarch64.whl

7. Try something fun: recognize handwritten digits

This compact example downloads the MNIST handwritten-digit dataset, trains a small convolutional neural network, and reports its test accuracy. It uses only part of MNIST, so it runs comfortably on an LA664 system with 8 GB of memory. In testing on a Loongson 3A6000, the process reached about 1.2 GB peak resident memory.

Save this as mnist.py:

import tensorflow as tf
(x, y), (xt, yt) = tf.keras.datasets.mnist.load_data()
x, y, xt, yt = x[:20000, ..., None] / 255.0, y[:20000], xt[:5000, ..., None] / 255.0, yt[:5000]
m = tf.keras.Sequential([tf.keras.Input((28, 28, 1)), tf.keras.layers.Conv2D(16, 3, activation="relu"), tf.keras.layers.MaxPooling2D(), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation="softmax")])
m.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
m.fit(x, y, epochs=3, batch_size=256, validation_split=0.1)
print("Test accuracy:", m.evaluate(xt, yt, verbose=0)[1])

Run it inside the activated virtual environment:

python mnist.py

The dataset is downloaded only on the first run and cached under ~/.keras/datasets.