This repository was archived by the owner on Jul 1, 2023. It is now read-only.
This repository was archived by the owner on Jul 1, 2023. It is now read-only.
code crashes on macos but not linux #832
Open
Description
This code crashes when run with the "Xcode 11 (April 15, 2020)" toolchain, but does not crash when run with a nightly toolchain on Linux.
import Foundation
import TensorFlow
typealias Tensorf = Tensor<Float>
let input = Tensorf(randomNormal: [1, 256, 256, 12])
let semanticMap = Tensorf(ones: [1, 256, 256, 1])
struct CLADE: Layer {
struct Input: Differentiable {
var input: Tensorf
@noDerivative var semanticMap: Tensorf
}
var table: Tensorf
init(table: Tensorf) {
self.table = table
}
@differentiable
func callAsFunction(_ input: Input) -> Tensorf {
let smap = withoutDerivative(at: input.semanticMap.scalars) {
$0.map { Int($0) }
}
var scalars: [Tensorf] = []
for element in smap {
scalars.append(self.table[element])
}
let gammaTensor = Tensorf(stacking: scalars).reshaped(to: input.semanticMap.shape)
return input.input * gammaTensor
}
}
var clade = CLADE(table: .init([0.6, 0.8]))
var optimizer = Adam(for: clade)
while true {
let cladeGrad = gradient(at: clade) { c -> Tensorf in
let output = c(.init(input: input, semanticMap: semanticMap))
return output.sum()
}
optimizer.update(&clade, along: cladeGrad)
print(clade.table)
}
Metadata
Metadata
Assignees
Labels
No labels