AITemplate icon indicating copy to clipboard operation
AITemplate copied to clipboard

Fix gap in ads model BF16

Open wushirong opened this issue 1 year ago • 2 comments

Summary: Now we can set LowerPrecision=BF16 during ads publish pipeline. However, this setting won't change the packaged sample_input's dtype, thus AIT lower pipeline would hit this error during lowering:

RuntimeError: AITModel run failed with input spec: [10, 3968]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 64]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 64]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 128]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 64]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 96]:c10::BFloat16, [10, 64]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 120]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 72]:c10::BFloat16, [10, 2069]:c10::BFloat16, [10, 5252]:c10::BFloat16,

Because the sample input used by AIT is still fp16. Adding input and submod dtype conversion in pipeline to resolve this issue. *We cannot add the dtype conversion earlier in pipeline, because this would affect run_on_gpu part of model, which may contain op that doesn't suport BF16.

**TO use BF16 input, AIT lowering setting need to be set as: (input) precision: LowerPrecision.BF16 output_precision: LowerPrecision.FP16 This setting makes sure the connections between any run_on_acc and run_on_gpu graph is smooth. Otherwise a run_on_gpu graph follow after run_on_acc may throw error due to unable to process BF16 tensors.

Differential Revision: D45298122

wushirong avatar May 01 '23 17:05 wushirong

This pull request was exported from Phabricator. Differential Revision: D45298122

facebook-github-bot avatar May 01 '23 17:05 facebook-github-bot

Hi @wushirong!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Aug 22 '23 07:08 facebook-github-bot