Skip to content

Commit a233651

Browse files
committed
add check with sysctl for bf16 support
1 parent 2cea8d0 commit a233651

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

vllm/platforms/cpu.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ class CpuPlatform(Platform):
7575
def supported_dtypes(self) -> list[torch.dtype]:
7676
if self.get_cpu_architecture() == CpuArchEnum.POWERPC:
7777
return [torch.bfloat16, torch.float32]
78-
elif sys.platform.startswith(
79-
"darwin") and self.get_cpu_architecture() == CpuArchEnum.ARM:
80-
# TODO: change this condition to check if the platform support bf16
81-
# instead of checking the OS.
82-
return [torch.bfloat16, torch.float16, torch.float32]
78+
elif (self.get_cpu_architecture() == CpuArchEnum.ARM
79+
and sys.platform.startswith("darwin")):
80+
if (subprocess.check_output(
81+
["sysctl", "-n", "-e", "hw.optional.arm.FEAT_BF16"]
82+
).strip() == b"1"):
83+
return [torch.bfloat16, torch.float16, torch.float32]
84+
return [torch.float16, torch.float32]
8385
# x86/aarch64 CPU has supported both bf16 and fp16 natively.
8486
return [torch.bfloat16, torch.float16, torch.float32]
8587

0 commit comments

Comments
 (0)