-
Notifications
You must be signed in to change notification settings - Fork 61
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
implementation of other operators #125
Comments
I think I have the softplus: |
Ok, these are very similar: |
@janaboy74 |
@brightening-eyes |
Hello! A couple of the operators that you've mentioned (e.g. Elu and Softmax) are currently implemented in RTNeural. You've mentioned a lot of operators, so I'll try to split them into three parts: basic math operations, Fourier-style transforms, and neural operators. First I should mention that RTNeural is different from many "machine learning libraries", in that it only supports inferencing, not training. This makes it much simpler for users to provide their own operators. For example, a
I think I would generally prefer to avoid supplying basic math operations (e.g. As for how you would implement a math operator for your own use with RTNeural, it should be pretty straightforward. /** Static implementation of a sin operator. */
template <typename T, int size>
class SinFunctionT
{
public:
static constexpr auto in_size = size;
static constexpr auto out_size = size;
SinFunctionT() = default;
/** Performs forward propagation for sin function. */
inline void forward(const T (&ins)[size]) noexcept
{
for(int i = 0; i < size; ++i)
outs[i] = std::sin(ins[i]);
}
T outs alignas(RTNEURAL_DEFAULT_ALIGNMENT)[size];
}; If you're using the XSIMD backend, the using v_type = xsimd::simd_type<T>;
static constexpr auto v_size = (int)v_type::size;
static constexpr auto v_io_size = ceil_div(size, v_size);
inline void forward(const v_type (&ins)[v_io_size]) noexcept
{
for(int i = 0; i < v_io_size; ++i)
outs[i] = xsimd::sin(ins[i]);
} And with Eigen: using v_type = Eigen::Matrix<T, size, 1>;
inline void forward(const v_type& ins) noexcept
{
outs = ins.array().sin();
}
For operators like the DFT, STFT, DCT, etc... I think I would prefer to avoid implementing those within RTNeural as well, largely for the same reasoning mentioned above. At least with the math operators, we have a pretty "standard" implementation that's always available to us ( For implementing these types of operators for your own use, I think it's hard to give advice without knowing more about the use-case, but I think in most cases it would probably make sense to apply your Fourier operators outside of RTNeural. For example, do a Fourier transform, then run inference on your transformed data in RTNeural, and then do an inverse transform using the output from RTNeural. The reason I would suggest this is that the way RTNeural uses the XSIMD and Eigen libraries to improve performance may not interact well with the tricks used by many Fourier transform libraries to get the best possible performance for those operations. Again, this may depend on your Fourier transform library of choice, and on your particular application.
Some of the operators you mentioned (e.g. softplus, selu, etc) seem pretty like pretty straightforward activation functions, and it would be great to add them to the library! I imagine they could be done pretty simply using the existing activation function implementations as examples. It seems like most of the other operators that you've mentioned are intended to work on two-dimensional data (e.g. reshape, convTranspose, channelShuffle). This is something we've been slowly working on, starting with Conv2D support that was added a few months ago. The current approach is to pass a single array through the model which contains the two-dimensional data in a "flattened" format. However, this approach has some issues (particularly with the XSIMD backend), and I worry that it may not scale well for many layers that are operating on 2D data (at least not in its current form). I have some ideas about how to solve this issue, but I haven't yet written any code in that direction. Again, I'd be happy to discuss this further if you've got some ideas, or have some time available to help with implementation/testing. Anyway, sorry for the long reply. I hope this information is helpful for you! Feel free to reply here, or to split this out into a couple of separate issues if you prefer. |
@jatinchowdhury18 What I can do I will try to fix my json stuff. I don't think that it will be 100% compatible with all the json files, but hopefully I will make from it as much as I can. The main design idea was to create a easy to use parser. To get the data easy after it is in memory. Maybe the structure what I have created is not enough. I have added a vector for single items and as I said the parser is working now, but to format the output is much harder. I don't know when I will done with it. |
I can work on some of the activation functions proposed, as I had already been working on them: GeLU, swish, mish, CDELU, SELU. I can check to see if softmax and softplus is possible/already done. |
@jatinchowdhury18 |
I see. |
hello.
thanks for such a cool library.
if you have time, or if possible, please let me know how can I add these operators?
convTranspose, gelu, layerNorm, groupNorm, instanceNorm, swish, mish, localResponseNorm, paddings, permute, repeat, channelShuffle, reshape, celu, selu, elu, shrink, softmax, softplus, expandDims, squeeze, tile, dft/stft?
the reason is that when these ops when implemented, can help rtNeural run transformers and attention based models, autoencoders and spectrogram to spectrogram conversion models, allowing to write various plugins like noise removals etc.
other things like abs, log, sin, cos, sinh, cosh, argmin, argmax, clip, etc seems not implemented, although it seems easier to implement than others.
thanks.
The text was updated successfully, but these errors were encountered: