Skip to content

Dimitris/requantize bmm ref#78

Open
DimitrisPapac wants to merge 61 commits intomainfrom
dimitris/requantize-bmm-ref
Open

Dimitris/requantize bmm ref#78
DimitrisPapac wants to merge 61 commits intomainfrom
dimitris/requantize-bmm-ref

Conversation

@DimitrisPapac
Copy link
Contributor

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, Qarray to Tensor, InnerType to Integral, etc.) These changes resulted in significant code cleanup. A number of tests are also included. This pull request subsumes pull requests: #70 and #73 .

DimitrisPapac and others added 30 commits April 8, 2024 10:02
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>
Antonio95 and others added 10 commits April 18, 2024 15:11
…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
@DimitrisPapac DimitrisPapac requested a review from a team as a code owner April 26, 2024 09:27
Copy link
Contributor

@Antonio95 Antonio95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@Cesar199999 Cesar199999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this revision is already in master, and I think we should stick to revs no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, on it!

Comment on lines +66 to +76
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),
),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be simplified? e.g. with a macro

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this means there's one requantization strategy per model, yes?
Is this what we want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +100 to +102
RequantizeBMMFloat(RequantizeBMMFloatNode<ST>),
RequantizeBMMRef(RequantizeBMMRefNode<ST>),
RequantizeBMMSingle(RequantizeBMMSingleNode<ST>),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok def need better names :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Successfully merging this pull request may close these issues.

4 participants