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

error: AttributeError: 'float' object has no attribute 'backward' #25

Open
KeranLi opened this issue Apr 23, 2023 · 2 comments
Open

error: AttributeError: 'float' object has no attribute 'backward' #25

KeranLi opened this issue Apr 23, 2023 · 2 comments

Comments

@KeranLi
Copy link

KeranLi commented Apr 23, 2023

Hi, I'm confused about the error: AttributeError: 'float' object has no attribute 'backward'
It occurs during the image-to-image translation. The details about the error information are:

────────── Traceback (most recent call last) ────────────────────────────────╮
│ /pix2pix-zero/src/edit_synthetic.py:51 in │
│ │
│ 48 │ pipe = EditingPipeline.from_pretrained(args.model_path, torch_dtype=torch_dtype).to( │
│ 49 │ pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) │
│ 50 │ │
│ ❱ 51 │ rec_pil, edit_pil = pipe(args.prompt_str, │
│ 52 │ │ num_inference_steps=args.num_ddim_steps, │
│ 53 │ │ x_in=x, │
│ 54 │ │ edit_dir=construct_direction(args.task_name), │
│ │
│ /pix2pix-zero/src/utils/edit_pipeline.py:150 in call
│ │
│ 147 │ │ │ │ │ │ ref = d_ref_t2attn[t.item()][name].detach().to(device) │
│ 148 │ │ │ │ │ │ cal = ((curr-ref)**2).sum((1,2)).mean(0) │
│ 149 │ │ │ │ │ │ loss += torch.tensor(cal, requires_grad=True) │
│ ❱ 150 │ │ │ │ loss.backward(retain_graph=False) │
│ 151 │ │ │ │ opt.step() │
│ 152 │ │ │ │ │
│ 153 │ │ │ │ # recompute the noise │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'float' object has no attribute 'backward'

I think the problem is caused by the line 149 in edit_pipline.py so I transfer it into a tensor, but it doesn't work. If possible, I wanna know what's wrong here. Thanks a lot!

@Pudding-0503
Copy link

I added this line of code loss = torch.tensor(0.0, requires_grad=True) after line 142 in the edit_pipline.py file, and it will work. Maybe you can try it?

@KeranLi
Copy link
Author

KeranLi commented May 6, 2023

Thanks, it's really helpful

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