HRM icon indicating copy to clipboard operation
HRM copied to clipboard

import adam_atan2_backend ModuleNotFoundError: No module named 'adam_atan2_backend'

Open TuananhCR opened this issue 5 months ago • 6 comments

OMP_NUM_THREADS=8 python pretrain.py
data_path=data/sudoku-extreme-1k-aug-1000
epochs=20000
eval_interval=2000
global_batch_size=384
lr=7e-5
puzzle_emb_lr=7e-5
weight_decay=1.0
puzzle_emb_we> ight_decay=1.0> > > > > > > Traceback (most recent call last): File "/tf/HRM/pretrain.py", line 19, in from adam_atan2 import AdamAtan2 File "/tf/hrm-env/lib/python3.11/site-packages/adam_atan2/init.py", line 1, in from .adam_atan2 import AdamATan2 File "/tf/hrm-env/lib/python3.11/site-packages/adam_atan2/adam_atan2.py", line 4, in import adam_atan2_backend ModuleNotFoundError: No module named 'adam_atan2_backend'

Need someone to fix this .Thank you in advanced.

TuananhCR avatar Aug 07 '25 09:08 TuananhCR

Found a workaround by using adam_atan2_pytorch. Just have to initialize the learning rate to a small value > 0 in the pretrain code or else it will return an assertion error.

bjiro avatar Aug 07 '25 11:08 bjiro

Just switching imports doesn't work - you'd have to modify the code. The reason we're seeing this error, I believe, is that simply adding adam_atan2 from PyPI via PIP is not resulting in the building of the CUDA module adam_atan2_backend, which is missing because it needs to be compiled.

It would be useful if the Sapient folks could clarify this step in the installation process.

mmadsen avatar Aug 11 '25 15:08 mmadsen

Check #45

kroggen avatar Aug 11 '25 16:08 kroggen

Thanks @kroggen - doing the following worked for me, as you suggested. Appreciate the help! ``sed -i 's/adam-atan2/adam-atan2-pytorch/g' requirements.txt

pip install -r requirements.txt

sed -i 's/adam_atan2/adam_atan2_pytorch/g' pretrain.py

sed -i 's/AdamATan2/AdamAtan2/g' pretrain.py

sed -i 's/lr=0,/lr=0.0001,/g' pretrain.py``

mmadsen avatar Aug 11 '25 19:08 mmadsen

Fix for "No module named 'adam_atan2_backend'" Error

Problem

When importing adam_atan2, you may encounter this error:

ModuleNotFoundError: No module named 'adam_atan2_backend'

Root Cause

This error occurs because the C++ CUDA backend extension wasn't properly compiled during installation. The adam_atan2_backend module contains the optimized CUDA kernels that are essential for the optimizer to function.

Solution

Prerequisites

Ensure you have the necessary build tools installed:

  • GCC/G++ compiler
  • CUDA toolkit (matching your PyTorch CUDA version)
  • Python development headers

Step-by-Step Fix

  1. Clean uninstall the existing package:

    pip uninstall adam-atan2 -y
    
  2. Upgrade build dependencies:

    pip install --upgrade pip setuptools wheel
    
  3. Reinstall with fresh compilation:

    pip install --no-cache-dir --verbose adam-atan2
    

What to Look For

During installation, you should see output indicating successful CUDA compilation:

building 'adam_atan2_backend' extension
/usr/bin/nvcc ... -c csrc/adam_atan2.cu -o build/temp.../adam_atan2.o ...
/usr/bin/nvcc ... -c csrc/ops.cu -o build/temp.../ops.o ...

And the final shared library being created:

adam_atan2_backend.cpython-xxx-x86_64-linux-gnu.so

Verification

Test that the fix worked:

import adam_atan2
import torch

# Create test parameter
param = torch.randn(10, requires_grad=True)

# Create optimizer - this should work without errors
optimizer = adam_atan2.AdamATan2([param], lr=0.001)
print("✅ AdamATan2 optimizer created successfully!")

Common Issues

Issue: ninja not found warning

  • Solution: This is just a warning. The build will fall back to distutils and still work correctly.

Issue: CUDA version mismatch warning

  • Solution: Minor version mismatches are usually fine. Ensure your CUDA toolkit is compatible with your PyTorch installation.

Issue: Missing build tools

  • Solution: Install development tools:
    # Ubuntu/Debian
    sudo apt-get install build-essential python3-dev
    
    # CentOS/RHEL
    sudo yum groupinstall "Development Tools"
    sudo yum install python3-devel
    

Alternative: Install from Source

If the above doesn't work, you can build from source:

git clone https://github.com/jettify/adam-atan2.git
cd adam-atan2
pip install -e .

This ensures the C++ extensions are compiled in your specific environment.


Hope this helps! The key is ensuring the CUDA backend is properly compiled during installation. The --no-cache-dir --verbose flags are crucial for debugging and ensuring a fresh build.

wuttechadmin avatar Sep 29 '25 23:09 wuttechadmin

git clone https://github.com/jettify/adam-atan2.git returns a 404.

bumi001 avatar Nov 30 '25 10:11 bumi001