ganspace icon indicating copy to clipboard operation
ganspace copied to clipboard

AttributeError because initgl() never called

Open natoucs-datagen opened this issue 4 years ago • 16 comments

When running interactive.py, I get an AttributeError with the TorchImageView object on attributes such as 't_last' or 'tex'.

Looking into it, this is because the code calls draw() without ever calling before initgl() where those attributes are first initialized.

Could you point to me the right place to call initgl() so those attributes are initialized ?

natoucs-datagen avatar May 18 '20 08:05 natoucs-datagen

The method initgl() is supposed to be called by the base class BaseOpenGLFrame when the frame is show on the screen - see https://github.com/jonwright/pyopengltk/blob/master/pyopengltk/base.py#L30. I have no idea why it's not being called for you, perhaps this is related to the other issues you've opened?

harskish avatar May 19 '20 11:05 harskish

ah ok makes sense! I checked and pyopengltk has been installed. I'll look into it more.

natoucs-datagen avatar May 19 '20 14:05 natoucs-datagen

I am having the same issue - see my error readout below.

What happens is the GUI appears momentarily before crashing. I'm on windows.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\site-packages\pyopengltk\base.py", line 74, in tkExpose
    self._display()
  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\site-packages\pyopengltk\base.py", line 98, in _display
    self.redraw()
  File "C:\ganspace\TkTorchWindow.py", line 141, in redraw
    dt = t_now - self.t_last
AttributeError: 'TorchImageView' object has no attribute 't_last'
Traceback (most recent call last):
  File "interactive.py", line 651, in <module>
    app.update()
  File "C:\ganspace\TkTorchWindow.py", line 198, in update
    self.redraw()
  File "C:\ganspace\TkTorchWindow.py", line 141, in redraw
    dt = t_now - self.t_last
AttributeError: 'TorchImageView' object has no attribute 't_last'

adamdavidconn avatar May 20 '20 10:05 adamdavidconn

So Ive narrowed it down to pycuda.gl.autoinit failing to import in the function setup_gl Traceback:

  File "<ipython-input-30-abae472cf583>", line 1, in <module>
    import pycuda.gl.autoinit

  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\site-packages\pycuda\gl\autoinit.py", line 9, in <module>
    context = make_default_context(lambda dev: cudagl.make_context(dev))

  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\site-packages\pycuda\tools.py", line 204, in make_default_context
    "on any of the %d detected devices" % ndevices)

RuntimeError: make_default_context() wasn't able to create a context on any of the 1 detected devices

Seems like an issue with the pycuda install. To install it I pip installed pytools (https://www.lfd.uci.edu/~gohlke/pythonlibs/#pytools) and then pycuda (pycuda‑2019.1.2+cuda101‑cp37‑cp37m‑win_amd64.whl) as I have cuda 10.1. Is this correct?

adamdavidconn avatar May 20 '20 14:05 adamdavidconn

I am stuck at the same step (getting the make_default_context() error) and am also using cuda 10.1. Why did you need pytools to get PyCuda by the way ?

natoucs-datagen avatar May 21 '20 07:05 natoucs-datagen

@adamdavidconn the Windows dependencies are included under deps/windows, could you try to install all of those to see if it helps? The process is detailed in the setup instructions.

In general, it would be great if ether of you could make a minimal example that fails, which could then be filed as a pycuda bug.

harskish avatar May 21 '20 07:05 harskish

Oh, I misunderstood that line of the instructions, Ill try and install those deps now and let you know if fixed. Thanks!

adamdavidconn avatar May 21 '20 08:05 adamdavidconn

So installing the windows dependencies did not solve the issue.

Delving a bit further: import pycuda.gl.autoinit is failing. Within that module the line context = make_default_context(lambda dev: cudagl.make_context(dev)) is failing, throwing the below error:

Traceback (most recent call last):

  File "<ipython-input-24-69046de7b68f>", line 1, in <module>
    context = make_default_context(lambda dev: cudagl.make_context(dev))

  File "C:\Users\adconn\miniconda3\envs\ganspace\lib\site-packages\pycuda\tools.py", line 204, in make_default_context
    "on any of the %d detected devices" % ndevices)

RuntimeError: make_default_context() wasn't able to create a context on any of the 1 detected devices0

Looking at the function make_default_context the line devn = os.environ.get("CUDA_DEVICE") is returning None. @harskish is your cuda_device system variable set to anything?

adamdavidconn avatar May 21 '20 09:05 adamdavidconn

Neither CUDA_DEVICE nor .cuda_device is set on my machine, and make_default_context() returns after the first iteration of the for loop.

harskish avatar May 21 '20 10:05 harskish

Was this ever resolved? I'm stuck with the same issue. Running Ubuntu 18.04.

Rebuilt my Anaconda environment and still the same.

Am able to run the pyopengltk "basic example" here: https://github.com/jonwright/pyopengltk

Is there some way to explicitly run the gl initialization routine if pyopengltk isn't calling it properly?

