Skip to content

[BUG] Attempting to compile/download foundation models for use on CPU. #553

@CompRhys

Description

@CompRhys

Describe the bug
Following https://www.nequip.net/models/mir-group/NequIP-OAM-L:0.1 but attempting to compile to run on CPU leads to following errors.

To Reproduce

(torch-sim-atomistic) ➜  torch-sim git:(nequip-framework) ✗ nequip-compile \
  nequip.net:mir-group/NequIP-OAM-L:0.1 \
  mir-group__NequIP-OAM-L__0.1.nequip.pt2 \
  --mode aotinductor \
  --device cpu \
  --target ase
[2025-10-03 17:30:50,601][nequip.scripts.compile][INFO] - [rank: 0] Compiling for device: cpu
[2025-10-03 17:30:50,602][nequip.model.saved_models.load_utils][INFO] - [rank: 0] Fetching mir-group/NequIP-OAM-L:0.1 from nequip.net...
Downloading from Zenodo: 100%|██████████████████████████████████████████████████████| 78.5M/78.5M [00:27<00:00, 2.90MB/s]
[2025-10-03 17:31:18,461][nequip.model.saved_models.load_utils][INFO] - [rank: 0] Download complete, loading model...
[2025-10-03 17:31:18,461][nequip.model.saved_models.package][INFO] - [rank: 0] Loading model from package file: /var/folders/nl/sh8rg5qn11b4f5g6lgn35m380000gn/T/tmpf3a9vlz8.nequip.zip ...
Traceback (most recent call last):
  File "/Users/radical-rhys/Radical/torch-sim/.venv/bin/nequip-compile", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/nequip/scripts/compile.py", line 186, in main
    model = load_saved_model(
            ^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/nequip/model/saved_models/load_utils.py", line 120, in load_saved_model
    model = ModelFromPackage(actual_input_path, compile_mode=compile_mode)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/nequip/model/saved_models/package.py", line 132, in ModelFromPackage
    model = imp.load_pickle(
            ^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/package/package_importer.py", line 303, in load_pickle
    result = unpickler.load()
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/pickle.py", line 1256, in load
    dispatch[key[0]](self)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/pickle.py", line 1760, in load_build
    setstate(state)
  File "<torch_package_0>.e3nn/util/codegen/_mixin.py", line 121, in __setstate__
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/storage.py", line 530, in _load_from_bytes
    return torch.load(io.BytesIO(b), weights_only=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1549, in load
    return _legacy_load(
           ^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1807, in _legacy_load
    result = unpickler.load()
             ^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1742, in persistent_load
    obj = restore_location(obj, location)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 698, in default_restore_location
    result = fn(storage, location)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 636, in _deserialize
    device = _validate_device(location, backend_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/radical-rhys/Radical/torch-sim/.venv/lib/python3.12/site-packages/torch/serialization.py", line 605, in _validate_device
    raise RuntimeError(
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Expected behavior
The tensors should be saved from CPU such that they can be loaded to a CPU device. I expect this is the problem here.

Environment (please complete the following information):

  • OS: MacOS
  • python version: 3.12
  • python environment (commands are given for python interpreter):
    • nequip version 0.15
    • e3nn version 0.5.7
    • pytorch version 2.7.1
  • (if relevant) GPU support with CUDA
    • cuda Version according to nvcc (nvcc --version)
    • cuda version according to PyTorch (import torch; torch.version.cuda)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions