tenstorrent/tenstorrent.github.io

Error Importing TTNN after wheel installation

Closed this issue · 6 comments

When installing the wheel on the Github runner, I am unable to import ttnn

  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/tt_lib/__init__.py", line 5, in <module>
    import ttnn
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/ttnn/__init__.py", line 18, in <module>
    library_tweaks.setup_ttnn_so()
NameError: name 'library_tweaks' is not defined

The effect of this is TTNN API documentation for functions can not pick up function docstrings and they are left blank.

Previously, Artem Yerofieiev has helped with this issue for versions below 52 by outlining that there was a known issue to the team and it would not work correctly for versions of metallium v0.50.0 and v0.51.0.

Shoot, this is for v0.52?

Not sure why this doesn't appear on our pipelines but it looks like these lines

# Sets env and updates shared libs rpath
# This is a tweak required for a proper wheel functioning
import ttnn.library_tweaks

library_tweaks.setup_ttnn_so()

might be the culprit. It might have to be ttnn.library_tweaks.setup_ttnn_so()

Should we make this change and try on metal pipelines? I'm not sure why this wasn't caught...

Correct - this is in v0.52.0 and in the current code base as well.
import ttnn.library_tweaks

It works on an Austin machine but fails in Github ephemeral runners.

It might not be just the import but somewhere related to rpath setup and .so's according to Artem

My gut feeling is this is definitely a Python error. I believe we would see something related to SOs not found, rather than a Python NameError.

The thing is we use GitHub ephemeral runners to test the wheel...

Copying from the Slack discussion:

I have had a great session today with Bryan and following that I was able to get on the right track.
I isolated the build for docs to fail upon python3 -c "import ttnn"
See literally the super basic Github run that just installs the wheel -

jobs:
  build-and-deploy:
    runs-on: ubuntu-20.04

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.8' 
      - name: OS Dependencies
        run: |
          sudo apt-get update -y
          sudo apt-get install -y pandoc
          sudo apt install software-properties-common=0.99.9.12 build-essential=12.8ubuntu1.1 python3.8-venv libhwloc-dev graphviz
      - name: Build documentation
        run: |

          wget https://github.com/tenstorrent/tt-metal/releases/download/v0.52.0/metal_libs-0.52.0+wormhole.b0-cp38-cp38-linux_x86_64.whl
          pip install --extra-index-url https://download.pytorch.org/whl/cpu metal_libs-0.52.0+wormhole.b0-cp38-cp38-linux_x86_64.whl --force-reinstall
          python -c "import ttnn"
          

https://github.com/tenstorrent/tenstorrent.github.io/actions/runs/11487587549/job/31972476196

This is the error

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/ttnn/__init__.py", line 20, in <module>
    import ttnn._ttnn
ImportError: libunwind.so.1: cannot open shared object file: No such file or directory

I will continue digging through this.

After an investigation and lots of help from @tt-rkim Bryan Keith and Artem, I was able to distill the error to the missing CLang-17 installation! Once that was corrected, import ttnn stopped failing and the TTNN API docs could be introspected.

The change was the addition of these lines to the Github actions workflow

    - name: Install Clang-17
      shell: bash
      run: |
        wget https://apt.llvm.org/llvm.sh
        chmod u+x llvm.sh
        sudo ./llvm.sh 17
        sudo apt install -y libc++-17-dev libc++abi-17-dev