Comments (4)
Hi @jk4011 !
Thanks for the bug report. So, my first suspicion would be that your data generator returns data that is on the CPU while you set up the default device to be GPU with set_up_backend("torch")?
Could you by any chance post a minimal code example to help me reproduce the problem? Then I would have a more detailed look.
Thanks!
from torchquad.
Hello @gomezzz
Of course!
import torch
from torchquad import set_up_backend
from torchvision import datasets
from torch.utils.data import DataLoader
# this error only occurs when cuda is available
assert(torch.cuda.is_available())
set_up_backend('torch')
training_data = datasets.MNIST(
root="data",
train=True,
download=True,
)
train_loader = DataLoader(training_data, batch_size=64, shuffle=True)
for (i, x) in enumerate(train_loader):
pass
and the error is like below
Traceback (most recent call last):
File "/home/wlsgur4011/torchlevy/tmp.py", line 19, in <module>
for (i, x) in enumerate(train_loader):
File "/home/wlsgur4011/.anaconda3/envs/torchlevy/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 681, in __next__
data = self._next_data()
File "/home/wlsgur4011/.anaconda3/envs/torchlevy/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 720, in _next_data
index = self._next_index() # may raise StopIteration
File "/home/wlsgur4011/.anaconda3/envs/torchlevy/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 671, in _next_index
return next(self._sampler_iter) # may raise StopIteration
File "/home/wlsgur4011/.anaconda3/envs/torchlevy/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 247, in __iter__
for idx in self.sampler:
File "/home/wlsgur4011/.anaconda3/envs/torchlevy/lib/python3.8/site-packages/torch/utils/data/sampler.py", line 132, in __iter__
yield from torch.randperm(n, generator=generator).tolist()
RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'
from torchquad.
Hi @jk4011
Sorry for the late reply 🙏 Busy days
Just tried the snippet and indeed same happens for me. However, I think, the problem is due to a missing device specification.
See also this stackoverflow post
Below snippet fixes the problem (and a follow-up one related to MNIST being PIL images) for me:
import torch
from torchquad import set_up_backend
from torchvision import datasets
from torch.utils.data import DataLoader
from torchvision import transforms
# this error only occurs when cuda is available
assert torch.cuda.is_available()
set_up_backend("torch")
transform = transforms.Compose(
[
# you can add other transformations in this list
transforms.ToTensor()
]
)
training_data = datasets.MNIST(
root="data", train=True, download=True, transform=transform
)
train_loader = DataLoader(
training_data,
batch_size=64,
shuffle=True,
generator=torch.Generator(device="cuda"),
)
for (i, x) in enumerate(train_loader):
pass
Does it fix it for you too, @jk4011 ? :)
from torchquad.
Should be fixed / not a problem in torchquad
from torchquad.
Related Issues (20)
- Change behavior of 'backend' HOT 6
- Elementwise numerical integration HOT 28
- Let user choose which GPU to use HOT 4
- Cannot import torchquad (conda install) HOT 2
- A lot of warnings in the current test CI on develop HOT 1
- Add tests for JIT HOT 2
- Evaluate many different integrands over the different domain HOT 6
- Coverage check fails on PRs HOT 1
- Release 0.4.0 HOT 8
- Tests failing on GPU HOT 15
- torch.tensor containing integers as integration domain returns zero with non-compiled integrator HOT 2
- Logging with loguru not implemented correctly
- Example/documentation for parametric domain of integration? HOT 9
- Integrate function with parameters HOT 3
- Google Colab TPU support HOT 8
- CI failing on coverage check
- Regression in tests with TF HOT 4
- depricated torch.set_default_tensor_type()
- torchquad0.4版本没有BatchMulVEGAS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchquad.