PML-380: Unitary device fix for g2#283
Conversation
|
@claude review |
|
Claude finished @LF-Vigneux's task in 1m 8s —— View job Code Review — PML-380: Unitary device fix for g2
SummaryThe fix is correct, minimal, and well-targeted. The two changed allocations in What I verified
Minor observations (non-blocking)
VerdictLooks good to merge. The core change is sound and mirrors the existing correct behavior. The observations above are optional test-quality nits, not correctness issues. |
CassNot
left a comment
There was a problem hiding this comment.
The fix does not work (cuda issue) once the perceval typo and type issue are solved (n=5 and dtype=np.complex64)
You will find my fix in the file attached:
- lines 214-215 and 225-226 and 232-238: I am ensuring the probs stay on the same device as the unitary (if g2_distinguishable or not)
- lines 783 and 796, I am also sending the bit_weight and convolution to the unitary.device
So now, all probability tensors are explicitly placed on the unitary's device before use. This should prevent device mismatch errors during convolution and other operations.
With all these fixes, it works on GPU
| ) | ||
|
|
||
| unitary = torch.tensor( | ||
| np.array(pcvl.Matrix.random_unitary(m=5), dtype=np.complex128), |
There was a problem hiding this comment.
here it should be n=5 and not m=5 otherwise it fails with a perceval error
There was a problem hiding this comment.
Another error from this line is that the type is np.complex128 which is inconsistent with the torch.float32 defaults types from the compute graph. If you set it, you need to change the type of the graph. My fix would be to just have the dtype=np.complex64 here and that works !
|
@claude I believe your analysis was wrong and the code was not working on GPU because
|
|
Claude finished @CassNot's task in 2m 12s —— View job Re-analysis — you're right, my earlier review was incomplete
You're correct, and my original review missed the real bug. I verified only the two allocations inside Where it actually breaks
for i, partition in enumerate(self._partitions):
bit_weight = self._weights[i] # built on self.device at construction (:701-704)
...
_, convolution = convolve_distributions(fock_states, *cell_distributions) # on unitary.device
output_probs += bit_weight * convolution * count.item() # CPU * CUDA -> device mismatch
Because the g2 graph gets The test never actually exercised the fixBoth of your review comments on
Corrected verdictChanges requested is right. The complete fix needs:
Thanks for catching this — apologies for the incomplete first pass. Want me to apply your attached |
Summary
Fixed this issue:
Noisy g2 path allocates on self.device/self.dtype, not unitary.device — merlin/pcvl_pytorch/noisy_slos.py:238-258,316. p_emit/weight_k and each SectorResult.tensor are built on self.device, while the sub-graph probs live on unitary.device. A CUDA unitary on a graph constructed with default device=None (without a prior .to()) raises a cross-device error. The non-g2 path correctly derives device from unitary.device (:768) — mirror that here.
Related Issue
PML-380
Type of change
Proposed changes
How to test / How to run
Documentation