| 15 | |
| 16 | |
| 17 | class NPU_Accelerator(DeepSpeedAccelerator): |
| 18 | |
| 19 | def __init__(self): |
| 20 | super().__init__() |
| 21 | self._name = 'npu' |
| 22 | self._communication_backend_name = 'hccl' |
| 23 | self._compile_backend = "inductor" |
| 24 | # dict that holds class name <--> class type mapping i.e. |
| 25 | # 'AsyncIOBuilder': <class 'op_builder.async_io.AsyncIOBuilder'> |
| 26 | # this dict will be filled at init stage |
| 27 | self.class_dict = None |
| 28 | |
| 29 | def is_synchronized_device(self): |
| 30 | return False |
| 31 | |
| 32 | def use_host_timers(self): |
| 33 | return self.is_synchronized_device() |
| 34 | |
| 35 | def resolves_data_dependency(self): |
| 36 | return self.is_synchronized_device() |
| 37 | |
| 38 | def handles_memory_backpressure(self): |
| 39 | return self.is_synchronized_device() |
| 40 | |
| 41 | # Device APIs |
| 42 | def device_name(self, device_index=None): |
| 43 | if device_index is None: |
| 44 | return 'npu' |
| 45 | return 'npu:{}'.format(device_index) |
| 46 | |
| 47 | def device(self, device_index=None): |
| 48 | return torch.device('npu', device_index) |
| 49 | |
| 50 | def set_device(self, device_index): |
| 51 | torch.npu.set_device(device_index) |
| 52 | |
| 53 | def current_device(self): |
| 54 | return torch.npu.current_device() |
| 55 | |
| 56 | def current_device_name(self): |
| 57 | return 'npu:{}'.format(torch.npu.current_device()) |
| 58 | |
| 59 | def device_count(self): |
| 60 | return torch.npu.device_count() |
| 61 | |
| 62 | def synchronize(self, device_index=None): |
| 63 | return torch.npu.synchronize(device_index) |
| 64 | |
| 65 | # RNG APIs |
| 66 | def random(self): |
| 67 | return torch.random |
| 68 | |
| 69 | def set_rng_state(self, new_state, device_index=None): |
| 70 | if device_index is None: |
| 71 | return torch.npu.set_rng_state(new_state) |
| 72 | |
| 73 | return torch.npu.set_rng_state(new_state, device_index) |
| 74 |
no outgoing calls
no test coverage detected
searching dependent graphs…