(device)
| 1183 | |
| 1184 | # Utils for custom and alternative accelerator devices |
| 1185 | def _is_torch_fp16_available(device): |
| 1186 | if not is_torch_available(): |
| 1187 | return False |
| 1188 | |
| 1189 | import torch |
| 1190 | |
| 1191 | device = torch.device(device) |
| 1192 | |
| 1193 | try: |
| 1194 | x = torch.zeros((2, 2), dtype=torch.float16).to(device) |
| 1195 | _ = torch.mul(x, x) |
| 1196 | return True |
| 1197 | |
| 1198 | except Exception as e: |
| 1199 | if device.type == "cuda": |
| 1200 | raise ValueError( |
| 1201 | f"You have passed a device of type 'cuda' which should work with 'fp16', but 'cuda' does not seem to be correctly installed on your machine: {e}" |
| 1202 | ) |
| 1203 | |
| 1204 | return False |
| 1205 | |
| 1206 | |
| 1207 | def _is_torch_fp64_available(device): |
no test coverage detected
searching dependent graphs…