Here's the full error:

Loaded components for car from /mnt/hdd/pytorch/ganspace2/cache/components/stylegan2-car_style_ipca_c80_n1000000.npz Seed: 1764490008 GLX version: 1.4 Screen is 0 libGL error: No matching fbConfigs or visuals found libGL error: failed to load driver: swrast Number of FBconfigs 40 Got a matching visual: index 5 34 xid 0x22 Is Direct?: 0 Done making a first context Exception in Tkinter callback Traceback (most recent call last): File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/tkinter/__init__.py", line 1705, in __call__ return self.func(*args) File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pyopengltk/base.py", line 30, in tkMap self.initgl() File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 80, in initgl self.setup_gl(self.width, self.height) File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 94, in setup_gl import pycuda.gl.autoinit File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pycuda-2019.1.2-py3.7-linux-x86_64.egg/pycuda/gl/autoinit.py", line 9, in <module> context = make_default_context(lambda dev: cudagl.make_context(dev)) File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pycuda-2019.1.2-py3.7-linux-x86_64.egg/pycuda/tools.py", line 204, in make_default_context "on any of the %d detected devices" % ndevices) RuntimeError: make_default_context() wasn't able to create a context on any of the 1 detected devices Exception in Tkinter callback Traceback (most recent call last): File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/tkinter/__init__.py", line 1705, in __call__ return self.func(*args) File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pyopengltk/base.py", line 74, in tkExpose self._display() File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pyopengltk/base.py", line 98, in _display self.redraw() File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 147, in redraw dt = t_now - self.t_last AttributeError: 'TorchImageView' object has no attribute 't_last' Exception in Tkinter callback Traceback (most recent call last): File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/tkinter/__init__.py", line 1705, in __call__ return self.func(*args) File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pyopengltk/base.py", line 74, in tkExpose self._display() File "/home/user/anaconda3/envs/ganspace2/lib/python3.7/site-packages/pyopengltk/base.py", line 98, in _display self.redraw() File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 147, in redraw dt = t_now - self.t_last AttributeError: 'TorchImageView' object has no attribute 't_last' Traceback (most recent call last): File "interactive.py", line 652, in <module> app.update() File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 204, in update self.redraw() File "/mnt/hdd/pytorch/ganspace2/TkTorchWindow.py", line 147, in redraw dt = t_now - self.t_last AttributeError: 'TorchImageView' object has no attribute 't_last'

botty-mc-bot-face avatar Jun 21 '20 13:06 botty-mc-bot-face

Hmmm.....

Been running my Linux over ssh from a Mac; Linux box has 2 graphics cards: an AMD to drive a monitor when I need it, and the NVIDIA for compute.

Just pulled the AMD card out and plugged the monitor into NVIDIA. Reboot.

Can now run GANSpace directly on Linux box, but not over ethernet from Mac.

Running remotely still emits "AttributeError: 'TorchImageView' object has no attribute 't_last'"

FYI.

Thanks for your work, this software looks fun!

botty-mc-bot-face avatar Jun 21 '20 14:06 botty-mc-bot-face

Thank you @botty-mc-bot-face , this is very useful information. @adamdavidconn and @natoucs-datagen , would you be able to confirm whether or not you were also trying to run over ssh (e.g. using X11 forwarding)?

harskish avatar Jun 23 '20 11:06 harskish

yes I was

natoucs-datagen avatar Jun 23 '20 12:06 natoucs-datagen

@harskish glad to be able to remunerate the libre community for the free-of-cost software I use! I'm just trying to do my part to destroy the white collar with ubiquitous A.I. running on cheap video game hardware. Soon we will have no need for designers, coders, models or retouch artists, painters, musicians, or actors. That is, talent. When the global warming from the CO2 created by the booming electrical demand for cloud computing kicks off the next Ice Age by pushing us over the tipping point into the collapse of trans-oceanic air currents, the devastating disruptions in the delicate balance between climactic stability and the agricultural systems civilization has depended upon for the last 10,000 years will make Earth a perfect location for the new super-cooled data warehouse required by the hyper-advanced pink dromedaries in Alpha Centauri, who need to process quazilliaflops of digital sensor readings in floating point arithmetic output from the black hole hypercomputers they manage around over a dozen singularities. Good luck surviving the plague, revolution, drunk drivers, terrorists, fascists, antifascists, and inter-dimensional alien invaders lol!

botty-mc-bot-face avatar Jun 27 '20 01:06 botty-mc-bot-face

I have the exact same error on Azure Windows VM with Nvidia GPU.

I checked that all dependencies from /deps/windows have been installed. The basic pyopengltk example runs for me as well. CUDA_DEVICE is not set on my machine.

Is there anything else I can try?

gingergenius avatar Oct 13 '20 14:10 gingergenius

I get the same errors on a V100 on a cluster, using X11 forwarding. Did anybody make it work?

edgarschnfld avatar Nov 13 '21 21:11 edgarschnfld