-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[AutoDiff] Fix AllocStack SILDebugVariable assertion failure. #27486
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
[AutoDiff] Fix AllocStack SILDebugVariable assertion failure. #27486
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this code is constructing a temporary buffer inside PullbackEmitter::getAdjointBuffer
- maybe it's even correct for this buffer to have a synthesized location (because it's an auxiliary variable that doesn't directly relate to user-written variables).
This patch isn't yet robust, triggering tests to see if TensorFlow compilation passes. (I found locally that it did.) |
@swift-ci Please test tensorflow |
swiftlang#27238 tightened debug info requirements, adding assertions to AllocStack and AllocBox constructors. This caused assertion failures for the differentiation transform, which does not provide SILDebugVariable when building AllocStack during differential/pullback generation: ``` Assertion failed: ((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) && "location is a VarDecl, but SILDebugVariable is empty"), function createAllocStack, file /Users/danielzheng/swift-merge/swift/include/swift/SIL/SILBuilder.h, line 407. Stack dump: ... 1. Swift version 5.1-dev (LLVM c5340df2d1, Swift 7bc4a06) 2. While running pass swiftlang#56204 SILModuleTransform "Differentiation". swift::SILBuilder::createAllocStack(...) (anonymous namespace)::PullbackEmitter::getAdjointBuffer(...) ``` There are a few potential fixes: - Use `RegularLocation::getAutoGeneratedLocation()` so that the assertion does not trigger. This needs to be done for all `createAllocStack` invocations in Differentiation.cpp. - Find a way to provide the correct SILDebugVariable. This seems hard because SILDebugVariable is constructed during SILGen and has a particular "ArgNo" field that seems hard to compute. This is an initial minimal test to see if tensorflow/swift-apis compilation will pass. More changes are needed for a robust final fix: - Update all `createAllocStack` calls, including those in differential generation. - Add apple/swift tests.
Doing this for all |
Use the VarInfo of the original AllocStack instruction.
9e2a28d
to
2c6f07c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix LGTM.
@swift-ci Please test tensorflow |
1 similar comment
@swift-ci Please test tensorflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you guys for explaining how this should be fixed!
#27238 tightened debug info requirements, adding assertions to
AllocStack and AllocBox constructors.
This requires differentiation transform changes:
alloc_stack
instructions that may have SILDebugVariable info,propagate the info.
JVPEmitter::emitTangentForAllocStackInst
.user-written VarDecls, use
RegularLocation::getAutoGeneratedLocation()
asthe location so that assertions do not trigger.
PullbackEmitter::getAdjointBuffer
.Example assertion failure prior to this patch: