8000 Enable bf16 autocast on Intel XPU devices (Arc) by TomTheHand · Pull Request #31 · volotat/mini-AGI · GitHub
[go: up one dir, main page]

Skip to content

Enable bf16 autocast on Intel XPU devices (Arc) - #31

Open
TomTheHand wants to merge 1 commit into
volotat:mainfrom
TomTheHand:feat/intel-arc-xpu
Open

TomTheHand wants to merge 1 commit into
volotat:mainfrom
TomTheHand:feat/intel-arc-xpu

Conversation

@TomTheHand
Copy link
Copy Markdown

Summary

Treat xpu as a bf16-native accelerator so the configured precision actually applies on Intel Arc:

  • gpu_bf16_native() returns True for XPU (Intel XMX computes bf16 in hardware; validated on Arc Pro B60).
  • autocast_on() treats xpu like cuda: bf16/fp16 autocast is used unless fp32 was explicitly selected.
  • _gpu_info() returns None for XPU, so CUDA/ROCm property queries and the VRAM-based fp32 fallback can never consult a colocated different-vendor GPU. This matters even with MINAGI_GPU_BF16=0: the override only disables the native-bf16 predicate, and without the guard the CUDA memory check would otherwise decide XPU policy.

MINAGI_GPU_BF16=1|0 still overrides, and CUDA/ROCm/CPU behavior is unchanged.

Why

On a Battlemage Arc (B60), torch.xpu.is_bf16_supported() reports False (a known capability-query gap that fails closed) even though the hardware computes bf16 fine - measured 7.4x matmul speedup fp32→bf16 on this card. Trusting that flag leaves Arc in fp32 for no benefit. We measured before switching, per the same discipline the module already applies to RDNA2.

Tests

  • tests/test_precision.py: CPU/mock coverage for device-type forms, dtype selection, autocast dispatch, env overrides, and unchanged CUDA/ROCm/CPU policy (5 tests).
  • tests/test_precision_xpu.py: opt-in (MINAGI_TEST_XPU=1) tiny-tensor bf16 forward/backward + SGD update on real XPU - no checkpoints, no training data.
python -m unittest discover -s tests -v          # OK (skipped=1)
MINAGI_TEST_XPU=1 python -m unittest discover -s tests -v
# XPU smoke: torch=2.14.1+xpu; device=Intel(R) Arc(TM) Pro B60 Graphics;
#   output=torch.bfloat16; finite gradients and SGD update OK   -- OK

Hardware validation covers this B60 only; no cross-vendor or performance claims beyond the measurement above.

Treat XPU as a bf16-native accelerator: autocast follows the configured
dtype instead of silently staying fp32, and XPU never consults the
CUDA/ROCm capability queries (a colocated NVIDIA card must not decide
Intel precision policy, including when MINAGI_GPU_BF16=0 disables the
native-bf16 predicate).

MINAGI_GPU_BF16=1/0 still overrides. Validated on Arc Pro B60 with
torch 2.14.1+xpu: bf16 forward/backward and an SGD update run and stay
finite. Adds CPU regression tests and an opt-in MINAGI_TEST_XPU=1
hardware smoke test.
@TomTheHand
Copy link
Copy Markdown
Author

If it's not obvious enough, the above was written by AI 😅 Sorry. With that said, mini-AGI nearly runs on Intel Arc GPUs out of the box, and the attached changes seal the deal.

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

0