-
Notifications
You must be signed in to change notification settings - Fork 1.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
Additional Tensor Operations Needed #1359
Comments
Perhaps see #1351? I also noticed there are definitely some missing Tensor features. |
For |
I would like to see an example implementation of The From what I understand, the custom op traits have a fixed output type ( |
Or a simple idea there would just be to have a |
@LaurentMazare I spent the last weekend digging through the documentation and found that the crate is very under-documented. The example given does not touch layout manipulation at all and does little help to understanding the required steps to implement a custom operation like sort or search. By the way, none of the "some gathering function" really pops into my mind, which leads me back to the starting point. EDIT: I just noticed that impl TensorExt for Tensor {
fn sort<D: dim>(&self, dim: D, ascending: bool) -> Result<(Tensor, Tensor)> {
let sorted_idx = self.apply_op1(/* something */)?;
let sorted_val = self.gather(&sorted_idx, dim)?;
Ok((sorted_val, sorted_idx))
}
} Although I still have no idea how to implement that |
I've tweaked the basics example to show how to implement the custom op. It's only implemented for contiguous tensors (so no need to care about the layout) and only for f32 but should be easy to extend if you want to cover other dtypes. |
Added a See PR #1418. |
Sorry for not responding for a long time, I am too occupied in real life. It is a thrill to see your (and the community's) great work. I am grateful to it. |
I am re-implementing the famous NeRF (https://github.com/bmild/nerf) model in candle. During my experience with candle, I found the following Tensor operations missing.
torch.linspace
torch.cumprod
torch.searchsorted
torch.sort
I am able to find a workaround for
torch.linspace
andtorch.cumprod
, buttorch.searchsorted
andtorch.sort
look formidable. Are there recommended ways to implement that efficiently? Thanks.Current workarounds for
linspace
andcumprod
linspace
: directly taken from the stable-diffusion example.cumprod
: modified from https://github.com/mokeyish/candle-ext/blob/1b38cb1b9faa9694c204d46788fd70d479109bab/src/cumsum.rs#L6-L28 changing the add operation to multiply operation. Not the optimal solution, I admit.The text was updated successfully, but these errors were encountered: