feat(mobilevit): align factories to paper Table-3 (L=[2,4,3], XXS expand=2)#20
Open
runwangdl wants to merge 2 commits into
Open
feat(mobilevit): align factories to paper Table-3 (L=[2,4,3], XXS expand=2)#20runwangdl wants to merge 2 commits into
runwangdl wants to merge 2 commits into
Conversation
…and=2) The existing MobileViT factory functions left `num_transformer_blocks` at its default of 2 for every stage and used the InvertedResidual default expand_ratio of 4 for all variants. Per the MobileViT paper (Mehta & Rastegari, ICLR 2022, Table 3 / §3.3) all three variants use L = [2, 4, 3] transformer layers per MobileViT block, and XXS uses an MV2 expansion factor of 2 (vs. 4 for XS/S). This commit: - Adds `transformer_depths` and `mv2_expand_ratio` keyword arguments to MobileViT.__init__, threading them through to each MobileViTBlock and InvertedResidual. - Updates `mobile_vit_xxs`, `mobile_vit_xs`, `mobile_vit_s` factories to pass the paper-specified values. Param-count check (1×3×256×256 input, 1000 classes): XXS: 0.93 M -> 1.04 M (paper ~1.3 M) XS: ---- -> 2.07 M (paper ~2.3 M) S: ---- -> 5.20 M (paper ~5.6 M) Remaining gap (~0.2–0.4 M per variant) comes from this deploy version's implementation choices (no dropout, separate bias-less Q/K/V projections instead of a single bias-ful combined QKV linear), not from architectural deviation.
Pre-commit hook in pulp-platform/Onnx4Deeploy CI runs psf/black 24.1.1 with --line-length=100. The six new InvertedResidual(...) call sites with expand_ratio=mv2_expand_ratio exceeded 100 chars; black wants them broken across lines. No semantic change.
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.
Summary
Brings the MobileViT factory functions in line with the MobileViT paper (Mehta & Rastegari, ICLR 2022) Table 3 / §3.3:
num_transformer_blocksper stage is now L = [2, 4, 3] for every variant. Previously every MobileViT block used the default of2, silently dropping ~3 transformer layers vs. the paper.4. Previously every variant used 4.Changes
onnx4deeploy/models/pytorch_models/mobilevit/mobilevit.py:MobileViT.__init__:transformer_depths: list = [2, 4, 3]mv2_expand_ratio: int = 4MobileViTBlock(num_transformer_blocks=) and eachInvertedResidual(expand_ratio=).mobile_vit_xxs/mobile_vit_xs/mobile_vit_sfactories to passtransformer_depths=[2, 4, 3]and the per-variantmv2_expand_ratio.Parameter count check
1 × 3 × 256 × 256 input, 1000 classes:
Remaining ~0.2–0.4 M gap per variant comes from this deploy version implementation choices (no dropout; separate bias-less Q / K / V linears instead of a single combined QKV linear with bias), not from architectural deviation from Table 3.