-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[TF] Added support for advanced indexing and slicing #23684
Conversation
Folks are still working on merging things from master. I'll take a little longer. Have you tried adding a setter?
Before we have variadic generics, we can use existentials.
The Google Swift Style Guide is slightly inconsistent with out local convention: https://google.github.io/swift/#line-wrapping. But you can follow its line wrapping guide.
Not yet. The feature is called "retroactive derivative registration" and will take some time to engineer.
We should stick with Swift's range formation operators and semantics for now. The precondition that
I don't think providing our own
For now, I'd recommend against supporting
Actually, our plan is to gradually move everything to tensorflow/swift-apis. |
I'll add this today. I can use
Ok, I can use
Sounds good.
Sorry, that's what I meant with the
Sounds good, although, if we want to avoid using Also, the strided slice gradient is a dense tensor, so we can support it fine for now, but an advantage of gather is that, once we support sparse tensor gradients, we can compute its gradient as something equivalent to
That sounds great actually! I wonder if we should be making these new additions for ops directly in that repo in that case. Let's keep this PR here for now, but maybe next time I work on adding support for new ops, I may do it there directly. |
Also, I just realized that the |
Great, we are on the same page. Before
Feel free to move APIs there in future PRs.
The raw op generation script should be changed to ignore ops that take ref arguments. As to |
I looked into the setter a bit and I realized that |
I agree. Also, |
I added support for a new |
You can start a PR and go through reviews in core TF with folks like @alextp. This looks right, but I don't own the kernel code in core TensorFlow to say this is the right direction or not.
There's no way yet. Adding the kernel in core TF will be the first step. |
I'm following through with Alex on the core TF PR. In the meantime, how can I add separate VJP registrations for the getter and the setter of a subscript? |
Setters cannot have a VJP yet. |
Ok, so that means I can just use |
Use |
@rxwei I updated the TensorFlow checkout commit to include the strided slice assign op that was merged, but when I try to compile, I get a linking error saying that |
Could you try a bazel build in |
That succeeds. I can also see the compiled binaries in
`../tensorflow/bazel-bin/tensorflow`.
…On Tue, Apr 9, 2019 at 1:21 PM Richard Wei ***@***.***> wrote:
Could you try a bazel build in ../tensorflow?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#23684 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABPCXL0qI4wN9fICdRMGY9bvF9lK04sCks5vfMwngaJpZM4cTioG>
.
|
You can make a renamed copy of the lib and try that. |
But where should I place it? |
Yes I agree. By the way, what's the difference between a nullary operator and a global variable? I tried to start an evolution topic that included strides, but I guess it may have been too generic and not focused on a single subject. By the way, I just pushed the requested changes. If these look ok, I can go ahead and merge upstream changes including the |
Operators and identifiers are separate sets of characters. That's the main difference. Operators are functions, so I guess a nullary operator would have to represent a nullary function. Even if we had nullary operators, it still won't solve our problem. We need structural types (including function types) to be able to conform to protocols. |
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.
By the way, I just pushed the requested changes. If these look ok, I can go ahead and merge upstream changes including the
Int32 -> Int
change.
LGTM! One suggestion is adding tests for the newly added ..
operators.
@rxwei This should be ready now. I have also added a couple of tests for the new stride operator. |
@swift-ci please test tensorflow |
1 similar comment
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
6 similar comments
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
I can't tell if the tests are running on the CI, but I just ran them locally and they all pass (in case this helps). |
@swift-ci please test tensorflow |
Now it's triggered! |
Thanks Anthony for driving this! |
Thanks for all the help and useful suggestions Richard! |
This actually failed GPU tests: https://ci-external.swift.org/job/swift-PR-TensorFlow-Linux-gpu/1272/console. Could you look into this? |
Ok, I think this is because GPU only supports Int32 masks. We need to switch them from Int64 to Int32. |
I'm not sure if that's the reason because int64 is also supported for these masks with GPUs. The error messages look like something else may be wrong. |
This adds support for advanced indexing and slicing to tensors. I plan to add support for setters and gradients soon, but first I wanted to see if this initial design looks good to the Swift for TF team.
I also added a new test and made sure all previous tests using tensor subscripts still pass, using the new subscript implementation.
Some comments/questions:
@differentiating
to directly provided the gradient ofRaw.stridedSlice
? Otherwise, I can provide a gradient directly for the subscript function.0 ..< -1
cannot be used, even if only as syntactic sugar. Do we need that precondition for Swift ranges? In principle, the ranges could be allowed to be empty, from a Swift point of view, and have this be used simply as syntactic sugar. This can also be avoided if we define our own..<
,...
, etc. operators that support negative indices and are only used as syntactic sugar for advanced indexing and slicing...<
,...
, etc. operators as discussed above, that also allow for a..
operator for strided ranges.Int32
,Tensor<Int32>
, and other types? I get an error whenever I try to do that saying I can only define one extension for each protocol conformance, irrespective of the conditional constraint on the type.Ops.swift
. How about making anOps
directory inTensorFlow
and have separate files likeManipulation.swift
,Math.swift
, etc.