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

Deepcopy in BPM prevents gradient calculation #225

Open
Hespe opened this issue Jul 23, 2024 · 1 comment
Open

Deepcopy in BPM prevents gradient calculation #225

Hespe opened this issue Jul 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Hespe
Copy link
Member

Hespe commented Jul 23, 2024

In the BPM, there is a call to deepcopy before passing on the beam down the line:

return deepcopy(incoming)

Unfortunetly, this copy currently inhibits taking gradients of the BPM reading. The reduced example

import torch
import cheetah

beam = cheetah.ParameterBeam.from_parameters(mu_x=torch.tensor([0.0], requires_grad=True))

bpm = cheetah.BPM()
bpm.track(beam)

fails with

RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment. If you were attempting to deepcopy a module, this may be because of a torch.nn.utils.weight_norm usage, see pytorch/pytorch#103001

@Hespe Hespe added the bug Something isn't working label Sep 2, 2024
@Hespe
Copy link
Member Author

Hespe commented Oct 7, 2024

Maybe the deepcopy can simply be replaced by a call to torch.clone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant