-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Alternative to np.repeat
?
#258
Comments
@harryjulian you are looking for the concatenate op. We also have a stack if that's useful. Would be great to put a |
@awni Hey sorry to bother you, but I would love to contribute to this can you please move me in the right direction, somewhat new to this. |
@awni I also like to work on the same. Can you please provide a bit more context so I can add the relevant code? Thanks in advance! |
Here is the function we'd like to implement: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html So the same behavior as that |
Would an operation like this need to be implemented under the hood or just on top of the existing Python bindings? |
The way to do it is as a C++ op (which uses other C++ ops like reshape, concatenate, etc) with a binding to python. We don't implement functions in pure python in |
To repeat the instances of |
@0x1orz What do you mean by that? Can you give an example? |
@awni from copy import deepcopy
repeat = lambda module, n: [deepcopy(module) for _ in range(n)]
from torch import nn
layer = nn.Linear(2,3)
layers = repeat(layer, 2)
for layer in layers:
layer.reset_parameters() while in MLX, import mlx.nn as mlx_nn
mlx_layer = mlx_nn.Linear(2,3)
mlx_layers = repeat(mlx_layer, 2) that raised |
Ah that makes sense. Since that's such a different thing from |
We added repeat in #278. Will be in the next release. |
I tried to use
.repeat
to repeat a 1D array, but found it's missing from MLX at the moment.I tried making a similar function, making use of a list for the cloning, but MLX doesn't seem to like this either.
Any ideas on the easiest / most efficient way to compute a repeat of an array with MLX at the moment?
The text was updated successfully, but these errors were encountered: