Swift: error: internal error generating TensorFlow graph: GraphGen cannot lower a 'send' to the host yet

Created on 28 Apr 2018  Â·  5Comments  Â·  Source: tensorflow/swift

Using the code below (examples from swift-TF):

import Foundation

import TensorFlow

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

    func prediction(for x: Tensor<Float>) -> Tensor<Float> {
        // The ⊗ operator performs matrix multiplication.
        let o1 = tanh(x ⊗ w1 + b1)
        return tanh(o1 ⊗ w2 + b2)
    }

    func multiply(_ x: Tensor<Float>) -> Tensor<Float> {
      return x ⊗ w1 + b1
    }
}

let input = Tensor<Float>([[0.2, 0.8]])
let classifier = MLPClassifier()
print(classifier.prediction(for: input))
print(classifier.prediction(for: input)) //Added here on purpose.

if the line 'print(classifier.prediction(for: input))' is duplicated, the compilation fails with " error: internal error generating TensorFlow graph: GraphGen cannot lower a 'send' to the host yet"

Q: What does mean this error message, and how to work around it?

thanks

Most helpful comment

This is a current limitation due to the lack of send/receive support. If you make a temporary variable and print that variable multiple times, this error won’t occur.

Swift’s Graph Program Extraction algorithm assumes there are two sides of the world running a program: the host and the accelerator. When Swift is compiling your code, it determines that the first print statement is going to require the result from the tensor computIon to be copied back to host, and that it is not the last tensor computation in this region (the last being the prediction call in the second print), so it creates a “tensorflowSend” node in the compiler-generated TensorFlow graph.

Send/receive is a fundamental feature we will support, and the core team is implementing it. After it is implemented, users won’t encounter this problem!

All 5 comments

// OK
var x = Tensor([[1, 2], [3, 4]])
_ = x[0]
print(x)
// Error:  Internal error generating TensorFlow graph:
// GraphGen cannot lower a 'send' to the host yet
var x = Tensor([[1, 2], [3, 4]])
print(x)
_ = x[0]

This is a current limitation due to the lack of send/receive support. If you make a temporary variable and print that variable multiple times, this error won’t occur.

Swift’s Graph Program Extraction algorithm assumes there are two sides of the world running a program: the host and the accelerator. When Swift is compiling your code, it determines that the first print statement is going to require the result from the tensor computIon to be copied back to host, and that it is not the last tensor computation in this region (the last being the prediction call in the second print), so it creates a “tensorflowSend” node in the compiler-generated TensorFlow graph.

Send/receive is a fundamental feature we will support, and the core team is implementing it. After it is implemented, users won’t encounter this problem!

Ok, thanks for this detailed explanation.

Just a quick note: I suspect i’m Not going to be the last one reporting this issue, so it might be interesting to add this limitation in the readme file of the project.

Cheers

@Mamonaku
I've created an FAQ and explained this issue in more depth. Thanks for reporting it!

Was this page helpful?
0 / 5 - 0 ratings