[FIX] allow Accelerator
to prepare models in eval mode for XPU&CPU
#2426
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.
Problem
When trying to run the
nlp_example.py
on Intel GPUs and CPUs, theprepare
function in the following code will complain with the following:This is a bug because the
ipex.optimize
function expects the model to be in training mode, otherwise, it will assume that the user is doing inference as shown in this line.Another thing I noticed is that the dtype passed to
ipex.optimize()
isfp32
, butipex.optimize()
expects the dtype to be eitherbf16
orfp16
and the default value is None as stated here. So if nomixed_precision
is used for training (currently only bf16 is supported), the dtype should keep the same with the default None value.What does this PR do?
Fix the bug in
_prepare_ipex
and improve the dtype passed toipex.optimize()
ortorch.xpu.optimize()
. With this fix, the example code can now run on CPU and XPU both in single and distributed modes.Who can review?
@muellerzr or @sywangyi