GithubHelp home page GithubHelp logo

Comments (3)

holl- avatar holl- commented on August 22, 2024

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

from phiflow.

holl- avatar holl- commented on August 22, 2024

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.

from phiflow.

ne3x7 avatar ne3x7 commented on August 22, 2024

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!

from phiflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.