-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fixed a bug in const folding, where an inst that's not of type SingleValueInstruction gets added to the worklist #18272
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
Fixed a bug in const folding, where an inst that's not of type SingleValueInstruction gets added to the worklist #18272
Conversation
SingleValueInstruction gets added to the worklist, causing cast assert at https://github.com/apple/swift/blame/master/lib/SILOptimizer/Utils/ConstantFolding.cpp#L1585. One such example inst is the following, which produces a SILValue of type MultipleValueInstructionResult, so ValueBase::getDefiningInstruction() still returns a valid inst for it, even though that graph_op inst is not a SingleValueInstruction. ``` %94 = graph_op "Fill,i,i"(%73 : $TensorHandle<Int32>, %85 : $TensorHandle<Float>) {T: $Float, index_type: $Int32, __device: "/device:CPU:0"} : $TensorHandle<Float> // users: %1581, %100, %98, %97, %99, %103, %106, %111, %113, %118, %755 ```
@swift-ci please test tensorflow |
I can upstream this fix later if that makes sense. |
I didn't have a simpler test case, but the fix is motivated by a crash in the AutoEncoder model, and I verified the fix with that model as follows.
The compilation finishes. When I run the code as
I got:
This is probably due to my incorrect env, and I guess would not occur if we build and run this model with the proper S4TF toolchain. |
I built a toolchain, and compiled the model code with:
But the above runtime error still occurs. @rxwei, are you seeing this as well? |
From google search, this error appears to come from python (e.g. MDAnalysis/mdanalysis#1739). Any ideas? |
This should be a python error. On macOS, removing brewed python would solve the problem. Not sure about Linux though. |
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.
LGTM, please do upstream this, thanks!
@dan-zheng Dan, can you try if you can reproduce this python error on Linux? Thanks. |
@mhong I wasn't able to reproduce the error on a fresh toolchain build (swift 37864e1, swift-models tensorflow/swift-models@40c239b). I ran the following and it worked fine:
|
@dan-zheng, running My error trace:
|
You need to install matplotlib.
|
The error is Incidentally, I did find another bug with the data loading logic (using |
The matplotlib error appears a red herring -- I got that only when I activate a certain conda env. Once I deactivate that, I'm getting back to the
|
SingleValueInstruction gets added to the worklist, causing cast assert at https://github.com/apple/swift/blame/master/lib/SILOptimizer/Utils/ConstantFolding.cpp#L1585. One such example inst is the following (in the tensorflow branch), which produces a SILValue of type MultipleValueInstructionResult, so ValueBase::getDefiningInstruction() still returns a valid inst for it, even though that graph_op inst is not a SingleValueInstruction. ``` %94 = graph_op "Fill,i,i"(%73 : $TensorHandle<Int32>, %85 : $TensorHandle<Float>) {T: $Float, index_type: $Int32, __device: "/device:CPU:0"} : $TensorHandle<Float> ``` The same fix has been merged into the tensorflow branch: swiftlang#18272
MultipleValueInstructionResult, which got fixed in swiftlang#18272. Confirmed this test crashes without that fix.
MultipleValueInstructionResult, which got fixed in #18272. Confirmed this test crashes without that fix.
This causes cast assert at https://github.com/apple/swift/blame/master/lib/SILOptimizer/Utils/ConstantFolding.cpp#L1585.
One such example inst is the following, which produces a SILValue of type
MultipleValueInstructionResult, so ValueBase::getDefiningInstruction() still
returns a valid inst for it, even though that graph_op inst is not a SingleValueInstruction.