Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Conversation

@dan-zheng
Copy link
Member

…ors.

Fixes swift build. Without this change, swift build fails:

$ swift build
Compile Swift Module 'DeepLearning' (8 sources)
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:49:35: error: ambiguous use of 'inference'
        return withLearningPhase(.inference) {
                                  ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Context.swift:28:10: note: found this candidate
    case inference
         ^
TensorFlow.LearningPhase:3:10: note: found this candidate
    case inference
         ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:60:35: error: ambiguous use of 'inference'
        return withLearningPhase(.inference) {
                                  ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Context.swift:28:10: note: found this candidate
    case inference
         ^
TensorFlow.LearningPhase:3:10: note: found this candidate
    case inference
         ^

@dan-zheng dan-zheng requested a review from rxwei April 17, 2019 16:47
@rxwei
Copy link
Contributor

rxwei commented Apr 17, 2019

I want to figure out why this is the case though. It wasn't a problem until the Int32 patch.

@dan-zheng
Copy link
Member Author

Did you try swift build with a toolchain after the Context patch?
I don't believe this problem is related to the Int32 patch, since that didn't affect Context.

@rxwei
Copy link
Contributor

rxwei commented Apr 17, 2019

I think I did, but I'm not 100% sure.

It seems tests are failing because you haven't updated them.

…ors.

Fixes `swift build` and `swift test`.
@saeta
Copy link
Contributor

saeta commented Apr 17, 2019

Thanks @dan-zheng This is blocking me too. :-)

@dan-zheng dan-zheng merged commit 9832310 into master Apr 17, 2019
@dan-zheng dan-zheng deleted the fix-swift-build branch April 17, 2019 18:02
@dan-zheng
Copy link
Member Author

After merging master, I get a new crash now:

Compile Swift Module 'DeepLearning' (8 sources)
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1353:33: error: function is not differentiable
    public var zeroState: State {
                                ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1354:42: note: cannot differentiate through a non-differentiable result; do you want to add '.withoutDerivative()'?
        return State(cell: Tensor(zeros: stateShape), hidden: Tensor(zeros: stateShape))
                                         ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1353:33: error: function is not differentiable
    public var zeroState: State {
                                ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1354:42: note: expression is not differentiable
        return State(cell: Tensor(zeros: stateShape), hidden: Tensor(zeros: stateShape))
                                         ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1307:42: error: function is not differentiable
    public var zeroState: Tensor<Scalar> {
                                         ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1308:30: note: cannot differentiate through a non-differentiable result; do you want to add '.withoutDerivative()'?
        return Tensor(zeros: stateShape)
                             ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1307:42: error: function is not differentiable
    public var zeroState: Tensor<Scalar> {
                                         ^
/Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift:1308:30: note: expression is not differentiable
        return Tensor(zeros: stateShape)
                             ^
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-tensorflow-LOCAL-2019-04-17-a.xctoolchain/usr/bin/swift -frontend -c /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Context.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Helpers.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Initializers.swift -primary-file /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Loss.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Operators.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Optimizer.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Random.swift -emit-module-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer~partial.swiftmodule -emit-module-doc-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer~partial.swiftdoc -emit-dependencies-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.d -emit-reference-dependencies-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.swiftdeps -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macos
x/debug/ModuleCache -swift-version 4.2 -Onone -D SWIFT_PACKAGE -D DEBUG -color-diagnostics -parse-as-library -module-name DeepLearning -o /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.swift.o -index-store-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/index/store -index-system-modules
1.	While running pass #8606 SILModuleTransform "Differentiation".
0  swift                    0x00000001093d6598 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x00000001093d5815 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001093d6ba2 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff6bee1b3d _sigtramp + 29
4  swift                    0x0000000106bab048 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 216
5  swift                    0x00000001065a8b33 swift::SILType::subst(swift::SILModule&, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::CanGenericSignature) const + 179
6  swift                    0x00000001065a8bf3 swift::SILType::subst(swift::SILModule&, swift::SubstitutionMap) const + 51
7  swift                    0x000000010623dc2f (anonymous namespace)::AdjointEmitter::makeZeroAdjointValue(swift::SILType) + 95
8  swift                    0x000000010623684e swift::SILInstructionVisitor<(anonymous namespace)::AdjointEmitter, void>::visit(swift::SILInstruction*) + 16030
9  swift                    0x00000001061ff7c6 (anonymous namespace)::Differentiation::run() + 6950
10 swift                    0x000000010630044b swift::SILPassManager::runModulePass(unsigned int) + 1083
11 swift                    0x0000000106300f24 swift::SILPassManager::execute() + 692
12 swift                    0x000000010583b3ab swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
13 swift                    0x0000000106309dd4 swift::runSILDiagnosticPasses(swift::SILModule&) + 132
14 swift                    0x00000001056e7d7b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 11291
15 swift                    0x00000001056e40cd swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3021
16 swift                    0x0000000105695cde main + 686
17 libdyld.dylib            0x00007fff6bcf6ed9 start + 1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)

It seems related to changes introduced in #71.

@rxwei
Copy link
Contributor

rxwei commented Apr 17, 2019

Darn. We should remove the @differentiable requirement from the RNNCell protocol.

@dan-zheng
Copy link
Member Author

I tried removing @differentiable from the zeroState requirement, but the crash persists:

diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift
index ca2c333..b8f6926 100644
--- a/Sources/DeepLearning/Layer.swift
+++ b/Sources/DeepLearning/Layer.swift
@@ -1276,7 +1276,6 @@ public protocol RNNCell: Layer where Input == RNNCellInput<TimeStepInput, State>
     /// The state that may be preserved across time steps.
     associatedtype State: Differentiable
     /// The zero state.
-    @differentiable
     var zeroState: State { get }
 }

@@ -1303,7 +1302,6 @@ public struct SimpleRNNCell<Scalar: TensorFlowFloatingPoint>: RNNCell {
         return TensorShape([1, weight.shape[1]])
     }

-    @differentiable
     public var zeroState: Tensor<Scalar> {
         return Tensor(zeros: stateShape)
     }
@@ -1349,7 +1347,6 @@ public struct LSTMCell<Scalar: TensorFlowFloatingPoint>: RNNCell {
         return TensorShape([1, inputWeight.shape[1]])
     }

-    @differentiable
     public var zeroState: State {
         return State(cell: Tensor(zeros: stateShape), hidden: Tensor(zeros: stateShape))
     }
Compile Swift Module 'DeepLearning' (8 sources)
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-tensorflow-LOCAL-2019-04-17-a.xctoolchain/usr/bin/swift -frontend -c /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Context.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Helpers.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Initializers.swift -primary-file /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Layer.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Loss.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Operators.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Optimizer.swift /Users/danielzheng/swift-dev/tensorflow-swift-apis/Sources/DeepLearning/Random.swift -emit-module-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer~partial.swiftmodule -emit-module-doc-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer~partial.swiftdoc -emit-dependencies-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.d -emit-reference-dependencies-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.swiftdeps -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/ModuleCache -swift-version 4.2 -Onone -D SWIFT_PACKAGE -D DEBUG -color-diagnostics -parse-as-library -module-name DeepLearning -o /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/DeepLearning.build/Layer.swift.o -index-store-path /Users/danielzheng/swift-dev/tensorflow-swift-apis/.build/x86_64-apple-macosx/debug/index/store -index-system-modules
1.	While running pass #8606 SILModuleTransform "Differentiation".
0  swift                    0x000000010e985598 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010e984815 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010e985ba2 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff6bee1b3d _sigtramp + 29
4  swift                    0x000000010c15a048 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 216
5  swift                    0x000000010bb57b33 swift::SILType::subst(swift::SILModule&, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::CanGenericSignature) const + 179
6  swift                    0x000000010bb57bf3 swift::SILType::subst(swift::SILModule&, swift::SubstitutionMap) const + 51
7  swift                    0x000000010b7ecc2f (anonymous namespace)::AdjointEmitter::makeZeroAdjointValue(swift::SILType) + 95
8  swift                    0x000000010b7e584e swift::SILInstructionVisitor<(anonymous namespace)::AdjointEmitter, void>::visit(swift::SILInstruction*) + 16030
9  swift                    0x000000010b7ae7c6 (anonymous namespace)::Differentiation::run() + 6950
10 swift                    0x000000010b8af44b swift::SILPassManager::runModulePass(unsigned int) + 1083
11 swift                    0x000000010b8aff24 swift::SILPassManager::execute() + 692
12 swift                    0x000000010adea3ab swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
13 swift                    0x000000010b8b8dd4 swift::runSILDiagnosticPasses(swift::SILModule&) + 132
14 swift                    0x0000
00010ac96d7b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 11291
15 swift                    0x000000010ac930cd swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3021
16 swift                    0x000000010ac44cde main + 686
17 libdyld.dylib            0x00007fff6bcf6ed9 start + 1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)

Narrowing down the bug now.

@rxwei
Copy link
Contributor

rxwei commented Apr 17, 2019

Looks like zero emission is doing something funny. I do wonder what it's emitting a zero for.

@dan-zheng
Copy link
Member Author

Filed TF-440 with full log.
The crash happens for a struct_extract instruction:

[AD] AdjointEmitter visited:
[ORIG]  %4 = struct_extract %0 : $RNNCellInput<Tensor<Scalar>, Tensor<Scalar>>, #RNNCellInput.input // users: %35, %11, %6, %5
... crash

@rxwei
Copy link
Contributor

rxwei commented Apr 17, 2019

Fixing now.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants