Conversation
Co-authored-by: Cesar Descalzo <Cesar199999@users.noreply.github.com>
…ion node generic without floating the type all the way to the model Co-authored-by: Antonio95 <anmegi.95@gmail.com>
…uantisation node generic without floating the type all the way to the model" This reverts commit 75caebd8cbeb809b197c53087f69892fa49785b6.
Co-authored-by: Antonio95 <anmegi.95@gmail.com>
Co-authored-by: Antonio95 <anmegi.95@gmail.com>
Co-authored-by: Antonio95 <anmegi.95@gmail.com>
…innertype Various refactors around `QArray` and requantisation
Co-authored-by: Antonio Mejías Gil <anmegi.95@gmail.com> Signed-off-by: Cesar Descalzo <80001463+Cesar199999@users.noreply.github.com>
Co-authored-by: Antonio Mejías Gil <anmegi.95@gmail.com> Signed-off-by: Cesar Descalzo <80001463+Cesar199999@users.noreply.github.com>
…ge-types Replace QTypeArray by NIOTensor
Antonio95
left a comment
There was a problem hiding this comment.
Very good job! The thorough tests are great. There are no meaningful changes to make as far as I am concerned: I have simply left a couple of tiny comments.
Cesar199999
left a comment
There was a problem hiding this comment.
Nice! Thanks a lot @DimitrisPapac for this great PR :)
I already had the chance to review #70 before it was merged here. Furthermore, while working on #73 (merged here) and #67 (ongoing in antonio-cesar/trait-objects) I could see that everything works. There's not much to add from my side, appart from a couple of design question (that could be done as part of #76 and #75 in future PRs).
mmagician
left a comment
There was a problem hiding this comment.
non-comprehensive review. overall looks good, left some minor comments
Cargo.toml
Outdated
| blake2 = { version = "0.10", default-features = false } | ||
| serde_json = "1.0.108" | ||
| ark-pcs-bench-templates = { git = "https://github.com/HungryCatsStudio/poly-commit", branch = "ligero-uni-and-ml-absorb", default-features = false } | ||
| ark-pcs-bench-templates = { git = "https://github.com/HungryCatsStudio/poly-commit", rev = "dfdd8e8" } |
There was a problem hiding this comment.
this revision is already in master, and I think we should stick to revs no?
There was a problem hiding this comment.
Hey @mmagician, I think you're right. In any case, you can regard the Cargo.toml here as a temporary thing: the one in main was recently cleaned up, pinned to specific revs and made much more consistent (by @Cesar199999, I think).
Things will be much cleaner when main is merged into this PR (which, if I recall correctly, @Cesar199999 will take care of?). In principle that will happen very soon, when the remaining tiny open discussions are concluded.
| let req_bmm_2 = match req_strategy { | ||
| BMMRequantizationStrategy::Floating => Node::RequantizeBMMFloat( | ||
| RequantizeBMMFloatNode::new(OUTPUT_DIM, S_2_I, Z_2_I, S_2_W, Z_2_W, S_2_O, Z_2_O), | ||
| ), | ||
| BMMRequantizationStrategy::Reference => Node::RequantizeBMMRef(RequantizeBMMRefNode::new( | ||
| OUTPUT_DIM, S_2_I, S_2_W, S_2_O, Z_2_O, | ||
| )), | ||
| BMMRequantizationStrategy::SingleRound => Node::RequantizeBMMSingle( | ||
| RequantizeBMMSingleNode::new(OUTPUT_DIM, S_2_I, S_2_W, S_2_O, Z_2_O), | ||
| ), | ||
| }; |
There was a problem hiding this comment.
can this be simplified? e.g. with a macro
There was a problem hiding this comment.
Indeed! I went for a function, since it seemed quite natural. Already pushed to the PR branch. Diff here: https://github.com/HungryCatsStudio/verifiaml/compare/f91ecadc5eea54bc532c3119a4906dfb13cc5d88~1..f91ecadc5eea54bc532c3119a4906dfb13cc5d88
This is a good cleanup, thanks for the suggestion
| // TODO this is incorrect now that we have switched to logs | ||
| pub fn build_simple_perceptron_mnist<F, S, PCS>() -> Model<i8, i32> | ||
| pub fn build_simple_perceptron_mnist<F, S, PCS>( | ||
| req_strategy: BMMRequantizationStrategy, |
There was a problem hiding this comment.
so this means there's one requantization strategy per model, yes?
Is this what we want?
There was a problem hiding this comment.
Yes, basically these are just auxiliary functions that construct our example models by filling the vector of nodes with the nodes it should have. In one of the models there is only one requantisation node and in the other one there are two. In the latter case, we don't have any need to mix requantisation strategies (which sounds a bit unlikely anyway). Still, it should be stressed that this is just code to build examples, not library functionality code. Therefore the "lack of generality" shouldn't be a problem.
Incidentally, the reason we added this argument was so that we could test out how much the reference, single-round and floating-point-based implementations of requantisation each differ from TF Lite execution.
| RequantizeBMMFloat(RequantizeBMMFloatNode<ST>), | ||
| RequantizeBMMRef(RequantizeBMMRefNode<ST>), | ||
| RequantizeBMMSingle(RequantizeBMMSingleNode<ST>), |
There was a problem hiding this comment.
Ok def need better names :)
There was a problem hiding this comment.
Hey @mmagician, what bothers you exactly? Is it how long these lines end up being?
I think the current naming is at least consistent: for each implementor <name>Node of the NodeOps... trait, we have one variant <name>(<name>Node) of the Node enum. Furthermore, as we also discussed a while ago, these requantisation nodes are specific to BMM outputs (e.g. the output of a convolutional layer will likely have a slightly different requantisation code - although I'm not sure tbh; if that turns out not to be the case, we could remove BMM from all of these).
Do you have some better name for these in mind? If it is the length that bothers you, I would propose shortening Requantize to Req:
ReqBMMFloat(ReqBMMFloatNode<ST>),
ReqBMMRef(ReqBMMRefNode<ST>),
ReqBMMSingle(ReqBMMSingleNode<ST>),
As a side note, this code (and in general variant code pattern <name>(<name>Node)) will go away if/when we switch to trait objects.
In summary, this pull request adds new nodes implementing TF Lite's reference requantization method, as well as a simplified (i.e., single-round) requantization variant. This involved some drastic refactoring throughout the codebase in order to accommodate the newly added nodes and use more meaningful identifiers wherever possible (for example,
QarraytoTensor,InnerTypetoIntegral, etc.) These changes resulted in significant code cleanup. A number of tests are also included. This pull request subsumes pull requests: #70 and #73 .