Skip to content

[AutoDiff] make diff_wit_fns instead of fn_refs #28451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 29, 2019

Conversation

marcrasi
Copy link

@marcrasi marcrasi commented Nov 23, 2019

Main change

The main point of this PR is to make the differentiation pass look up witnesses and make differentiable_witness_function instructions, instead of looking up attributes and making function_refs.

Related changes

Some fixes were required to make this work properly:

  • LinkEntity::SecondaryPointer needed to be set to nullptr. Otherwise it gets garbage that messes up equality comparisons.
  • Added some logic to LoadableByAddress to handle differentiable_witness_function.
  • Do not canonicalize the generic signature in the differentiability witnesses. This makes the "tau" stuff appear in the diagnostics, breaking some tests. Canonicalization is not necessary because all users that require canonicalization canonicalize it again anyways.
  • Adjusted some tests.
  • Some interesting stuff happened in differentiable_sil_attr_roundtrip.swift, see the comment.

I used this PR as an opportunity to move all "derivative lookup" logic into its own file. I think this makes it easier to read and also it'll make incremental compilation faster.

What I'm doing next

I'm going to run toolchain build and swift-apis tests on this because it's a big change.

I'll be online from ~9pm to ~10pm tonight to fix any CI failures or address any comments. After that, I'll be out until Monday, so feel free to do whatever you want with this if you want to extend it over the weekend.

Next steps

This does not yet eliminate SILDifferentiableAttr, which is still used for at least:

  • Initial triggering of differentiation.
  • Canonicalization fills in a SILDifferentiableAttr, and then the jvp/vjp from that gets copied to the witness.

I think it'll be quite easy for a follow-up PR to remove these things and delete SILDifferentiableAttr, and that's what I think the next PR should do.

After that, all the typechecking and SILGen simplifications that we want should be unblocked. And then after that we should be able to implement cross-file and cross-module retrodiff and start using it in the stdlib.

I plan not to work on any of this until Monday, so feel free to start doing stuff on it if you want.

@marcrasi marcrasi requested review from rxwei and dan-zheng November 23, 2019 01:38
@marcrasi marcrasi force-pushed the marcrasi-use-diff-witness branch from 38824cf to 4036d53 Compare November 23, 2019 01:39
@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow linux

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

I'm super excited to see this working!

Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

This is huge, LGTM!

const auto *minimalAttr = getMinimalASTDifferentiableAttr(
originalAFD, parameterIndices, minimalParameterIndices);

// TODO(TF-835): This will also need to search all `@differentiating`
Copy link
Contributor

Choose a reason for hiding this comment

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

Great future facing note!

@marcrasi
Copy link
Author

I figured out why the tests are failing. I pushed a fix that makes it slightly better but does not fix it. I have to sign off now, feel free to do more stuff to this.

The reason the tests are failing is that inlinable functions with differentiability_witness_function instructions are getting inlined into the module, but the corresponding witness tables are not getting inlined into the module. So deserialization tries to look up the witness table, does not find it, and dies.

@marcrasi
Copy link
Author

I had a bit of time to investigate the failure today, so I added a simple testcase that triggers it that should make it pretty clear what's happening. In the testcase, the test_serialized function gets serialized into the module, so there's a reference to the differentiability witness, so the differentiability witness needs to get serialized into the module. Otherwise, deserialization fails because it doesn't see the witness.

Okay, that's all I'll be doing for now.

@dan-zheng
Copy link
Contributor

dan-zheng commented Nov 24, 2019

In the testcase, the test_serialized function gets serialized into the module, so there's a reference to the differentiability witness, so the differentiability witness needs to get serialized into the module. Otherwise, deserialization fails because it doesn't see the witness.

Thanks for the clear explanation! I think I understand the SIL serialization issues and I'll investigate now.

Edit: I merged the fix #28463 to tensorflow.

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor

Concern

This makes litrun test/AutoDiff -sv 2x slower for me (10s -> 20s). I haven't done any investigation of this. It should probably be investigated eventually.

Shall we investigate the (compile-time and/or runtime) performance regressions before merging this PR? I suspect generating differentiability_witness_function instructions instead of JVP/VJP function_refs may impact runtime performance - TF-994 tracks devirtualization.

@marcrasi
Copy link
Author

I'll spend a bit of time measuring the compile time and runtime performance impact of this. I'll report back on the PR before merging and we can decide whether to go ahead.

@marcrasi
Copy link
Author

marcrasi commented Nov 25, 2019

Runtime performance

Microbenchmark

func descendQuadratic(
  a: Float, b: Float, x0: Float, rate: Float, count: Int
) -> Float {
  var x = x0
  for _ in 0..<count {
    let g = gradient(at: x) { x in
      x * x + a * x + b
    }
    x -= rate * g
  }
  return x
}

let x1 = descendQuadratic(
  a: 0, b: 0, x0: 10, rate: 0.001, count: 10_000_000)
print(x1)

When compiled with swiftc -O, the runtime goes from 4.9s (before this PR) to 5.7s (after this PR) on my workstation.

swift-models Benchmark

No noticeable difference when running this benchmark.

Internal Google model

An internal Google model is affected, with about the same amount of performance regression as the microbenchmark.

Decision

I will implement devirtualization before merging this patch because we don't want to check in such a big performance regression without being sure that we have a solution.

@marcrasi
Copy link
Author

A swift-apis failure also remains after the latest fixes, so I will investigate that too:

Step 17/34 : RUN /swift-tensorflow-toolchain/usr/bin/swift test
 ---> Running in a31cd76d5d87
