-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix stack overflow containsTensorFlowValue for recursive data structures. #21449
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
Conversation
@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.
Interesting finding! Some thoughts / suggestions:
- can you create a stand-alone unit test (which deals with tensors) that exposes this problem?
From the cited example:
struct PairedStructure<I: Comparable> {
let bounds: Range<I>
let subStructure: [PairedStructure<I>]
}
subStructure
is not itself a struct, and given https://stackoverflow.com/questions/36080491/swift-struct-type-recursion, i wonder if we should tweak the impl to avoid descending into a non-struct type, such as array?
- i'm also wondering if we could avoid calling
structContainsTensorFlowValue()
on structs likePairedStructure
, which are not related to tensors / TF. As a general principle, can we avoid triggering any of our S4TF related code, when user code involves no tensors (the "pay only for what you use" principle in language/system design and impl).
I will try to create one. I think I will have to create the Struct explicitly in the test.
Shouldn't we return true if the field is an array of tensors?
Don't we want to know if a struct has fields of Tensors? e.g. Parameters? |
I played with this issue and understood it better now. The test I used is: struct S {
let sub: [S] = []
}
func foo() -> S {
let s = S()
return s
}
public func bar() {
_ = Tensor<Float>(1.0)
_ = foo()
} In this case the
So I agree this is a real issue. The fix looks fine. Another option that might be worth considering is extending Following up on another point that was raised earlier -- I'm still curious how this issue got triggered for Can you confirm that we will not be calling |
@swift-ci please test tensorflow |
The utility function
containsTensorFlowValue
fails with a stack overflow error when it is invoked on a recursive data structure such as PairedStructure struct in Prototypes/PatternMatching.swift test.This PR simply breaks cycles by keeping track of the parent decls.