Skip to content

[AutoDiff] Constrain wrt parameters to conform to Differentiable. #26406

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 1 commit into from
Jul 30, 2019

Conversation

dan-zheng
Copy link
Contributor

Constrain all wrt parameters to conform to Differentiable when computing
AD associated function generic signatures.

This fixes crashes when differentiating generic original functions that
do not constrain parameters to be Differentiable, e.g. an unconstrained
identity function.

Resolves TF-691.


func id<T>(_ x: T) -> T { x }
print(gradient(at: 0, in: { x in id(x) }))

Before:

$ swift tf-691.swift
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-07-25-a.xctoolchain/usr/bin/swift -frontend -interpret tf-691.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main
1.	Swift version 5.1-dev (LLVM 200186e28b, Swift 3416770d73)
2.	While running pass #28 SILModuleTransform "Differentiation".
0  swift                    0x000000010ae97ad5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010ae96b18 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010ae980c8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff65936b5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007fc6038c0430 _sigtramp + 2650314992
5  swift                    0x0000000107a8a803 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 243
6  swift                    0x0000000107a8a6d7 swift::SILFunctionType::substGenericArgs(swift::SILModule&, swift::SubstitutionMap) + 231
7  swift                    0x0000000107afc59d swift::SILType::substGenericArgs(swift::SILModule&, swift::SubstitutionMap) const + 77
8  swift                    0x0000000107ab1dc6 swift::PartialApplyInst::create(swift::SILDebugLocation, swift::SILValue, llvm::ArrayRef<swift::SILValue>, swift::SubstitutionMap, swift::ParameterConvention, swift::SILFunction&, swift::SILOpenedArchetypesState&, swift::GenericSpecializationInformation const*, swift::PartialApplyInst::OnStackKind) + 70
9  swift                    0x00000001077cfc1d swift::SILInstructionVisitor<(anonymous namespace)::VJPEmitter, void>::visit(swift::SILInstruction*) + 50573
10 swift                    0x00000001077af6b8 (anonymous namespace)::ADContext::processDifferentiableAttribute(swift::SILFunction*, swift::SILDifferentiableAttr*, (anonymous namespace)::DifferentiationInvoker) + 10856
11 swift                    0x00000001077fe1ca (anonymous namespace)::ADContext::promoteToDifferentiableFunction(swift::AutoDiffFunctionInst*, swift::SILBuilder&, swift::SILLocation, (anonymous namespace)::DifferentiationInvoker) + 4954
12 swift                    0x00000001077b263a (anonymous namespace)::ADContext::processAutoDiffFunctionInst(swift::AutoDiffFunctionInst*) + 378
13 swift                    0x00000001077ac501 (anonymous namespace)::Differentiation::run() + 2913

After:

$ swift tf-691.swift
1.0

Constrain all wrt parameters to conform to `Differentiable` when computing
AD associated function generic signatures.

This fixes crashes when differentiating generic original functions that
do not constrain parameters to be `Differentiable`, e.g. an unconstrained
identity function.

Resolves TF-691.
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Jul 30, 2019
@dan-zheng dan-zheng requested review from rxwei and bartchr808 July 30, 2019 08:26
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng dan-zheng merged commit 6f58fd4 into swiftlang:tensorflow Jul 30, 2019
@dan-zheng dan-zheng deleted the TF-691 branch July 30, 2019 15:54
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Jul 30, 2019
…able`. (swiftlang#26406)"

This reverts commit 6f58fd4.

swiftlang#26406 introduced TF-697;
reverting it until the issue is fixed.

Add testcase for TF-697 to prevent future regressions.
dan-zheng added a commit that referenced this pull request Jul 31, 2019
…able`. (#26406)" (#26420)

This reverts commit 6f58fd4.

#26406 introduced TF-697;
reverting it until the issue is fixed.

Add testcase for TF-697 to prevent future regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants