Skip to content

Add Intel's GPU / XPU support to TIMM's validation script #2138

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@
except ImportError:
has_apex = False

try:
import intel_extension_for_pytorch as ipex
has_ipex = True
except ImportError:
has_ipex = False

has_native_amp = False
try:
if getattr(torch.cuda.amp, 'autocast') is not None:
if getattr(torch.cuda.amp, 'autocast') is not None or getattr(torch.xpu.amp, 'autocast') is not None:
has_native_amp = True
except AttributeError:
pass
Expand Down Expand Up @@ -170,6 +176,9 @@ def validate(args):
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.benchmark = True

if args.device == 'xpu':
assert has_ipex, 'Please install Intel-extension-for-pytorch to enable XPU'

device = torch.device(args.device)

# resolve AMP arguments based on PyTorch / Apex availability
Expand All @@ -182,7 +191,7 @@ def validate(args):
use_amp = 'apex'
_logger.info('Validating in mixed precision with NVIDIA APEX AMP.')
else:
assert has_native_amp, 'Please update PyTorch to a version with native AMP (or use APEX).'
assert has_native_amp, 'Please update PyTorch to a version with native AMP (or use APEX / IPEX).'
assert args.amp_dtype in ('float16', 'bfloat16')
use_amp = 'native'
amp_dtype = torch.bfloat16 if args.amp_dtype == 'bfloat16' else torch.float16
Expand Down