Skip to content

Conversation

@shvul
Copy link
Contributor

@shvul shvul commented Mar 7, 2023

Different values might be stored in different place within swift protobuf for onnx models

Different values might be stored in different place within swift protobuf for onnx models
guard !tensor.int64Data.isEmpty else {
throw OnnxError.unsupportedTensorDataType(onnx: tensor.dataType, mps: nil)
}
return constant(tensor.int64Data.rawData, shape: tensor.mpsShape, dataType: targetDataType)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

с точки зрения имплементации - это ошибка, потому что все тензоры должны быть либо float32, либо float16 для того чтобы в рантайме не нужно было делать лишние касты. поэтому я предлагаю либо кастить сначала int64/int32/uint/etc. в float16/float32 тут, либо ожидать что в сетке будет только rawData (это можно сделать в питон скрипте ONNX2MPSX). Если же кастить все во float32/float16, то это надо делать не здесь а внутри методов halfs/floats в экстеншене.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай тогда притормозим это немного, надо потестить хорошо будет конвертации. В ту же Where ноду надо bool тензор с другой стороны, он все равно, наверное, внутри кастится в float для в step функции, но все же. Надо мерять

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ок)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

заменить на флоты все нельзя

(mpsFileLoc): /Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Core/Files/MPSGraphUtilities.mm:132:0: error: 'mps.gather' op operand #1 must be tensor of int values, but got 'tensor<1xf32>'

}
case (.float16, _):
guard let values = tensor.halfs else {
guard let values = tensor.halfs, values.rawData.count != 0 else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, кажется что isEmpty проверка более православная чтоли

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я католик, мне можно так 😁

_dataType.flatMap(rawData.floats16(assumingDataType:))
}

var ints: [Int]? {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю выше в методах halfs/floats добавить конвертацию из int64Data/int32Data/uint64Data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants