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

[Bug] Afar not working with cudf/dask-cudf/gpu-numba #29

Closed
ncclementi opened this issue Sep 30, 2021 · 4 comments · Fixed by #30
Closed

[Bug] Afar not working with cudf/dask-cudf/gpu-numba #29

ncclementi opened this issue Sep 30, 2021 · 4 comments · Fixed by #30

Comments

@ncclementi
Copy link

When trying to use afar with cudf, it's not working the problem seems to be with numba when using gpu (numba jit by itself has no problems)

Minimal reproducible example:

with afar.run, remotely:
    import cudf
    x = str(cudf)

x.result() retrieves

AttributeError: 'LocalPrint' object has no attribute '__name__'

after looking into the traceback

import traceback

traceback.print_tb(x.traceback())

I get the following:

  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/afar/_core.py", line 337, in run_afar
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/innerscope/core.py", line 492, in __call__
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/innerscope/core.py", line 541, in _call
  File "<afar>", line 2, in _afar_magic_
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/cudf/__init__.py", line 4, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/cudf/utils/gpu_utils.py", line 18, in validate_setup
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/rmm/__init__.py", line 16, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/rmm/mr.py", line 2, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/rmm/_lib/__init__.py", line 3, in <module>
  File "rmm/_lib/device_buffer.pyx", line 1, in init rmm._lib.device_buffer
  File "rmm/_cuda/stream.pyx", line 26, in init rmm._cuda.stream
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/__init__.py", line 39, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/decorators.py", line 12, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/stencils/stencil.py", line 11, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/registry.py", line 4, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/dispatcher.py", line 16, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/compiler.py", line 6, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/callconv.py", line 12, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/base.py", line 24, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/cpython/builtins.py", line 511, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/typing/builtins.py", line 22, in <module>
  File "/opt/conda/envs/rapids/lib/python3.8/site-packages/numba/core/typing/templates.py", line 1157, in register_global

I'm using numba=0.53 which line 1157 corresponds to the following https://github.com/numba/numba/blob/release0.53/numba/core/typing/templates.py#L1157-L1159

Which is trying to get .__name__ from LocalPrint

Looking at this all issue numpy/numpy#3112 (comment) it seems that in the numba end (https://github.com/numba/numba/blob/97fe221b3704bd17567b57ea47f4fc6604476cf9/numba/core/typing/templates.py#L1161-L1163) they are not updating the wraper as suggested here https://docs.python.org/3.3/library/functools.html#functools.update_wrapper, meaning that it is not assigning __name__ to LocalPrint when it gets there.

I wonder if there is a way of fixing this on afar maybe on LocalPrint().

@eriknw
Copy link
Owner

eriknw commented Sep 30, 2021

Oh no!

Thanks for the excellent bug report (and for using afar!). I'll see what I can do.

Perhaps LocalPrint could mock itself as builtins.print by setting it's __module__ and __name__ attribute as such. Far from being hacky and sinful, this may actually be a reasonable thing to do.

@jcrist
Copy link

jcrist commented Sep 30, 2021

Perhaps LocalPrint could mock itself as builtins.print by setting it's module and name attribute as such. Far from being hacky and sinful, this may actually be a reasonable thing to do.

That might work. Another option would be to spoof sys.stdout as a threadlocal IO type and leave print alone. When no file is passed to print, it will dynamically getattr(sys, "stdout") every call, letting you still capture stdout without modifying builtins.

eriknw added a commit that referenced this issue Sep 30, 2021
Fixes #29 (probably).  This was a quick and easy fix, so let's see how far it takes us.

@jcrist's suggestion to instead monkey-patch `sys.stdout` (and `sys.stderr`)
is a good idea, and we may want to give it a try too.
@eriknw
Copy link
Owner

eriknw commented Oct 1, 2021

Release version 0.6.1 with the easy fix 🤞 . On PyPI, and should be available from conda-forge soon.

Heh, I don't know whether to be proud or embarrassed by afar's code. It's... something. But, it works, and it brings me laughter 😂 !

@ncclementi
Copy link
Author

ncclementi commented Oct 1, 2021

@eriknw awesome, we'll give it a try soon and I'll keep you updated!
Cheers to bringing laughter 😂 !

Edit: tried it and indeed it worked! Thank you for your work!

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

Successfully merging a pull request may close this issue.

3 participants