-
Notifications
You must be signed in to change notification settings - Fork 47
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
allow fully parameterized seperate types for matrix elements,vector elements,their products and accumulators #283
Comments
The If you wish to implement this, the easiest way is to copy |
https://docs.rs/sprs/0.10.0/sprs/trait.MulAcc.html now examining more closely I see that you really do rely on Fused multiply add. it might take a bit more thought for me how this will work. I think it might be possible even in my experiment and still allowing everything as generic as I have in mind.. but I should confirm this before trying anything here .. i'll end up with something like this I'll mention that I've also been using references in the computation steps (wheras in most graphics-style vec/matrix libs i've used copy types) - again this opens the door for slotting in non trivial types (bignums ?..) |
This trait bound looks right, although care must be taken so it does not involve a |
thinking out loud , what if the library was split into some layers ..is it possible to achieve code re-use with easy experimentation (without making changes to a larger library with little overlap in my rather tangential requirements).. without creating dependancy hell with many smaller libraries. I've already benefited from reviewing your code here.. (discoverd the established Besides all that (grand plan) .. I may be curious to submit a PR fully genericising MulAdd Back in C++ i'm just experimenting with Eigen ( a very comprehensive library) .. it can get as far as 3 types (a Matrix element, a Vector element , and a seperate Output type computed from MatrixElem*VecElem->ResultElem) .. but can't quite seem to do the full 4 types I have in mind. Retrofitting changes to Eigen would be downright impossible as it's huge and more internally complex, and has way more users riding on it |
1st small experiment in this direction:
https://github.com/experiment9123/sprs/blob/master/src/mul_acc.rs so,this defaults to Src1,Src2=Self, and the "default impl" just does I think we could gradually work through the functions and make each function using a I've changed this function to handle it, see the example .. this is a taste of the kind of refactoring that might crop up to retrofit this change. the good new is (i)it seems to be possible incrementally(ii)The MulAcc trait itself really helps this refactor. the bad news is "non trivial changes may be needed", hence needing review for mathematical correctness It will have to be a rolling refactor so you will need to approve every step of the process rather than waiting for one big PR that enables this support
further investigation - "mat(A) * mat(B) -> vec(C)" |
Really great to see this can be done incrementally, that makes reviews a lot easier!
|
Apologies if this is already supported (or considered and rejected)
for AI mixed precision matrices are increasingly common - for example 8bit weights, relying on 32bit accumulation
one way to support this might be this kind of signature:
it may however be even more intuitive to rely on the 'accumulator' being reverse infered , and rely on it supporing "+=" for products.
this would support all eventualities, e.g. 16bit vector values, 8bit matrix weights -> 24 bit products(in i32), but so many components that 64bit accumulators are needed.
I wasn't sure if the library already supports this but I see the
trait MulAcc {}
which I presume is used for the evaluation, which seems to imply the same type must be used for all steps of the process.Perhaps the type relationships here could be retrofitted to an extension of this trait?
This would also allow for dimension checked types, e.g. physical units for the A,B, Outputs being seperate. However merely considering that will miss the potential for product / accumulator precision
Furthermore putting non numeric types into these would allow using the sparse matrix ops as a way of performing graph operations (for example the "Accumulator" could be a collection that takes information from edge links described by a sparse matrix)
in this toy example i'm building i'm doing this sort of thing - here 'conways game of life' is implemented on a 'graph type' built from a vector & SparseMatrix holding the edges. (the edge matrix 'value' is empty (), the 'product' & accumulators are u32, the vector type is a generic 'Cell', the output of the matrix multiply is a "number of neighbours" and another function is used to update the cells using that)
https://github.com/experiment9123/graphengine/blob/master/rustgraph/examples/gol.rs
https://github.com/experiment9123/graphengine/blob/master/rustgraph/src/lib.rs
the eventual intention here is to use this framework for spiking neural net experiments
The text was updated successfully, but these errors were encountered: