I have the following lines of code: with torch.enablegrad(): y = torch.randn(B, K, N, T,…
- User
I have the following lines of code:
with torch.enable_grad(): y = torch.randn(B, K, N, T, 2, device=pred.device) y = torch.nn.Parameter(y.detach(), requires_grad=True) print(y.requires_grad, y.mean())
I run this once separate from everything else, and the output of the print is "True tensor(0.0012, device='cuda:0', grad_fn=)". This is what I would expect, because y requires the gradient and thus it has a grad_fn. However, if I run the same lines of code within a large codebase hidden deeply in a complicated architecture, the result is "True tensor(-0.0005, device='cuda:0')". What could be a reason that there is no grad_fn in the second case?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.