mirror of
https://github.com/wassname/ml-debug.git
synced 2026-06-27 17:31:04 +08:00
fix: apply Gemini review fixes (device kwarg, gradcheck requires_grad, torch prefix)
Review: Gemini 3.1 Pro approved. 3 fixes applied: - pinn/SKILL.md: PchipFunction torch.tensor missing device=h.device (GPU crash) - SKILL.md: gradcheck needs .requires_grad_(True) on doubled inputs - SKILL.md: loss surface pseudocode now has torch. prefix + indexing='ij'
This commit is contained in:
+3
-3
@@ -281,13 +281,13 @@ For heat exchangers with phase change, the T(h) mapping from REFPROP/GERG-2008 m
|
||||
def forward(ctx, h):
|
||||
T = pchip_interp(h.detach().numpy()) # scipy
|
||||
ctx.save_for_backward(h)
|
||||
return torch.tensor(T, dtype=h.dtype)
|
||||
return torch.tensor(T, dtype=h.dtype, device=h.device)
|
||||
|
||||
@staticmethod
|
||||
def backward(ctx, grad_output):
|
||||
h, = ctx.saved_tensors
|
||||
dTdh = pchip_interp.derivative()(h.detach().numpy()) # scipy
|
||||
return grad_output * torch.tensor(dTdh, dtype=h.dtype)
|
||||
dTdh = pchip_interp.derivative()(h.detach().cpu().numpy()) # scipy
|
||||
return grad_output * torch.tensor(dTdh, dtype=h.dtype, device=h.device)
|
||||
```
|
||||
5. Use float64 throughout. float32 loses precision near the phase boundary where dT/dh is small.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user