Closed ne3x7 closed 4 years ago
Hi Nikolai,
Thanks for your feedback! Unfortunately we don't have anyone with a lot of experience in PyTorch in our group, so we don't yet have advanced tests.
I'll look into the error shortly and post a fix.
Best, Philipp
I have fixed this issue in the develop branch. The following script now runs until the last line.
from phi.torch.flow import *
from torch.utils.data import TensorDataset, DataLoader
inputs = torch.rand(1000, 10, 10, 1)
targets = torch.rand(1000, 10, 10, 1)
dataset = TensorDataset(inputs, targets)
dataloader = DataLoader(dataset, batch_size=10)
domain = Domain([10, 10], boundaries=PERIODIC)
sz = domain.staggered_grid(0).staggered_tensor().shape
initial_velocity = torch.zeros(*sz)
initial_velocity = initial_velocity.expand(10, *initial_velocity.shape[1:])
velocity = torch.nn.Parameter(initial_velocity)
optimizer = torch.optim.Adam([velocity], lr=1e-3)
for epoch in range(10):
for batch_index, (inputs, targets) in enumerate(dataloader):
optimizer.zero_grad()
domain = Domain([10, 10], boundaries=PERIODIC)
fluid = Fluid(domain, batch_size=10, density=inputs, velocity=velocity)
density = advect.semi_lagrangian(fluid.density, fluid.velocity, dt=1)
density = diffuse(density, 1 * 0.1, substeps=1)
loss = math.l2_loss(density.data - targets)
loss.backward()
optimizer.step()
The optimizer.step()
still complains that
more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.
It sounds to me like the problem lies in the setup. Can you confirm this?
Note that Fluid.density
is read-only. Use fluid.copied_with(density=new_density)
to make an altered copy.
Thank you for such a prompt response. Indeed, Fluid
object is created correctly now. I also confirm that the problem with optimizer lies in the setup, to be precise, in the line initial_velocity = initial_velocity.expand(10, *initial_velocity.shape[1:])
. This operation should be done at each step when creating Fluid
object. I am now closing the issue, thank you again!
Hello, authors. First of all, thank you for your amazing work!
I can see that experimental PyTorch support has been added. I am trying to use it, but face some errors. Is it meant to be used yet? If so, could you please guide me through my error?
I am trying to use PhiFlow in a PyTorch-friendly style, and am getting an error when
Fluid
validates input density.I am trying to do approximately the following:
And I get the following error:
Error stackstrace
```python --------------------------------------------------------------------------- TypeError Traceback (most recent call last)I tried to track down where exactly my Tensor becomes numpy.ndarray, but failed to do so. I am getting this error both on master and develop branches.
A couple of comments regarding the piece of code above:
phi.torch
torch.zeros()
, becausemath.zeros()
returns numpy.ndarrayLooking forward to your answer, Nikolai