[FBC] Support models without the batch dimension - #4149
Open
darshil929 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
get_mean_statistic_collector(common and OpenVINO builders) accepts an optionalinput_rankargument. Forinput_rank == 1the mean branch usesRawReducer, since a 1D activation has no batch dimension and its elements are already the per channel values; theMeanAggregatorthen averages them across samples. The defaultNonekeeps the current reducer selection for every existing caller.FastBiasCorrection.get_statistic_pointspasses the statically known input and output ranks to the collectors, forwarded bymean_statistic_collectorin all four backends.FastBiasCorrection._get_bias_shiftskipsmean_per_channelfor 1D outputs of the extracted submodel, since they are already per channel data.OneDimMMcase from [BC] Useatleast_1dto enable models with no batch dimention #3479 is enabled in the FBC test template, which parametrizes it across the OpenVINO, Torch, Torch FX and ONNX backend tests.Reason for changes
FastBiasCorrection crashes for models without the batch dimension. On current develop the crash happens in
_get_fp_outputs(TypeError: iteration over a 0-d tensor), and behind it sits theIndexErrorfrom the issue increate_input_data. The root cause is that the statistics pipeline treats axis 0 as the batch axis, so a 1D activation gets its only axis averaged away and the per channel statistics collapse to a scalar. Selecting the reducer by rank where the collectors are built fixes the statistics at the source and keeps BiasCorrection and all other users of the builders unchanged.Related tickets
#3481
Tests
test_update_bias[OneDimMM]passes on all four backends against the reference biases introduced with [BC] Useatleast_1dto enable models with no batch dimention #3479