nmichlo / disent

🧶 Modular VAE disentanglement framework for python built with PyTorch Lightning ▸ Including metrics and datasets ▸ With strongly supervised, weakly supervised and unsupervised methods ▸ Easily configured and run with Hydra config ▸ Inspired by disentanglement_lib
https://disent.michlo.dev
MIT License
122 stars 18 forks source link

[BUG]: "AssertionError: Torch not compiled with CUDA enabled" #16

Closed mhr closed 3 years ago

mhr commented 3 years ago

Hello,

First, thank you for creating this package, it will make my life so much easier. One problem I've run into though is that since installing the package, it only allows me to run my PyTorch models on the CPU, even though when I run torch.device(0), it gives me "cuda". But when I run torch.cuda.is_available(), I get False. I'm on a Windows machine. In another virtual environment, where I don't have disent installed, I can load my models on the GPU just fine. Any idea why this is happening? I'm going to keep playing around with installation of the different packages, and if I figure it out, I'll reply to this post with the solution.

def make_vae(beta):
    return BetaVae(
        make_optimizer_fn=lambda params: Adam(params, lr=5e-3),
        make_model_fn=lambda: AutoEncoder(
            encoder=EncoderConv64(x_shape=data.x_shape, z_size=6, z_multiplier=2),
            decoder=DecoderConv64(x_shape=data.x_shape, z_size=6),
        ),
        cfg=BetaVae.cfg(beta=beta)
    )

DEVICE = torch.device(0)
model = make_vae(beta=4).to(DEVICE) # Results in AssertionError
mhr commented 3 years ago

For me, I was able to make it work using pip install disent --user to install disent globally and then install PyTorch in a distinct virtual environment, which appears to allow disent to use all of its dependencies while allowing me to customize the version of PyTorch I'm using for my project. I realize this is probably not strictly kosher, but it does the trick.

I was able to run all of the import statements from https://disent.dontpanic.sh/en/latest/#metrics, except for from disent.frameworks.vae import BetaVae, which results in some module import errors.

That's okay for my purposes, since I'm going to just use the metrics functions for my project.

nmichlo commented 3 years ago

Thank you for reporting this, glad you found a solution.

I unfortunately wont re-open this issue as this should have been fixed in the development versions. I will however be working on trimming down the dependencies, and removing unnecessary parts of the project.