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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrowing error on macOS #127

Closed
dfm opened this issue Oct 23, 2020 · 11 comments · Fixed by #972
Closed

Narrowing error on macOS #127

dfm opened this issue Oct 23, 2020 · 11 comments · Fixed by #972
Assignees
Labels
bug Something isn't working C-backend enhancement New feature or request MacOS

Comments

@dfm
Copy link
Contributor

dfm commented Oct 23, 2020

Compiling ops with fast_run on macOS results in an error because of "narrowing". This is a known issue (e.g. pymc-devs/pymc#3695) that is handled by downstream projects like PyMC3 (pymc-devs/pymc#3767). I propose that we fix this here by adding the -Wno-c++11-narrowing flag to theano.config.gcc.cxxflags by default on macOS.

Please provide a minimal, self-contained, and reproducible example.

import theano
import theano.tensor as tt
a = tt.dmatrix()
b = tt.dvector()
c = tt.dmatrix()
theano.function([a, b, c], tt.dot(a, b + c))

Please provide the full traceback of any errors.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/compile/function.py", line 341, in function
    fn = pfunc(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/compile/pfunc.py", line 538, in pfunc
    return orig_function(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/compile/function_module.py", line 1997, in orig_function
    fn = m.create(defaults)
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/compile/function_module.py", line 1850, in create
    _fn, _i, _o = self.linker.make_thunk(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/link.py", line 738, in make_thunk
    return self.make_all(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/vm.py", line 1145, in make_all
    node.op.make_thunk(node, storage_map, compute_map, [], impl=impl)
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/op.py", line 980, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/op.py", line 877, in make_c_thunk
    outputs = cl.make_thunk(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cc.py", line 1275, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cc.py", line 1204, in __compile__
    thunk, module = self.cthunk_factory(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cc.py", line 1720, in cthunk_factory
    module = get_module_cache().module_from_key(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cmodule.py", line 1229, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cc.py", line 1610, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/dforeman/src/pymc-devs/Theano-PyMC/theano/gof/cmodule.py", line 2567, in compile_str
    raise Exception(
Exception: ('The following error happened while compiling the node', Elemwise{add,no_inplace}(InplaceDimShuffle{x,0}.0, <TensorType(float64, matrix)>), '\n', "Compilation failed (return status=1): /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:524:27: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V5_n0, V3_n1};.                           ^~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:524:27: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V5_n0, V3_n1};.                           ^~~~~.                           static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:524:34: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V5_n0, V3_n1};.                                  ^~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:524:34: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V5_n0, V3_n1};.                                  ^~~~~.                                  static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:536:12: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].         0, V3_stride1, .            ^~~~~~~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:536:12: note: insert an explicit cast to silence this issue.         0, V3_stride1, .            ^~~~~~~~~~.            static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:537:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V5_stride0, V5_stride1, . ^~~~~~~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:537:1: note: insert an explicit cast to silence this issue. V5_stride0, V5_stride1, . ^~~~~~~~~~. static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:537:13: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V5_stride0, V5_stride1, .             ^~~~~~~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:537:13: note: insert an explicit cast to silence this issue. V5_stride0, V5_stride1, .             ^~~~~~~~~~.             static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:538:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1. ^~~~~~~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:538:1: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1. ^~~~~~~~~~. static_cast<int>( ). /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:538:13: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1.             ^~~~~~~~~~. /Users/dforeman/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpsatm5hgs/mod.cpp:538:13: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1.             ^~~~~~~~~~.             static_cast<int>( ). 7 errors generated.. ", '[Elemwise{add,no_inplace}(<TensorType(float64, row)>, <TensorType(float64, matrix)>)]')

Please provide any additional information below.

Versions and main components

  • Theano version: GitHub master
  • Theano config (python -c "import theano; print(theano.config)")
  • Python version: 3.8
  • Operating system: macos
  • How did you install Theano: pip (-e)
@brandonwillard
Copy link
Member

Any reason why we wouldn't?

@dfm
Copy link
Contributor Author

dfm commented Oct 23, 2020

I don't think there is any reason not to and I'm happy to implement. If anyone has reasons not to, let me know!

@axiezai
Copy link

axiezai commented Mar 9, 2021

Hi just wondering if there is any updates on this?

I am running the following code:

import theano
import theano.tensor as tt

theano.config.gcc.cxxflags = "-Wno-c++11-narrowing"

a = tt.dmatrix()
b = tt.dvector()
c = tt.dmatrix()
theano.function([a, b, c], tt.dot(a, b + c))

And still receiving the same error:

Exception: ('The following error happened while compiling the node', Elemwise{add,no_inplace}(InplaceDimShuffle{x,0}.0, <TensorType(float64, matrix)>), '\n', "Compilation failed (return status=1): /Users/xxie/.theano/compiledir_Darwin-19.6.0-x86_64-i386-64bit-i386-3.7.9-64/tmprz_0y49f/mod.cpp:524:27: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V3_n0, V5_n1};.                           ^~~~~. /Users/xxie/.theano/compiledir_Darwin-19.6.0-x86_64-i386-64bit-i386-3.7.9-64/tmprz_0y49f/mod.cpp:524:27: note: insert an explicit cast to silence this issue.

My settings on MacOS Catalina:

python --version: Python 3.7.9

conda list | grep theano
theano                    1.0.5            py37h54c7649_1    conda-forge
theano-pymc               1.1.0            py37h54c7649_1    conda-forge

My end goal is to use theano or aesara's rfft, but obviously that function compile is failing with the same issue. Please let me know if there's any progress or if i can provide more info. Thanks in advance.

@axiezai
Copy link

axiezai commented Mar 9, 2021

BTW, same issue when trying with aesara instead of theano function

@brandonwillard
Copy link
Member

BTW, same issue when trying with aesara instead of theano function

All examples and discussions should be strictly in terms of the codebase after the theano -> aesara change—especially since there have been changes to the config settings since then (e.g. the gcc.cxxflags option has been renamed).

@axiezai
Copy link

axiezai commented Mar 9, 2021

Then is there another flag I can try to solve this issue on MacOS? Like I mentioned, setting theano.config.gcc.cxxflags = "-Wno-c++11-narrowing" didn't solve the error for me, is there a new config I can try in aesara?

@brandonwillard
Copy link
Member

Oh, no, I wasn't recommending anything else to try; I was only pointing out how these theano-based examples are now outdated, so anyone attempting to reproduce a bug/fix will run into problems.

More specifically, theano.config.gcc.cxxflags is now aesara.config.gcc__cxxflags, so a simple theano -> aesara replacement won't work in that case.

@axiezai
Copy link

axiezai commented Mar 10, 2021

Thank you for clarifying, i will retry running the example on an ubuntu machine instead for now.

@brandonwillard
Copy link
Member

Unfortunately, I can't even try to reproduce that error locally, since I don't have a Mac. If it's possible to reproduce it in a virtual machine, I can take a look.

@dfm
Copy link
Contributor Author

dfm commented Mar 11, 2021

I just checked and I can also no longer reproduce this on my Mac with Python 3.9.1 (from conda) and the master branch of Aesara.

@axiezai
Copy link

axiezai commented Mar 11, 2021

Oh, that's hopeful news, I will upgrade my python and aesara versions. Thank you!

dgerlanc added a commit to dgerlanc/aesara that referenced this issue May 13, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue May 24, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue May 31, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue May 31, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Jun 7, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Jun 9, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Jun 14, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Oct 9, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Nov 29, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Nov 30, 2022
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Dec 2, 2022
brandonwillard pushed a commit to dgerlanc/aesara that referenced this issue Feb 15, 2023
dgerlanc added a commit to dgerlanc/aesara that referenced this issue Feb 17, 2023
brandonwillard pushed a commit to dgerlanc/aesara that referenced this issue Feb 17, 2023
dgerlanc added a commit that referenced this issue Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C-backend enhancement New feature or request MacOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants