Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc++abi: terminating with uncaught exception of type std::length_error: vector #4419

Closed
yezhuoyang opened this issue Apr 5, 2022 · 14 comments

Comments

@yezhuoyang
Copy link

馃樀 Describe the installation problem

Hi guys! I've installed "torch_geometric" on my MAC OS, but when I import it in python code, a c++ error occurs as following:

libc++abi: terminating with uncaught exception of type std::length_error: vector
fish: Job 1, 'python3' terminated by signal SIGABRT (Abort)

I've installed all related package by pip install. And the error seems to be caused by the dynamic C++ library torch_geometric linked to but I cannot figure out why.

Environment

  • PyG version:pyg-nightly-2.0.5.dev20220405.tar.gz
  • PyTorch version:1.11.0
  • OS:MAC
  • Python version:3.9.7
  • CUDA/cuDNN version: No cuda
  • How you installed PyTorch and PyG (conda, pip, source): pip
  • Any other relevant information (e.g., version of torch-scatter): 2.0.9
@rusty1s
Copy link
Member

rusty1s commented Apr 6, 2022

I've never encountered this issue. Does it only apply to the nightly release of PyG or to torch-geometric==2.0.4 as well? Can you share some information about how you tried to install PyG? Does the same issue happen in case you install it in a fresh miniconda environment?

@arunppsg
Copy link
Contributor

arunppsg commented Apr 6, 2022

Is it the arm64 mac? sometimes it returns weird errors.

@yezhuoyang
Copy link
Author

yezhuoyang commented Apr 7, 2022

Is it the arm64 mac? sometimes it returns weird errors.

Thanks for reply!
My mac uses a 6-core Intel Core I7 processor.
Screen Shot 2022-04-07 at 2 28 10 PM

@yezhuoyang
Copy link
Author

I've never encountered this issue. Does it only apply to the nightly release of PyG or to torch-geometric==2.0.4 as well? Can you share some information about how you tried to install PyG? Does the same issue happen in case you install it in a fresh miniconda environment?

I use the command pip install torch-geometric first(On my system directly). And the error happens whenever I try to import torch_geometric

Screen Shot 2022-04-07 at 2 41 27 PM

Then, I uninstall the package by pip uninstall torch-geometric.

I run the command according to the following page , where I choose Pytorch 1.11.*, Mac, Pip, Cpu
https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html

pip3 install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cpu.html

However, the error still remains.

@rusty1s
Copy link
Member

rusty1s commented Apr 7, 2022

Can you show me the output of which python3? Do you use the system-wide Python? It might be a good idea to install miniconda and try again. Let me know!

@yezhuoyang
Copy link
Author

yezhuoyang commented Apr 7, 2022

Can you show me the output of which python3? Do you use the system-wide Python? It might be a good idea to install miniconda and try again. Let me know!

Installing in miniconda is a great suggestion and solve my problem.
I create a conda virtual environment myvenv, activate myenv, and then use conda install command
conda install pyg -c pyg.
Then the import works fine!

Screen Shot 2022-04-07 at 5 08 47 PM

However, when I deactivate conda, the problem is still there.
As you can see in the following:
Screen Shot 2022-04-07 at 5 00 35 PM

It seems that pip install has some problem with system-wide Python.

@mysakbm
Copy link

mysakbm commented Apr 9, 2022

I have the very same problem with importing torch vision.
I'm on the most updated MacBook M1, Monterey, latest update, fresh instalation. Python 3.9.12.

@rusty1s
Copy link
Member

rusty1s commented Apr 9, 2022

@yezhuoyang I think it is good practice to work in personal environments. Glad that it is resolved!

@mysakbm What's the problem with the installation of torchvision? It might be best to ask for help directly in pytorch/vision repo though.

@jtduran
Copy link

jtduran commented May 1, 2022

I have an M1 mac running only miniconda (for the arm natively compiled stuff ) where everything works fine and I have an i9 mac running regular conda where I get the same error, tried adding miniconda and switching to that got same error, guessing I need to nuke the whole conda install which I don't want to do. I will go with the M1 I guess.
libc++abi: terminating with uncaught exception of type std::length_error: vector