[1/13] Compiling Tensor Random.swift
[3/14] Merging module Experimental
[4/16] Wrapping AST for Experimental for debugging
[5/16] Compiling ExperimentalTests XCTestManifests.swift
[6/17] Merging module Tensor
[7/21] Wrapping AST for Tensor for debugging
[8/35] Linking libTensor.so
[9/71] Compiling TensorFlow Exports.swift
[10/71] Compiling TensorFlow Freezable.swift
[11/71] Compiling TensorFlow Optimizer.swift
[12/71] Compiling TensorFlow Threading.swift
[13/71] Compiling TensorFlow Utilities.swift
[14/71] Compiling TensorFlow Execution.swift
[15/71] Compiling TensorFlow LazyTensorContext.swift
[16/71] Compiling TensorFlow Context.swift
[17/71] Compiling TensorFlow ArrayOps.swift
[18/71] Compiling TensorFlow SGD.swift
[19/71] Compiling TensorFlow Runtime.swift
[20/71] Compiling TensorFlow Serialization.swift
[21/71] Compiling TensorFlow Comparison.swift
[22/71] Compiling TensorFlow StdlibExtensions.swift
[23/71] Compiling TensorFlow EagerExecution.swift
[24/71] Compiling TensorFlow TensorHandle.swift
[25/71] Compiling TensorFlow TensorShape.swift
[26/71] Compiling TensorFlow RawOpsGenerated.swift
[27/71] Compiling TensorFlow LazyTensorTFFunctionBuilder.swift
[28/71] Compiling TensorFlow LazyTensorTrace.swift
[30/71] Compiling TensorFlow LazyTensorTraceCache.swift
[31/71] Compiling TensorFlow PythonConversion.swift
[32/71] Compiling TensorFlow Dataset.swift
[33/71] Compiling TensorFlow BackwardsCompatibility.swift
[34/72] Merging module TensorTests
[35/72] Wrapping AST for TensorTests for debugging
[36/72] Compiling TensorFlow DataTypes.swift
[37/72] Compiling TensorFlow DifferentialOperators.swift
[38/72] Compiling TensorFlow LazyTensorOperation.swift
[39/72] Compiling TensorFlow LazyTensorShapeInference.swift
[40/72] Compiling TensorFlow ShapedArray.swift
[41/72] Compiling TensorFlow StringTensor.swift
[43/73] Merging module ExperimentalTests
[44/73] Wrapping AST for ExperimentalTests for debugging
[45/73] Compiling TensorFlow Sequential.swift
[46/73] Compiling TensorFlow Embedding.swift
[47/73] Compiling TensorFlow Initialization.swift
[48/73] Compiling TensorFlow Tensor.swift
[49/73] Compiling TensorFlow TensorGroup.swift
[52/73] Compiling TensorFlow Initializers.swift
[53/73] Compiling TensorFlow Layer.swift
[54/73] Compiling TensorFlow MomentumBased.swift
[55/73] Compiling TensorFlow NN.swift
[56/73] Compiling TensorFlow Upsampling.swift
[57/73] Compiling TensorFlow Dense.swift
[58/73] Compiling TensorFlow Dropout.swift
[60/73] Compiling TensorFlow TFTensorOperation.swift
[61/73] Compiling TensorFlow Recurrent.swift
[62/73] Compiling TensorFlow Basic.swift
[63/73] Compiling TensorFlow Loss.swift
[64/73] Compiling TensorFlow Normalization.swift
[65/73] Compiling TensorFlow Pooling.swift
[66/73] Compiling TensorFlow Convolutional.swift
[67/73] Compiling TensorFlow Core.swift
[68/73] Compiling TensorFlow Math.swift
swift: /swift-base/swift/lib/SIL/SILDifferentiabilityWitness.cpp:36: static swift::SILDifferentiabilityWitness *swift::SILDifferentiabilityWitness::createDeclaration(swift::SILModule &, swift::SILLinkage, swift::SILFunction *, swift::IndexSubset *, swift::IndexSubset *, swift::GenericSignature, swift::DeclAttribute *): Assertion `!module.DifferentiabilityWitnessMap.count(mangledKey) && "Cannot create duplicate differentiability witness in a module"' failed.
Stack dump:
0.	Program arguments: /swift-tensorflow-toolchain/usr/bin/swift -frontend -merge-modules -emit-module /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/BackwardsCompatibility~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Bindings/EagerExecution~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Bindings/RawOpsGenerated~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Bindings/TFTensorOperation~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Context~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/ArrayOps~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/DataTypes~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/DifferentialOperators~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Execution~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorContext~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorOperation~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorShapeInference~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorTFFunctionBuilder~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorTrace~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/LazyTensorTraceCache~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/PythonConversion~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Runtime~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Serialization~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/ShapedArray~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/StringTensor~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Tensor~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/TensorGroup~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/TensorHandle~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/TensorShape~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Threading~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Core/Utilities~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Exports~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Freezable~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Initializers~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layer~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Convolutional~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Core~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Dense~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Dropout~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Embedding~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Initialization~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Normalization~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Pooling~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Recurrent~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Sequential~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Layers/Upsampling~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Loss~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Operators/Basic~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Operators/Comparison~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Operators/Dataset~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Operators/Math~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Operators/NN~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Optimizers/MomentumBased~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Optimizers/Optimizer~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Optimizers/SGD~partial.swiftmodule /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/StdlibExtensions~partial.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-unknown-linux-gnu -disable-objc-interop -I /swift-apis/.build/x86_64-unknown-linux-gnu/debug -enable-testing -g -module-cache-path /swift-apis/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 4.2 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -emit-module-doc-path /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.swiftdoc -emit-module-source-info-path /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.swiftsourceinfo -module-name TensorFlow -o /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.swiftmodule
1.	Swift version 5.1.1-dev (Swift 655b1919ac)
/swift-tensorflow-toolchain/usr/bin/swift[0x4bf7844]
/swift-tensorflow-toolchain/usr/bin/swift[0x4bf545e]
/swift-tensorflow-toolchain/usr/bin/swift[0x4bf7af8]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f84a613e890]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f84a45a1e97]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f84a45a3801]
/lib/x86_64-linux-gnu/libc.so.6(+0x3039a)[0x7f84a459339a]
/lib/x86_64-linux-gnu/libc.so.6(+0x30412)[0x7f84a4593412]
/swift-tensorflow-toolchain/usr/bin/swift[0xe91012]
/swift-tensorflow-toolchain/usr/bin/swift[0x12b8e0b]
/swift-tensorflow-toolchain/usr/bin/swift[0x12d29d3]
/swift-tensorflow-toolchain/usr/bin/swift[0x125e36f]
/swift-tensorflow-toolchain/usr/bin/swift[0x125e3d3]
/swift-tensorflow-toolchain/usr/bin/swift[0x759965]
/swift-tensorflow-toolchain/usr/bin/swift[0x4e094e]
/swift-tensorflow-toolchain/usr/bin/swift[0x4d6be7]
/swift-tensorflow-toolchain/usr/bin/swift[0x4d3c6d]
/swift-tensorflow-toolchain/usr/bin/swift[0x474290]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f84a4584b97]
/swift-tensorflow-toolchain/usr/bin/swift[0x473eda]
The command '/bin/sh -c /swift-tensorflow-toolchain/usr/bin/swift test' returned a non-zero code: 1

@marcrasi
Copy link
Author

@swift-ci please test tensorflow

1 similar comment
@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

@swift-ci please test tensorflow

2 similar comments
@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

@swift-ci please test tensorflow macos

@marcrasi
Copy link
Author

marcrasi commented Nov 26, 2019

Updates!

tldr: Only one remaining blocker, a swift-apis compile failure, which I am investigating now.

Runtime performance

#28480 has fully fixed the performance regression in the microbenchmark posted above and in the internal google model.

Compiletime performance

There's a bit of slowdown as measured by running the AD compiler test suite. None of it seems egregious, so I will defer investigation. Filed TF-1013 for future investigation. You can see the measurements at https://gist.github.com/marcrasi/456d09d15a14f9af092db2e7b24186bb.

swift-apis compile failure

Step 17/34 : RUN /swift-tensorflow-toolchain/usr/bin/swift test
 ---> Running in 1cd353790e84
[1/13] Compiling Tensor Random.swift
[3/14] Merging module Experimental
[4/16] Wrapping AST for Experimental for debugging
[5/16] Compiling ExperimentalTests XCTestManifests.swift
[6/17] Merging module Tensor
[7/21] Wrapping AST for Tensor for debugging
[8/37] Linking libTensor.so
[9/71] Compiling TensorFlow Exports.swift
[10/71] Compiling TensorFlow Freezable.swift
[11/71] Compiling TensorFlow Optimizer.swift
[12/71] Compiling TensorFlow Execution.swift
[13/71] Compiling TensorFlow LazyTensorContext.swift
[14/71] Compiling TensorFlow Threading.swift
[15/71] Compiling TensorFlow Utilities.swift
[16/71] Compiling TensorFlow Context.swift
[17/71] Compiling TensorFlow ArrayOps.swift
[18/71] Compiling TensorFlow StdlibExtensions.swift
[19/71] Compiling TensorFlow SGD.swift
[20/71] Compiling TensorFlow Runtime.swift
[21/71] Compiling TensorFlow Serialization.swift
[22/71] Compiling TensorFlow EagerExecution.swift
[23/71] Compiling TensorFlow RawOpsGenerated.swift
[24/71] Compiling TensorFlow TensorHandle.swift
[25/71] Compiling TensorFlow TensorShape.swift
[26/71] Compiling TensorFlow Comparison.swift
[27/71] Compiling TensorFlow LazyTensorTFFunctionBuilder.swift
[28/71] Compiling TensorFlow LazyTensorTrace.swift
[29/71] Compiling TensorFlow LazyTensorTraceCache.swift
[30/71] Compiling TensorFlow PythonConversion.swift
[32/71] Compiling TensorFlow Dataset.swift
[33/71] Compiling TensorFlow BackwardsCompatibility.swift
[34/72] Compiling TensorFlow DataTypes.swift
[35/72] Compiling TensorFlow DifferentialOperators.swift
[36/72] Merging module TensorTests
[37/72] Wrapping AST for TensorTests for debugging
[39/73] Merging module ExperimentalTests
[40/73] Wrapping AST for ExperimentalTests for debugging
[41/73] Compiling TensorFlow ShapedArray.swift
[42/73] Compiling TensorFlow StringTensor.swift
[43/73] Compiling TensorFlow LazyTensorOperation.swift
[44/73] Compiling TensorFlow LazyTensorShapeInference.swift
[45/73] Compiling TensorFlow Sequential.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[46/73] Compiling TensorFlow Embedding.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[47/73] Compiling TensorFlow Initialization.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[48/73] Compiling TensorFlow Tensor.swift
[49/73] Compiling TensorFlow TensorGroup.swift
[52/73] Compiling TensorFlow Initializers.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[53/73] Compiling TensorFlow Layer.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[54/73] Compiling TensorFlow MomentumBased.swift
[55/73] Compiling TensorFlow NN.swift
[56/73] Compiling TensorFlow Upsampling.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[57/73] Compiling TensorFlow Dense.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[58/73] Compiling TensorFlow Dropout.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[60/73] Compiling TensorFlow TFTensorOperation.swift
[61/73] Compiling TensorFlow Recurrent.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[62/73] Compiling TensorFlow Basic.swift
[63/73] Compiling TensorFlow Loss.swift
[64/73] Compiling TensorFlow Normalization.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[65/73] Compiling TensorFlow Pooling.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[66/73] Compiling TensorFlow Convolutional.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[67/73] Compiling TensorFlow Core.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[68/73] Compiling TensorFlow Math.swift
[69/74] Merging module TensorFlow
[70/81] Wrapping AST for TensorFlow for debugging
[71/100] Compiling TensorFlowTests LazyTensorTestHelper.swift
[72/100] Compiling TensorFlowTests RuntimeTests.swift
[73/100] Linking libTensorFlow.so
[74/100] Compiling TensorFlowTests ContextTests.swift
[75/100] Compiling TensorFlowTests Helpers.swift
[76/100] Compiling TensorFlowTests ComparisonTests.swift
[77/100] Compiling TensorFlowTests LazyTensorOperationTests.swift
[78/100] Compiling TensorFlowTests LazyTensorHandleTests.swift
[79/100] Compiling TensorFlowTests LazyTensorTraceCacheTests.swift
[80/100] Compiling TensorFlowTests LazyTensorTFFunctionBuilderTests.swift
[81/100] Compiling TensorFlowTests TensorTests.swift
[82/100] Compiling TensorFlowTests LazyTensorEvaluationTests.swift
[83/100] Compiling TensorFlowTests LazyTensorShapeInferenceTests.swift
[84/100] Compiling TensorFlowTests TensorGroupTests.swift
[85/100] Compiling TensorFlowTests LazyTensorExplicitTraceTests.swift
[86/100] Compiling TensorFlowTests LazyTensorTraceTests.swift
[87/100] Compiling TensorFlowTests XCTestManifests.swift
[88/100] Compiling TensorFlowTests InitializerTests.swift
[89/100] Compiling TensorFlowTests TrivialModelTests.swift
[90/100] Compiling TensorFlowTests DatasetTests.swift
[91/100] Compiling TensorFlowTests SequentialTests.swift
[92/100] Compiling TensorFlowTests FreezableTests.swift
[93/100] Compiling TensorFlowTests LossTests.swift
[94/100] Compiling TensorFlowTests MathTests.swift
[95/100] Compiling TensorFlowTests BasicTests.swift
[96/100] Compiling TensorFlowTests LayerTests.swift
[97/100] Compiling TensorFlowTests TensorAutoDiffTests.swift
[98/101] Merging module TensorFlowTests
[99/102] Wrapping AST for TensorFlowTests for debugging
[100/102] Compiling TensorFlowPackageTests LinuxMain.swift
[101/103] Merging module TensorFlowPackageTests
[102/103] Wrapping AST for TensorFlowPackageTests for debugging
/usr/bin/ld.gold: error: /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlowTests.build/LossTests.swift.o: multiple definition of 'AD__$s10TensorFlow9huberLoss9predicted8expected5delta9reductionAA0A0VyxGAI_AIxA2IXFtAA0aB13FloatingPointRzlFfA2_A2IcfU__PSRS10TensorFlow0aB13FloatingPointRzl'
/usr/bin/ld.gold: /swift-apis/.build/x86_64-unknown-linux-gnu/debug/TensorFlow.build/Loss.swift.o: previous definition here
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
[102/103] Linking TensorFlowPackageTests.xctest
The command '/bin/sh -c /swift-tensorflow-toolchain/usr/bin/swift test' returned a non-zero code: 1

@marcrasi
Copy link
Author

Okay, I have uploaded a fix that seems to work. I think it's not very proper, but if all the tests pass then it's probably good enough for now.

Gonna retrigger the swift-apis tests.

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Nov 27, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Nov 27, 2019

@swift-ci please test tensorflow macos

1 similar comment
@marcrasi
Copy link
Author

@swift-ci please test tensorflow macos

@marcrasi
Copy link
Author

swift-apis tests have gotten farther, but are still failing. The failure is currently a bit mysterious to me. Compilation succeeds, a lot of tests succeed, and then suddenly it says "Exited with signal code 11," with no other explanatory message. Investigating now.

Full test output:

Step 17/34 : RUN /swift-tensorflow-toolchain/usr/bin/swift test
 ---> Running in f9f367c76ab2
[1/13] Compiling Experimental Complex.swift
[3/14] Merging module Experimental
[4/16] Wrapping AST for Experimental for debugging
[5/16] Compiling ExperimentalTests XCTestManifests.swift
[6/17] Merging module Tensor
[7/21] Wrapping AST for Tensor for debugging
[8/35] Linking libTensor.so
[9/71] Compiling TensorFlow Exports.swift
[10/71] Compiling TensorFlow Freezable.swift
[11/71] Compiling TensorFlow Optimizer.swift
[12/71] Compiling TensorFlow Execution.swift
[13/71] Compiling TensorFlow LazyTensorContext.swift
[14/71] Compiling TensorFlow Threading.swift
[15/71] Compiling TensorFlow Utilities.swift
[16/71] Compiling TensorFlow Context.swift
[17/71] Compiling TensorFlow ArrayOps.swift
[18/71] Compiling TensorFlow Runtime.swift
[19/71] Compiling TensorFlow Serialization.swift
[20/71] Compiling TensorFlow StdlibExtensions.swift
[21/71] Compiling TensorFlow EagerExecution.swift
[22/71] Compiling TensorFlow RawOpsGenerated.swift
[23/71] Compiling TensorFlow SGD.swift
[24/71] Compiling TensorFlow Comparison.swift
[25/71] Compiling TensorFlow TensorHandle.swift
[26/71] Compiling TensorFlow TensorShape.swift
[27/71] Compiling TensorFlow LazyTensorTFFunctionBuilder.swift
[28/71] Compiling TensorFlow LazyTensorTrace.swift
[30/71] Compiling TensorFlow LazyTensorTraceCache.swift
[31/71] Compiling TensorFlow PythonConversion.swift
[32/71] Compiling TensorFlow BackwardsCompatibility.swift
[33/72] Merging module TensorTests
[34/72] Wrapping AST for TensorTests for debugging
[35/72] Compiling TensorFlow DataTypes.swift
[36/72] Compiling TensorFlow DifferentialOperators.swift
[37/72] Compiling TensorFlow Dataset.swift
[39/73] Merging module ExperimentalTests
[40/73] Wrapping AST for ExperimentalTests for debugging
[41/73] Compiling TensorFlow LazyTensorOperation.swift
[42/73] Compiling TensorFlow LazyTensorShapeInference.swift
[43/73] Compiling TensorFlow ShapedArray.swift
[44/73] Compiling TensorFlow StringTensor.swift
[45/73] Compiling TensorFlow Sequential.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[46/73] Compiling TensorFlow Embedding.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[47/73] Compiling TensorFlow Initialization.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[48/73] Compiling TensorFlow Tensor.swift
[49/73] Compiling TensorFlow TensorGroup.swift
[52/73] Compiling TensorFlow Initializers.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[53/73] Compiling TensorFlow Layer.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[54/73] Compiling TensorFlow MomentumBased.swift
[55/73] Compiling TensorFlow NN.swift
[56/73] Compiling TensorFlow Upsampling.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[57/73] Compiling TensorFlow Dense.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[58/73] Compiling TensorFlow Dropout.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[60/73] Compiling TensorFlow TFTensorOperation.swift
[61/73] Compiling TensorFlow Recurrent.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[62/73] Compiling TensorFlow Basic.swift
[63/73] Compiling TensorFlow Loss.swift
[64/73] Compiling TensorFlow Normalization.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[65/73] Compiling TensorFlow Pooling.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[66/73] Compiling TensorFlow Convolutional.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[67/73] Compiling TensorFlow Core.swift
/swift-apis/Sources/TensorFlow/Layer.swift:94:6: warning: '@differentiating' attribute is deprecated; use '@derivative(of:)' instead
    @differentiating(inferring(from:))
     ^
[68/73] Compiling TensorFlow Math.swift
[69/74] Merging module TensorFlow
[70/81] Wrapping AST for TensorFlow for debugging
[71/100] Compiling TensorFlowTests LazyTensorTestHelper.swift
[72/100] Compiling TensorFlowTests RuntimeTests.swift
[73/100] Compiling TensorFlowTests Helpers.swift
[74/100] Linking libTensorFlow.so
[75/100] Compiling TensorFlowTests ComparisonTests.swift
[76/100] Compiling TensorFlowTests LazyTensorOperationTests.swift
[77/100] Compiling TensorFlowTests ContextTests.swift
[78/100] Compiling TensorFlowTests LazyTensorTFFunctionBuilderTests.swift
[79/100] Compiling TensorFlowTests LazyTensorHandleTests.swift
[80/100] Compiling TensorFlowTests LazyTensorTraceCacheTests.swift
[81/100] Compiling TensorFlowTests TensorTests.swift
[82/100] Compiling TensorFlowTests LazyTensorEvaluationTests.swift
[83/100] Compiling TensorFlowTests LazyTensorExplicitTraceTests.swift
[84/100] Compiling TensorFlowTests LazyTensorShapeInferenceTests.swift
[85/100] Compiling TensorFlowTests TensorGroupTests.swift
[86/100] Compiling TensorFlowTests XCTestManifests.swift
[87/100] Compiling TensorFlowTests LazyTensorTraceTests.swift
[88/100] Compiling TensorFlowTests SequentialTests.swift
[89/100] Compiling TensorFlowTests DatasetTests.swift
[90/100] Compiling TensorFlowTests TrivialModelTests.swift
[91/100] Compiling TensorFlowTests InitializerTests.swift
[92/100] Compiling TensorFlowTests LossTests.swift
[93/100] Compiling TensorFlowTests FreezableTests.swift
[94/100] Compiling TensorFlowTests MathTests.swift
[95/100] Compiling TensorFlowTests BasicTests.swift
[96/100] Compiling TensorFlowTests LayerTests.swift
[97/100] Compiling TensorFlowTests TensorAutoDiffTests.swift
[98/101] Merging module TensorFlowTests
[99/102] Wrapping AST for TensorFlowTests for debugging
[100/102] Compiling TensorFlowPackageTests LinuxMain.swift
[101/103] Merging module TensorFlowPackageTests
[102/103] Wrapping AST for TensorFlowPackageTests for debugging
[103/103] Linking TensorFlowPackageTests.xctest
Test Suite 'All tests' started at 2019-11-27 06:56:35.939
Test Suite 'debug.xctest' started at 2019-11-27 06:56:35.941
Test Suite 'BasicOperatorTests' started at 2019-11-27 06:56:35.941
Test Case 'BasicOperatorTests.testGathering' started at 2019-11-27 06:56:35.941
Test Case 'BasicOperatorTests.testGathering' passed (0.029 seconds)
Test Case 'BasicOperatorTests.testBatchGathering' started at 2019-11-27 06:56:35.969
Test Case 'BasicOperatorTests.testBatchGathering' passed (0.003 seconds)
Test Case 'BasicOperatorTests.testPadded' started at 2019-11-27 06:56:35.973
Test Case 'BasicOperatorTests.testPadded' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testPaddedConstant' started at 2019-11-27 06:56:35.974
Test Case 'BasicOperatorTests.testPaddedConstant' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testPaddedReflect' started at 2019-11-27 06:56:35.974
Test Case 'BasicOperatorTests.testPaddedReflect' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testPaddedSymmetric' started at 2019-11-27 06:56:35.975
Test Case 'BasicOperatorTests.testPaddedSymmetric' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testVJPPadded' started at 2019-11-27 06:56:35.975
Test Case 'BasicOperatorTests.testVJPPadded' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testVJPPaddedConstant' started at 2019-11-27 06:56:35.977
Test Case 'BasicOperatorTests.testVJPPaddedConstant' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testVJPPaddedReflect' started at 2019-11-27 06:56:35.977
Test Case 'BasicOperatorTests.testVJPPaddedReflect' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testVJPPaddedSymmetric' started at 2019-11-27 06:56:35.978
Test Case 'BasicOperatorTests.testVJPPaddedSymmetric' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testElementIndexing' started at 2019-11-27 06:56:35.979
Test Case 'BasicOperatorTests.testElementIndexing' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testElementIndexingAssignment' started at 2019-11-27 06:56:35.979
Test Case 'BasicOperatorTests.testElementIndexingAssignment' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testNestedElementIndexing' started at 2019-11-27 06:56:35.980
Test Case 'BasicOperatorTests.testNestedElementIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testSliceIndexing' started at 2019-11-27 06:56:35.980
Test Case 'BasicOperatorTests.testSliceIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testSliceIndexingAssignment' started at 2019-11-27 06:56:35.980
Test Case 'BasicOperatorTests.testSliceIndexingAssignment' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testEllipsisIndexing' started at 2019-11-27 06:56:35.981
Test Case 'BasicOperatorTests.testEllipsisIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testNewAxisIndexing' started at 2019-11-27 06:56:35.981
Test Case 'BasicOperatorTests.testNewAxisIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testSqueezeAxisIndexing' started at 2019-11-27 06:56:35.982
Test Case 'BasicOperatorTests.testSqueezeAxisIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testStridedSliceIndexing' started at 2019-11-27 06:56:35.982
Test Case 'BasicOperatorTests.testStridedSliceIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testStridedSliceIndexingAssignment' started at 2019-11-27 06:56:35.982
Test Case 'BasicOperatorTests.testStridedSliceIndexingAssignment' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testWholeTensorSlicing' started at 2019-11-27 06:56:35.983
Test Case 'BasicOperatorTests.testWholeTensorSlicing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testAdvancedIndexing' started at 2019-11-27 06:56:35.983
Test Case 'BasicOperatorTests.testAdvancedIndexing' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testConcatenation' started at 2019-11-27 06:56:35.984
Test Case 'BasicOperatorTests.testConcatenation' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testVJPConcatenation' started at 2019-11-27 06:56:35.984
Test Case 'BasicOperatorTests.testVJPConcatenation' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testTranspose' started at 2019-11-27 06:56:35.985
Test Case 'BasicOperatorTests.testTranspose' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testReshape' started at 2019-11-27 06:56:35.985
Test Case 'BasicOperatorTests.testReshape' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testFlatten' started at 2019-11-27 06:56:35.985
Test Case 'BasicOperatorTests.testFlatten' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testFlatten0D' started at 2019-11-27 06:56:35.985
Test Case 'BasicOperatorTests.testFlatten0D' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testReshapeToScalar' started at 2019-11-27 06:56:35.985
Test Case 'BasicOperatorTests.testReshapeToScalar' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testReshapeTensor' started at 2019-11-27 06:56:35.986
Test Case 'BasicOperatorTests.testReshapeTensor' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testUnbroadcastRank4ToRank2' started at 2019-11-27 06:56:35.986
Test Case 'BasicOperatorTests.testUnbroadcastRank4ToRank2' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testUnbroadcastRank4ToRank3' started at 2019-11-27 06:56:35.986
Test Case 'BasicOperatorTests.testUnbroadcastRank4ToRank3' passed (0.0 seconds)
Test Case 'BasicOperatorTests.testUnbroadcast3x3To1x3' started at 2019-11-27 06:56:35.986
Test Case 'BasicOperatorTests.testUnbroadcast3x3To1x3' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testSliceUpdate' started at 2019-11-27 06:56:35.987
Test Case 'BasicOperatorTests.testSliceUpdate' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testBroadcast3x0To3x3' started at 2019-11-27 06:56:35.988
Test Case 'BasicOperatorTests.testBroadcast3x0To3x3' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testBroadcast3x1To3x3' started at 2019-11-27 06:56:35.989
Test Case 'BasicOperatorTests.testBroadcast3x1To3x3' passed (0.001 seconds)
Test Case 'BasicOperatorTests.testBroadcastTensor' started at 2019-11-27 06:56:35.991
Test Case 'BasicOperatorTests.testBroadcastTensor' passed (0.0 seconds)
Test Suite 'BasicOperatorTests' passed at 2019-11-27 06:56:35.991
	 Executed 37 tests, with 0 failures (0 unexpected) in 0.049 (0.049) seconds
Test Suite 'ComparisonOperatorTests' started at 2019-11-27 06:56:35.991
Test Case 'ComparisonOperatorTests.testElementwiseComparison' started at 2019-11-27 06:56:35.991
Test Case 'ComparisonOperatorTests.testElementwiseComparison' passed (0.0 seconds)
Test Case 'ComparisonOperatorTests.testLexicographicalComparison' started at 2019-11-27 06:56:35.991
Test Case 'ComparisonOperatorTests.testLexicographicalComparison' passed (0.0 seconds)
Test Case 'ComparisonOperatorTests.testIsAlmostEqual' started at 2019-11-27 06:56:35.991
Test Case 'ComparisonOperatorTests.testIsAlmostEqual' passed (0.0 seconds)
Test Suite 'ComparisonOperatorTests' passed at 2019-11-27 06:56:35.992
	 Executed 3 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'ContextTests' started at 2019-11-27 06:56:35.992
Test Case 'ContextTests.testDropout' started at 2019-11-27 06:56:35.992
Test Case 'ContextTests.testDropout' passed (0.001 seconds)
Test Case 'ContextTests.testMultithreadedDropout' started at 2019-11-27 06:56:35.993
Test Case 'ContextTests.testMultithreadedDropout' passed (0.002 seconds)
Test Suite 'ContextTests' passed at 2019-11-27 06:56:35.995
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite 'DatasetTests' started at 2019-11-27 06:56:35.995
Test Case 'DatasetTests.testMultiValue' started at 2019-11-27 06:56:35.995
Test Case 'DatasetTests.testMultiValue' passed (0.002 seconds)
Test Case 'DatasetTests.testSingleValueManualIterator' started at 2019-11-27 06:56:35.997
Test Case 'DatasetTests.testSingleValueManualIterator' passed (0.002 seconds)
Test Case 'DatasetTests.testDatasetIteration' started at 2019-11-27 06:56:35.998
Test Case 'DatasetTests.testDatasetIteration' passed (0.001 seconds)
Test Case 'DatasetTests.testSingleValueTransformations' started at 2019-11-27 06:56:36.000
Test Case 'DatasetTests.testSingleValueTransformations' passed (0.001 seconds)
Test Case 'DatasetTests.testSingleValueHOFs' started at 2019-11-27 06:56:36.001
Test Case 'DatasetTests.testSingleValueHOFs' passed (0.013 seconds)
Test Case 'DatasetTests.testParallelMap' started at 2019-11-27 06:56:36.013
Test Case 'DatasetTests.testParallelMap' passed (0.004 seconds)
Test Case 'DatasetTests.testMapToDifferentType' started at 2019-11-27 06:56:36.018
Test Case 'DatasetTests.testMapToDifferentType' passed (0.004 seconds)
Test Case 'DatasetTests.testSingleValueBatched' started at 2019-11-27 06:56:36.021
Test Case 'DatasetTests.testSingleValueBatched' passed (0.001 seconds)
Test Case 'DatasetTests.testDoubleValueDatasetIteration' started at 2019-11-27 06:56:36.022
Test Case 'DatasetTests.testDoubleValueDatasetIteration' passed (0.002 seconds)
Test Suite 'DatasetTests' passed at 2019-11-27 06:56:36.024
	 Executed 9 tests, with 0 failures (0 unexpected) in 0.029 (0.029) seconds
Test Suite 'InitializerTests' started at 2019-11-27 06:56:36.024
Test Case 'InitializerTests.testInitializers' started at 2019-11-27 06:56:36.024
Test Case 'InitializerTests.testInitializers' passed (0.0 seconds)
Test Case 'InitializerTests.testFactoryInitializers' started at 2019-11-27 06:56:36.024
Test Case 'InitializerTests.testFactoryInitializers' passed (0.0 seconds)
Test Case 'InitializerTests.testNumericInitializers' started at 2019-11-27 06:56:36.024
Test Case 'InitializerTests.testNumericInitializers' passed (0.001 seconds)
Test Case 'InitializerTests.testScalarToTensorConversion' started at 2019-11-27 06:56:36.025
Test Case 'InitializerTests.testScalarToTensorConversion' passed (0.0 seconds)
Test Case 'InitializerTests.testArrayConversion' started at 2019-11-27 06:56:36.025
Test Case 'InitializerTests.testArrayConversion' passed (0.0 seconds)
Test Case 'InitializerTests.testDataTypeCast' started at 2019-11-27 06:56:36.025
Test Case 'InitializerTests.testDataTypeCast' passed (0.0 seconds)
Test Case 'InitializerTests.testBoolToNumericCast' started at 2019-11-27 06:56:36.026
Test Case 'InitializerTests.testBoolToNumericCast' passed (0.0 seconds)
Test Case 'InitializerTests.testRandomUniform' started at 2019-11-27 06:56:36.026
Test Case 'InitializerTests.testRandomUniform' passed (0.001 seconds)
Test Case 'InitializerTests.testRandomNormal' started at 2019-11-27 06:56:36.027
Test Case 'InitializerTests.testRandomNormal' passed (0.004 seconds)
Test Case 'InitializerTests.testRandomTruncatedNormal' started at 2019-11-27 06:56:36.031
Test Case 'InitializerTests.testRandomTruncatedNormal' passed (0.002 seconds)
Test Case 'InitializerTests.testGlorotUniform' started at 2019-11-27 06:56:36.033
Test Case 'InitializerTests.testGlorotUniform' passed (0.002 seconds)
Test Case 'InitializerTests.testGlorotNormal' started at 2019-11-27 06:56:36.036
Test Case 'InitializerTests.testGlorotNormal' passed (0.002 seconds)
Test Case 'InitializerTests.testOrthogonalShapesValues' started at 2019-11-27 06:56:36.037
Test Case 'InitializerTests.testOrthogonalShapesValues' passed (0.009 seconds)
Test Suite 'InitializerTests' passed at 2019-11-27 06:56:36.046
	 Executed 13 tests, with 0 failures (0 unexpected) in 0.022 (0.022) seconds
Test Suite 'LayerTests' started at 2019-11-27 06:56:36.047
Test Case 'LayerTests.testSequential' started at 2019-11-27 06:56:36.047
Test Case 'LayerTests.testSequential' passed (0.018 seconds)
Test Case 'LayerTests.testConv1D' started at 2019-11-27 06:56:36.064
Test Case 'LayerTests.testConv1D' passed (0.001 seconds)
Test Case 'LayerTests.testConv1DDilation' started at 2019-11-27 06:56:36.065
Test Case 'LayerTests.testConv1DDilation' passed (0.0 seconds)
Test Case 'LayerTests.testConv2D' started at 2019-11-27 06:56:36.066
Test Case 'LayerTests.testConv2D' passed (0.0 seconds)
Test Case 'LayerTests.testConv2DGradient' started at 2019-11-27 06:56:36.066
Exited with signal code 11
The command '/bin/sh -c /swift-tensorflow-toolchain/usr/bin/swift test' returned a non-zero code: 1

@marcrasi
Copy link
Author

marcrasi commented Nov 27, 2019

Investigation update for the curious.

This reproduces the segfault:

import TensorFlow

func testConv2DGradient() {
    let filter =  Tensor(shape: [3, 3, 2, 4], scalars: (0..<72).map(Float.init))
    let bias = Tensor<Float>(zeros: [4])
    let layer = Conv2D<Float>(filter: filter,
                              bias: bias,
                              activation: identity,
                              strides: (2, 2),
                              padding: .valid)
    let input = Tensor(shape: [2, 4, 4, 2], scalars: (0..<64).map(Float.init))
    let grads = gradient( at: input, layer) { $1($0).sum() }
}

testConv2DGradient()

The backtrace from lldb is

* thread #1, name = 'retain', stop reason = signal SIGSEGV: invalid address (fault address: 0x29)
  * frame #0: 0x00007ffff75a281a libswiftCore.so`swift_retain + 42
    frame #1: 0x00007ffff7b4ec00 libswiftTensorFlow.so`AD__$s10TensorFlow6Conv2DV14callAsFunctionyAA0A0VyxGAGF__vjp_src_0_wrt_0_1 + 128
    frame #2: 0x0000555555557561 retain`AD__$s6retain18testConv2DGradientyyF10TensorFlow0E0VySfGAF_AC0C1DVySfGtcfU___vjp_src_0_wrt_0_1 + 209
    frame #3: 0x00005555555570df retain`reabstraction thunk helper from @callee_guaranteed (@guaranteed TensorFlow.Tensor<Swift.Float>, @guaranteed TensorFlow.Conv2D<Swift.Float>) -> (@owned TensorFlow.Tensor<Swift.Float>, @owned @escaping @callee_guaranteed (@guaranteed TensorFlow.Tensor<Swift.Float>) -> (@owned TensorFlow.Tensor<Swift.Float>, @owned TensorFlow.Conv2D<Swift.Float>.TangentVector)) to @escaping @callee_guaranteed (@in_guaranteed TensorFlow.Tensor<Swift.Float>, @in_guaranteed TensorFlow.Conv2D<Swift.Float>) -> (@owned TensorFlow.Tensor<Swift.Float>, @owned @escaping @callee_guaranteed (@guaranteed TensorFlow.Tensor<Swift.Float>) -> (@out TensorFlow.Tensor<Swift.Float>, @out TensorFlow.Conv2D<Swift.Float>.TangentVector)) + 143
    frame #4: 0x00007ffff79f1f98 libswiftTensorFlow.so`reabstraction thunk helper <A, B, C where A: Swift.Differentiable, B: Swift.Differentiable, C: TensorFlow.TensorFlowFloatingPoint> from @callee_guaranteed (@in_guaranteed A, @in_guaranteed B) -> (@owned TensorFlow.Tensor<C>, @owned @escaping @callee_guaranteed (@guaranteed TensorFlow.Tensor<C>) -> (@out A.TangentVector, @out B.TangentVector)) to @escaping @callee_guaranteed (@in_guaranteed A, @in_guaranteed B) -> (@out TensorFlow.Tensor<C>, @owned @escaping @callee_guaranteed (@in_guaranteed TensorFlow.Tensor<C>) -> (@out A.TangentVector, @out B.TangentVector)) + 72
    frame #5: 0x00007ffff7b0830d libswiftTensorFlow.so`partial apply forwarder for reabstraction thunk helper <A, B, C where A: Swift.Differentiable, B: Swift.Differentiable, C: TensorFlow.TensorFlowFloatingPoint> from @callee_guaranteed (@in_guaranteed A, @in_guaranteed B) -> (@owned TensorFlow.Tensor<C>, @owned @escaping @callee_guaranteed (@guaranteed TensorFlow.Tensor<C>) -> (@out A.TangentVector, @out B.TangentVector)) to @escaping @callee_guaranteed (@in_guaranteed A, @in_guaranteed B) -> (@out TensorFlow.Tensor<C>, @owned @escaping @callee_guaranteed (@in_guaranteed TensorFlow.Tensor<C>) -> (@out A.TangentVector, @out B.TangentVector)) + 93
    frame #6: 0x00007ffff74971f1 libswiftCore.so`Swift.valueWithPullback<A, B, C where A: Swift.Differentiable, B: Swift.Differentiable, C: Swift.Differentiable>(at: A, _: B, in: @differentiable (A, B) -> C) -> (value: C, pullback: (C.TangentVector) -> (A.TangentVector, B.TangentVector)) + 113
    frame #7: 0x00007ffff79f1a04 libswiftTensorFlow.so`TensorFlow.valueWithGradient<A, B, C where A: Swift.Differentiable, B: Swift.Differentiable, C: TensorFlow.TensorFlowFloatingPoint>(at: A, _: B, in: @differentiable (A, B) -> TensorFlow.Tensor<C>) -> (value: TensorFlow.Tensor<C>, gradient: (A.TangentVector, B.TangentVector)) + 1220
    frame #8: 0x00007ffff79f2c69 libswiftTensorFlow.so`TensorFlow.gradient<A, B, C where A: Swift.Differentiable, B: Swift.Differentiable, C: TensorFlow.TensorFlowFloatingPoint>(at: A, _: B, in: @differentiable (A, B) -> TensorFlow.Tensor<C>) -> (A.TangentVector, B.TangentVector) + 617
    frame #9: 0x000055555555674a retain`retain.testConv2DGradient() -> () + 2122
    frame #10: 0x0000555555555ef4 retain`main + 20
    frame #11: 0x00007fffed14a52b libc.so.6`__libc_start_main(main=(retain`main), argc=1, argv=0x00007fffffffde68, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffde58) at libc-start.c:308:16
    frame #12: 0x0000555555555c3a retain`_start + 42

