Skip to content
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

MINCUT for memory encoder, Int8 TransposeConv for mask decoder #10

Merged
merged 10 commits into from
Feb 24, 2025

Conversation

kyakuno
Copy link

@kyakuno kyakuno commented Feb 3, 2025

  • Memory Encodeにおいて、nn.LayerNormを使用することで、MINCUTに対応
  • Mask Decoderにおいて、TransposeConvにAnnotationを適用することで、Int8演算に対応
  • Mask Decoderにおいて、geluをInt8に固定
  • Memory Attentionにおいて、outputをInt8に固定

Memory Encoderにおいて、MINCUTのパーティショニングでエラーが発生している問題を解消します。

独自のLayerNorm2Dの実装の、Residual Blockの分岐で、NHWCとNCHWが衝突しているのが原因であるため、
公式のnn.layernormに置き換えることで問題を回避します。
独自実装のウエイトをnn.layrernormに登録する必要があるため、checkpointの読み込み時に、load_weights_from_old_modelを呼び出します。

これにより、Addのepsilonが量子化されて0になる問題も回避することが可能です。
MemoryEncoderとMaskDecoderのLayerNormで0加算とsqrtでinfが発生する問題を解消します。

公式のnn.layernormに置き換えずに、NHWC変換後に独自のLayerNormを呼び出す方法でも回避可能です。
その場合、ai-edge-torch 0.2.0だと、ai_edge_torch/convert/fx_passes/optimize_layout_transposes_pass/pass_body.pyのinsert_dq_t_qのself.get_paired_q_dq_ops(input_q.target)をutils.get_paired_q_dq_ops(input_q.target)に修正が必要です。

@kyakuno kyakuno changed the title MINCUT support for memory encoder MINCUT for memory encoder, Int8 TransposeConv for mask decoder Feb 8, 2025
@kyakuno
Copy link
Author

kyakuno commented Feb 9, 2025

nn.layernormはlast dimmensionを縮退するため、NHWCに変換して適用します。
pytorch/pytorch#71465

@kyakuno kyakuno merged commit 489ac97 into tflite_int8 Feb 24, 2025
@kyakuno
Copy link
Author

kyakuno commented Feb 24, 2025

#9 にマージした。

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.

1 participant