Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reparameterizing SpectralConv layers #310

Open
profPlum opened this issue Mar 26, 2024 · 1 comment
Open

Reparameterizing SpectralConv layers #310

profPlum opened this issue Mar 26, 2024 · 1 comment

Comments

@profPlum
Copy link

Hi I'm trying to apply 'parameterization constraints' as detailed in this tutorial. The problem is that this FNO library is rather unusual as it appears that SpectralConv doesn't have traditional "parameters", because when I try to do:

spectral_conv= SpectralConv(*args, **kwd_args)
parametrize.register_parametrization(spectral_conv, 'weight', MyParameterization())

It fails saying that:

ValueError: Module 'SpectralConv(
  (weight): ModuleList(
    (0): ComplexDenseTensor(shape=torch.Size([3, 3, 3]), rank=None)
  )
)' does not have a parameter, a buffer, or a parametrized element with name 'weight'

I've tried various troubleshooting methods like:

  1. Using the spectral_conv.named_parameters() name of the FNO layer parameters (called "weight.0.tensor")
  2. Trying to access spectral_conv[0].weight, which fails because it claims that the class "SubConv object has no attribute weight" even though it is clearly defined as a property... no idea whats happening here.
  3. And trying to manually convert the SpectralConv.weight[0] into a parameter but apparently a ComplexDenseTensor isn't an actual torch.Tensor since it doesn't implement detach()...

My Question: is it at all possible to apply 'parameterization constraints' as described in this tutorial?

@MaxGhi8
Copy link

MaxGhi8 commented May 16, 2024

Hi, I think a little about it and, in my opinion, you can't do this by a "user" of the library. I think that it is simpler to fork the library and make the modification that you want directly in the source code.
If I understand well you want to impose some constraint on the weight tensor within the spectral operator...
So, in your particular case, you can go to neuralop/layers/spectral_convolution.py and make the modification that you want directly to the weight variable of the class SpectralConv; between line $329$ and line $356$ of the mentioned file I think that you can find what you need.
Let me know if it is helpful and if you can implement what you want... If you want to provide more details about parameterization that you want to comment we can try to go beyond the code.

Best regards,
Massimiliano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants