Skip to content
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

Support for views, spans, iterators? #415

Open
stellarpower opened this issue Mar 23, 2024 · 4 comments
Open

Support for views, spans, iterators? #415

stellarpower opened this issue Mar 23, 2024 · 4 comments

Comments

@stellarpower
Copy link

Hi,

Thanks for this! C++ is making NNs a little bit tolerable. If I could train with this in lieu of python at all, life would be much better!!

It seems that tensor/tensors only have constructors for working directly with vectors of data. Would it be possible to support some other contiguous views, such as iterators, std::span, or maybe something from the ranges library, etc.?

I'm currently iterating over a long time series of data, and feeding in data one sequence at a time, to an LSTM-based model. It'd be nice if I could provide some non-owning reference to the start of the current page, and then the same for where frugally-deep can place the outputs, as currently I am copying into a shorter vector, running inference, and copying the output. I assume a copy of about 512 values is negligible compared to everything else that will be going on, but it'd still be nice to have. I assume a span would be the lowest-overhead way to achieve this.

Are there any technical reasons why this wouldn't be possible?

Thanks

@Dobiasd
Copy link
Owner

Dobiasd commented Mar 25, 2024

Hi, and thanks for the nice feedback and the interesting suggestion. Using std::span somewhere in frugally-deep would raise the compiler requirement from C++14 to C++20. So I'm a bit hesitant to add this feature.

@stellarpower
Copy link
Author

True; but you could enable it conditionally if the compiler has this built-in. There are also third-party implementations of span for pre C++-20 compilers.

Spans also meet requirements for contiguous iterators, so it might be best to template it and be agnostic to the exact implementation - just assuming we have a non-owning view on the input which we can run over and read, and possibly also a view on the output we can increment and write to.

@Dobiasd
Copy link
Owner

Dobiasd commented Mar 26, 2024

Copying the input data from a span into a vector should usually not be significant regarding speed or memory usage, since in the prediction step of most models, much more is happening. With such a small gain as the potential win, I'm not sure if it's worth the complexity.

Are you interested in proposing an implementation in a PR?

@stellarpower
Copy link
Author

I'm pretty short on time right now, but if I end up looking into it as part of the current project, then definitely happy to get something committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants