Comments (6)
For any user needing a quick (probably unsafe) fix, the following worked for my use case:
def patch_abs(t):
if (t.device == torch.device("mps:0")) and (t.dtype == torch.complex64):
return torch.sqrt(torch.pow(torch.real(t), 2) + torch.pow(torch.imag(t), 2) + 1e-12)
return torch.abs(t)
torch.Tensor.abs = patch_abs
with torch.device("cpu"):
print(torch.ones((2,), dtype=torch.complex64).abs())
with torch.device("mps"):
print(torch.ones((2,), dtype=torch.complex64).abs())
print(torch.tensor([1.0 + 0.0j, 0.0 + 10.0j, 100.0 + 0.0j, 1000.0 + 0.0j]).abs())
Output:
tensor([1., 1.])
tensor([1., 1.], device='mps:0')
tensor([ 1., 10., 100., 1000.], device='mps:0')
from pytorch.
Grabbing for myself, wish there was a proper doc for https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraph/3564540-absolutewithtensor?language=objc
from pytorch.
Hi @malfet! Wanted to add some context as I did have a brief discussion with some of the MPSGraph people regarding this issue and that particular op. My current hypothesis on what happens:
- If MPSGraph abs op gets passed an op that is data type Complex64, it will return a tensor of the same type. However if I print the type of the output from the CPU abs() (and the MPS abs for that matter) using the above snippet provided in the error it seems to be in float32. So probably the complex parts get dropped due to this conversion not being handled explicitly/correctly in the MPS abs implementation and we end up just interpreting the complex tensor as a float32 tensor. This would make complex 1+0i look like a float2 [1,0] tensor.
- If that's the case, we should check for complex data type in the abs op and explicitly take the real part of the complex output of the graph op absoluteWithTensor. There should be an API
-(MPSGraphTensor *) realPartOfTensor:(MPSGraphTensor *) tensor name:(NSString * _Nullable) name
that should do the trick.
Unfortunately I'm drowning in other work this week so I'm more than happy to let anyone take a shot at this if they'd like.
from pytorch.
Hi @bdhirsh !
First time contributor here. Could I work on this bug?
from pytorch.
@gambiTarun sorry, missed your comment. How familiar are you with ObjC/MPS framework?
from pytorch.
Hi @malfet, no worries! I’m not familiar with ObjC/MPS, but I’m willing to learn. If you could point me in the right direction for resolving this bug, or suggest some resources, I'd appreciate it!
from pytorch.
Related Issues (20)
- "torch.geqrf" performs differently on cpu and gpu HOT 7
- "torch.matrix_exp" performs differently on cpu and gpu HOT 6
- [cudagraph] simplify usage of how cudagraph dumps debug file HOT 2
- inplace parameter in dropouts should function as expected regardless of the value of training(or train) paramter HOT 2
- "torch.unique" performs differently on cpu and gpu HOT 3
- The unexpected behavior of `min()` HOT 1
- The unexpected behavior of `max()` HOT 1
- "torch.orgqr" performs differently on cpu and gpu HOT 2
- Feature request to add the SReLU activation function
- When testing the scalar version, test_torchinductor.py will fail HOT 2
- OOM Message is truncated HOT 2
- Third party LICENSE collection error when build wheel package HOT 10
- _convert_input_to_fake doesn't work when there are no inputs HOT 1
- Give`wait_tensor()` a schema that reflects its side effect HOT 4
- torch.onnx.dynamo_export nn.Bilinear's aten._trilinear HOT 2
- The significant difference between the outputs of torch.reciprocal running on cpu and gpu HOT 2
- One complex number or boolean value of a 1D or more D tensor with `argmin()` and `dim=` works HOT 1
- One complex number or boolean value of a 1D or more D tensor with `argmax()` and `dim=` works HOT 1
- error: call to non-‘constexpr’ function
- using pykan i met this error. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch.