-
Notifications
You must be signed in to change notification settings - Fork 46
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
RFC: add support for repeating each element of an array #654
Comments
I think because the
I think we should always do that. There are more places where flattening happens, and they should always be row-major I'd think.
Probably yes, but it's a relatively slow process to do so. The issue for it is pytorch/pytorch#50013, and in the tracker issue for numpy compat linked from there, it says:
Of course the longer that is not executed on, the less appetite there will be to do it later on. |
Strangely enough, PyTorch and JAX don't have the same keyword for |
I looked at the PyTorch situation again; it looks a little annoying. @lezcano do you have any thoughts on this one? |
Having a method and a free function that have different behaviour is not a good idea (if I understood the proposal correctly). The whole update process is also a non-go, has we'd need to do it in 3 releases, and the time between releases now has gone up (unofficially) to almost a year. Now, this should not stop the array api from standarising this, as this function is pretty much nb. it doesn't make any sense that in PyTorch's |
I argue we should allow value of Offloading libraries must convert this vector and transfer data to an accelerator during the implementation anyway. Supporting array input would unlock certain use-cases, such a programmatic generation of repeats (random sampling, procedural creation, etc.) |
@oleksandr-pavlyk I think this is a bug in the proposal. |
Supporting arrays is also useful for cases like PyTorch where there might be improvements if the repeats/counts argument is already a tensor obtained from elsewhere and especially if it's already on the target device |
@vadimkantorov What do you mean by "there might be improvements"? There are no improvements, and it may even be detrimental to pass a tensor to this function if it's in CUDA. |
Hi all, this RFC (and PR #690) was briefly discussed in the Array API meeting yesterday. Apology to @kgryte @oleksandr-pavlyk @seberg, for comments I made in the meeting without fully understanding the sticking points here. Below is my updated analysis & response. As already pointed out earlier this thread Moreover, with regard to the However, again some changes in the implementation can help. For example, if the array library can store array metadata on CUDA unified, pinned or heterogeneous memory, preserving stream ordering alone is sufficient, and no blocking copy is needed. (Consider the following CUDA events are ordered: API-wise speaking, there's no issues. The semantics is well-defined, pending the raw-major discussion which is a separate topic. CuPy chose to not support taking arrays for It has been a longstanding, recurrent user request to support
The UX improvement is large and also anticipated by many downstream developers and users. So, as long as we address the dynamic shape issue (I suspect we'd end up with adding a remark, similarly to what we did for the Since @jpivarski had kindly offered a partial workaround to CuPy, I'd like to have Jim to chime in. I'd also eager to have Jax developers involved, maybe @jakevdp can offer insight? |
What about libraries that create compiled code like JAX or Regarding UX, my point is that if you have a repeats tensor, you can always do in PyTorch a |
I argue that belongs to the dynamic shape issue, which is a separate discussion that we can/should certainly have. But given the array APIs have been dealing with it, |
For these cases, it might also be good to allow the user to pass in |
Thanks for digging into that @leofang, so the problem is the synchronization due to unknown size (and maybe also the fact that the array may be mutated). From a NumPy perspective I have to say I find it very strange to ask the user to use |
Nit: it should probably say "if |
Okay, I think we are getting to some semblance of consensus here. Namely,
Are we okay with this path forward? |
This RFC proposes adding support to the array API specification for repeating each element of an array.
Overview
Based on array comparison data, the API is available in most array libraries. The main exception is PyTorch which deviates in its naming convention (
repeat_interleave
vs NumPy et al'srepeat
).Prior art
Proposal
repeats: the number of repetitions for each element.
If
axis
is notNone
,repeats
is an array,repeats.shape
must broadcast tox.shape[axis]
.repeats
is a sequence of ints,len(repeats)
must broadcast tox.shape[axis]
.repeats
is an integer,repeats
must be broadcasted to match the size of a specifiedaxis
.If
axis
isNone
,repeats
is an array,repeats.shape
must broadcast toprod(x.shape)
.repeats
is a sequence of ints,len(repeats)
must broadcast toprod(x.shape)
.repeats
is an integer,repeats
must be broadcasted to match the size of the flattened array.axis: specifies the axis along which to repeat values. If
None
, use a flattened input array and return a flat output array.Questions
nonzero
)repeat
function in its main namespace, given the divergence in behavior fortorch.Tensor.repeat
, which behaves similar tonp.tile
?int
,List
, andTuple
for repeats, not an array. PyTorch may prefer a list ofints
(see Unnecessary cuda synchronizations that we should remove in PyTorch pytorch/pytorch#108968).Related
numpy.repeat
to avoid repeated invocations: ENH: Allow tuple arguments fornumpy.repeat
numpy/numpy#21435 and ENH: Introduce multiple pair parameters in the 'repeat' function numpy/numpy#23937.repeat
: Common APIs across array libraries (1 year later) #187 (comment)The text was updated successfully, but these errors were encountered: