Coder Social home page Coder Social logo

Comments (9)

ar4 avatar ar4 commented on August 29, 2024 1

Using TorchScript might also make your code run faster, too, so I think it is worth the effort of making sure you write your code in a way that torch.jit.script can be applied to it.

Do you create ax and bx using the setup_pml code from Deepwave? Printing the value of ax.requires_grad and bx.requires_grad inside your rs_cpml_absorb function would be useful to verify that it didn't get set to True somehow for them.

from deepwave.

ar4 avatar ar4 commented on August 29, 2024 1

If you did use Deepwave's setup_pml, is it possible that you passed the max_vel value using v.max() rather than v.detach().max(), and so the max_vel value has requires_grad=True, causing ax and bx to also have it set to True?

from deepwave.

YingchangLiu avatar YingchangLiu commented on August 29, 2024 1

Thank you very much, Dr Richardson.

The problem is indeed ax.require_grad. As you mentioned, I use the velocity parameter directly when calculating max_vel.

v_max=torch.max(vp)
az,bz,ddz,ax,bx,ddx = rs_cpml_parameter(vshape=self.mesh.shape,dzyx=self.mesh.size,H=self.mesh.H,vp_max=v_max,fm=self.source.f0,dt=self.mesh.dt,device=self.device)

That's amazing! Your programming ability and expertise amaze me.

Thanks for your solution!

from deepwave.

YingchangLiu avatar YingchangLiu commented on August 29, 2024

In addition, cpml greatly increases the memory requirements of the computation graphs. I'm thinking of replacing it with a simple sponge boundary condition.

from deepwave.

ar4 avatar ar4 commented on August 29, 2024

Hello @kelen51215

Does this mean that installation of Deepwave on Windows is still a problem, and that is why you have resorted to writing a pure PyTorch version?

I don't see any problem in the code that you provided, so I suspect that the problem must be occurring elsewhere. Are there any inplace operations (like a += b) in your code? Have you tried running with torch.autograd.set_detect_anomaly(True) to see if it provides more clarity on where the problem is occurring?

There are definitely advantages of just using a simple sponge boundary in certain situations. The absorption will probably not be as good as with CPML, but I suspect that it will indeed reduce the memory usage when relying on automatic differentiation.

from deepwave.

YingchangLiu avatar YingchangLiu commented on August 29, 2024

The new version of deepwave works well on Windows.

I am testing anisotropic parameter inversion, so I rewrote the package for flexibility.

The inplace operations have been removed earlier. This problem only occurs when adding CPML boundaries. I am using detect_anomaly to detect where the problem occurred.

from deepwave.

ar4 avatar ar4 commented on August 29, 2024

That is good news about Windows.

I just noticed in the code you showed there is the line

wavefield.p +=  self.mesh.dt * Mp * (dvxdx + dvzdz)

An in-place operation like that might cause problems. I suggest changing it to

wavefield.p = wavefield.p + self.mesh.dt * Mp * (dvxdx + dvzdz)

and the same with any other inplace operations that you have.

from deepwave.

YingchangLiu avatar YingchangLiu commented on August 29, 2024

Copy that!

I'm sure all += and *= are removed from the program, and I'm replacing the element.

Just discovering that either ax or bx exists causes an error. Replacing them with a constant will not result in an error. I'm trying to find out why. Thank you for your advice.

def rs_cpml_absorb(dpdx, cpml_dpdx ,ax, bx, kkx):
    cpml_dpdx = bx * cpml_dpdx + ax * dpdx
    dpdx = dpdx / kkx + cpml_dpdx
    return dpdx, cpml_dpdx

from deepwave.

ar4 avatar ar4 commented on August 29, 2024

That is quite strange. I cannot see any problem with that code. One idea that might help to diagnose the problem is to run your code through PyTorch's TorchScript interpreter. You will need to specify the types of inputs and outputs of all of your functions that are not Tensors, and then call torch.jit.script(). The error messages from the interpreter are sometimes more detailed and so might indicate where the problem is.

from deepwave.

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.