@mnbucher
Copy link

mnbucher commented Jun 7, 2022

can confirm that using venv (or conda) resolved the issue for me as well.

@21S003018
Copy link

I have exactly the same problem! I solved it by uninstall all the depencies: torch-sparse\scatter\cluster\spline-conv. And re-install with pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cpu.html.

@ruandocini
Copy link

I used the solutions presented here but It did not work.
If this happens to anyone, I used this to fix my problem -> #rusty1s/pytorch_scatter#241

@zzyzeyuan
Copy link

I have exactly the same problem! I solved it by uninstall all the depencies: torch-sparse\scatter\cluster\spline-conv. And re-install with pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cpu.html.

It does work! very helpful!

fabOnReact added a commit to fabOnReact/react-native that referenced this issue Nov 11, 2022
SOLUTION: Clearing the cache fixed the issue ([comment](pyg-team/pytorch_geometric#4419 (comment))). The user was experiencing similar issue on arm64.
It reports errors that result from attempts to exceed implementation defined length limits for some object ([link](https://en.cppreference.com/w/cpp/error/length_error)).

"Adding a string prop to TextAttributes.cpp:
Read error message with Android Studio ([screenshot](https://www.icloud.com/iclouddrive/053tE1XWF0rgVUMxmLhUJTJUA#terminating_std_length_error_vector))
Search online for the error message and understand the configuration mistake in the cpp type ([link](https://www.google.com/search?q=terminating+with+uncaught+exception+of+type+std::length_error:+vector))鈥╰erminating with uncaught exception of type std::length_error: vector
Verify all changes from [#2](https://github.com/fabriziobertoglio1987/react-native/pull/2/files) are added in [#3](https://github.com/fabriziobertoglio1987/react-native/pull/3/files)鈥╒erify there are no mistakes in the types
Read about APIs that you added to cpp
Read complete logcat errors
Does it build only with the Java Changes?鈥–ommit the java changes and stash cpp鈥═he error std::length_error: vector indicates wrong cpp type
@limitless-insanity
Copy link

limitless-insanity commented Oct 23, 2023

I know it's strange but I got this while not doing anything with python whatsoever. this is the c++ program:

#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
vector<int> MinimumCoins(int n)
{
    int arr[] = {10, 20, 30};
    int k = sizeof(arr) / sizeof(arr[0]);
    vector<int> coinValues(arr, arr + k);
    int numCoins = coinValues.size();
    vector<int> result;
    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;
    vector<int> lastCoin(n + 1, -1);
    for (int i; i <= n; i++)
    {
        for (int j = 0; j <= numCoins; j++)
        {
            if (coinValues[j] <= i && dp[i - coinValues[j]] + 1 < dp[i])
            {
                dp[i] = dp[i - coinValues[j]] + 1;
                lastCoin[i] = j;
            }
        }
    }
    if (dp[n] == INT_MAX)
        return result;
    int current = n;
    while (current > 0)
    {
        int coinIndex = lastCoin[current];
        result.push_back(coinValues[coinIndex]);
        current -= coinValues[coinIndex];
    }
    sort(result.begin(), result.end(), greater<int>());
    for (int i = 0; i < result.size(); i++)
    {
        cout << result[i] << " ";
    }
    return result;
}

int main()
{
    int n = -13;
    vector<int> result = MinimumCoins(n);
    if (result.empty())
    {
        cout << "-1";
    }
    else
    {
        sort(result.begin(), result.end(), greater<int>());
        for (int i = 0; i < result.size(); i++)
        {
            cout << result[i] << " ";
        }
    }
    return 0;
}

its a basic program of Dsa...

and now this is the error:

libc++abi: terminating due to uncaught exception of type std::length_error: vector
/bin/sh: line 1: 22734 Abort trap: 6 

I am using c++11 to compile in Mac m1.
can anybody help??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants