Return default precision that is supported by the hardware: either `bf16` or `16`. Args: training: `-mixed` or `-true` version of the precision to use Returns: default precision that is suitable for the task and is supported by the hardware
(training: bool)
| 340 | |
| 341 | |
| 342 | def get_default_supported_precision(training: bool) -> str: |
| 343 | """Return default precision that is supported by the hardware: either `bf16` or `16`. |
| 344 | |
| 345 | Args: |
| 346 | training: `-mixed` or `-true` version of the precision to use |
| 347 | |
| 348 | Returns: |
| 349 | default precision that is suitable for the task and is supported by the hardware |
| 350 | """ |
| 351 | from lightning.fabric.accelerators import MPSAccelerator |
| 352 | |
| 353 | if MPSAccelerator.is_available() or ( |
| 354 | torch.cuda.is_available() and not torch.cuda.is_bf16_supported() |
| 355 | ): |
| 356 | return '16-mixed' if training else '16-true' |
| 357 | return 'bf16-mixed' if training else 'bf16-true' |
| 358 | |
| 359 | |
| 360 | def load_checkpoint( |