Skip to content

Conversation

@dan-zheng
Copy link
Contributor

@dan-zheng dan-zheng commented Nov 6, 2019

Add PrettyStackTrace in the differentiation transform for the following actions:

  • Processing SIL [differentiable] attributes.
    • Generating JVP/differential functions.
    • Generating VJP functions.
    • Generating pullback functions.
  • Canonicalizing differentiable_function instructions.

Examples:

Assertion failed: (false), function processDifferentiableFunctionInst, file /Users/danielzheng/swift-build/swift/lib/SILOptimizer/Mandatory/Differentiation.cpp, line 8771.
Stack dump:
0.	Program arguments: /Users/danielzheng/swift-build/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -interpret simple_math.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name simple_math
1.	Swift version 5.1.1-dev (LLVM 6e04008c7f, Swift ccfec5fc42)
2.	While running pass #24 SILModuleTransform "Differentiation".
3.	While canonicalizing `differentiable_function` SIL node   %18 = differentiable_function [parameters 0] %17 : $@callee_guaranteed (Float, Int) -> Float // users: %22, %19
4.	While ...in SIL function "@main".
Assertion failed: (false), function VJPEmitter, file /Users/danielzheng/swift-build/swift/lib/SILOptimizer/Mandatory/Differentiation.cpp, line 3348.
Stack dump:
0.	Program arguments: /Users/danielzheng/swift-build/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -interpret simple_math.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name simple_math
1.	Swift version 5.1.1-dev (LLVM 6e04008c7f, Swift ccfec5fc42)
2.	While running pass #24 SILModuleTransform "Differentiation".
3.	While canonicalizing `differentiable_function` SIL node   %18 = differentiable_function [parameters 0] %17 : $@callee_guaranteed (Float, Int) -> Float // users: %22, %19
4.	While ...in SIL function "@main".
5.	While processing `[differentiable source 0 wrt 0]` attribute on SIL function "@$s11simple_mathS2f_SitcfU_".
 for expression at [simple_math.swift:5:25 - line:5:48] RangeText="{ x, y in x + Float(y) "
6.	While generating VJP for SIL function "@$s11simple_mathS2f_SitcfU_".
 for expression at [simple_math.swift:5:25 - line:5:48] RangeText="{ x, y in x + Float(y) "

@pschuh mentioned this enhancement months ago. 🙂

Add PrettyStackTrace in the differentiation transform for the following actions:
- Processing SIL `[differentiable]` attributes.
  - Generating JVP/differential functions.
  - Generating VJP functions.
  - Generating pullback functions.
- Canonicalizing `differentiable_function` instructions.
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Nov 6, 2019
DifferentiableFunctionInst *dfi) {
PrettyStackTraceSILNode dfiTrace("canonicalizing `differentiable_function`",
cast<SILInstruction>(dfi));
PrettyStackTraceSILFunction fnTrace("...in", dfi->getFunction());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this pattern of PrettyStackTraceSILNode followed by PrettyStackTraceSILFunction is used because PrettyStackTraceSILNode by itself does not print any info about the containing SILFunction.

I copied this technique from elsewhere in the codebase. It's less intrusive than adding a flag to PrettyStackTraceSILNode for printing SIL function info.

Example stack trace:

Stack dump:
...
3.	While canonicalizing `differentiable_function` SIL node   %18 = differentiable_function [parameters 0] %17 : $@callee_guaranteed (Float, Int) -> Float // users: %22, %19
4.	While ...in SIL function "@main".

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.

Very nice :)

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng dan-zheng merged commit 55d1070 into swiftlang:tensorflow Nov 7, 2019
@dan-zheng dan-zheng deleted the diff-transform-prettystacktrace branch November 7, 2019 00:14
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.

3 participants