The only SIL differences that this PR causes on this code are:

  • Declarations for differentiability witnesses of Tensor<>.sum(), Conv2D.callAsFunction(_:), and identity<A>(_:) appear.
  • A few function_refs turn into differentiability_witness_functions.

It's pretty surprising that this affects memory management.

Current ideas of what might be going on:

  • IRGen for differentiability_witness_functions does something improper with ownership. (Seems unlikely because these function pointers should be trivial.)
  • There's some latent nondeterministic memory management issue that suddenly popped up.

Next, I'm going to carefully read through the SIL to see if I see anything suspicious in it.

@marcrasi
Copy link
Author

I think I solved it. I uploaded a commit, and I'm going to run all the tests now.

This is the problem:

// If the witness is a declaration, then LoadableByAddress cannot have changed
// the type because the function is in a different module.
if (instr->getWitness()->isDeclaration())
  return true;

The comment is false. LoadableByAddress can change the type of a function in a different module because pre-LoadableByAddress SIL references the pre-LoadableByAddress versions of external functions.

So I have fixed it by making LoadableByAddress work on external differentiability witnesses.

I have also added a cross-module LoadableByAddress test.

While writing the test, I realized that we didn't have print/parse/serialization/deserialization for differentiability_witness_functions with explicit types, so I added all that too.

@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@marcrasi marcrasi force-pushed the marcrasi-use-diff-witness branch from fef6423 to 5f93d60 Compare November 28, 2019 02:42
@marcrasi
Copy link
Author

@swift-ci please test tensorflow

2 similar comments
@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Nov 28, 2019

This is really awesome. Thank you Marc!

@dan-zheng
Copy link
Contributor

The comment is false. LoadableByAddress can change the type of a function in a different module because pre-LoadableByAddress SIL references the pre-LoadableByAddress versions of external functions.

So I have fixed it by making LoadableByAddress work on external differentiability witnesses.

I have also added a cross-module LoadableByAddress test.

Nice! differentiability_witness_function verification isn't defined yet, oops - it seems like verification should've caught this error?

#28501 to apple:marcrasi-use-diff-witness adds SILVerifier::checkDifferentiableFunctionWitnessInst.

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor

dan-zheng commented Nov 29, 2019

Merging now! Verified that the extended test suite (tensorflow/swift-apis, etc) passes.
I'll use an adapted/updated version of the PR description as the squash commit message - hope that's okay.

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.

3 participants