swift-apis icon indicating copy to clipboard operation
swift-apis copied to clipboard

SIGABRT on matmul()

Open ematejska opened this issue 5 years ago • 6 comments

libc++abi.dylib: terminating with uncaught exception of type Xbyak::Error: can't protect

I got this error on matmul using example from git repo readme with additional row in input data

struct MLPClassifier {
    var w1 = Tensor<Float>(repeating: 0.1, shape: [2, 4])
    var w2 = Tensor<Float>(shape: [4, 1], scalars: [0.4, -0.5, -0.5, 0.4])
    var b1 = Tensor<Float>([0.2, -0.3, -0.3, 0.2])
    var b2 = Tensor<Float>([[0.4]])


    func prediction(for x: Tensor<Float>) -> Tensor<Float> {
        let o1 = tanh(matmul(x, w1) + b1)
        return tanh(matmul(o1, w2) + b2)
    }
}
let input = Tensor<Float>([[0.2, 0.8], [0.2, 0.8]])
print(input.shape)
let classifier = MLPClassifier()
let prediction = classifier.prediction(for: input)
print(prediction)

ematejska avatar Apr 24 '20 21:04 ematejska

This issue was submitted in JIRA by Artiom Bastun here: https://bugs.swift.org/projects/TF/issues/TF-1230. Moving from JIRA to Github Issues as much as possible for the project.

ematejska avatar Apr 24 '20 21:04 ematejska

Followup comment from Artiom Bastun:

I managed to get around this with

let locale = Python.import("locale")
locale.setlocale(locale.LC_ALL, "")

I guess it's the same issue like this one https://github.com/Microsoft/homebrew-mssql-release/issues/18

ematejska avatar Apr 24 '20 21:04 ematejska

I get the same error even with applying the said work-around. Problem persist on both release and developer versions of S4TF

let a: Tensor<Float> = [[0.0, 1.0, 0.0],
 [0.0, 1.0, 1.0],
 [1.0, 1.0, 1.0]]
 
 let b: Tensor<Float> = [[-0.074010275, -0.074010275, 0.14814812],
 [ 0.12646824, 0.12646824, 0.12646824],
 [ -0.05096831, 0.14284894, 0.14284894]]
 
 print(matmul(a, b))

ByCyril avatar Apr 28 '20 16:04 ByCyril

After continued tinkering, it seems that there is issues when predefining a tensor with its shape.

If I create the same tensor and specifying the shape

let a = Tensor(shape: [3,3], scalars: [0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0])
let b = Tensor(shape: [3,3], scalars: [-0.0740, -0.0740,   0.148, 0.126,   0.126,   0.126, -0.050,
print(matmul(a, b))

the code works.

I'm not sure if this is a bug with tensorflow or its just how it works.

ByCyril avatar Apr 28 '20 17:04 ByCyril

I get the same error even with applying the said work-around. Problem persist on both release and developer versions of S4TF

let a: Tensor<Float> = [[0.0, 1.0, 0.0],
 [0.0, 1.0, 1.0],
 [1.0, 1.0, 1.0]]
 
 let b: Tensor<Float> = [[-0.074010275, -0.074010275, 0.14814812],
 [ 0.12646824, 0.12646824, 0.12646824],
 [ -0.05096831, 0.14284894, 0.14284894]]
 
 print(matmul(a, b))

Could you please share details on how you reproduced an error for this program? I couldn't reproduce it in Colab, or locally on macOS.

Screen Shot 2020-04-28 at 10 48 17 AM

dan-zheng avatar Apr 28 '20 17:04 dan-zheng

I dunno where the problem is but it happens with matmul for two matrices, it works when multiplying vector and matrix. Screenshot 2020-04-28 at 21 19 12

Also there isn't error when using Python 2.7: PythonLibrary.useVersion(2, 7) or setting locale for Python 3.7 locale.setlocale(locale.LC_ALL, "")

I'm using latest swift tensorflow toolchain on mac os 10.15.4, xcode 11.4.1

Stunba avatar Apr 28 '20 18:04 Stunba