DeepSpeed
Зеркало из https://github.com/microsoft/DeepSpeed
306 строк · 5.7 Кб
1# Copyright (c) Microsoft Corporation.
2# SPDX-License-Identifier: Apache-2.0
3
4# DeepSpeed Team
5
6import abc
7from abc import ABC
8
9
10class DeepSpeedAccelerator(ABC):
11
12def __init__(self):
13self._name = None
14self._communication_backend_name = None
15self._compile_backend = None
16
17@abc.abstractmethod
18def is_synchronized_device(self):
19...
20
21@abc.abstractmethod
22def use_host_timers(self):
23...
24
25@abc.abstractmethod
26def resolves_data_dependency(self):
27...
28
29@abc.abstractmethod
30def handles_memory_backpressure(self):
31...
32
33# Device APIs
34@abc.abstractmethod
35def device_name(self, device_index):
36...
37
38@abc.abstractmethod
39def device(self, device_index):
40...
41
42@abc.abstractmethod
43def set_device(self, device_index):
44...
45
46@abc.abstractmethod
47def current_device(self):
48...
49
50@abc.abstractmethod
51def current_device_name(self):
52...
53
54@abc.abstractmethod
55def device_count(self):
56...
57
58@abc.abstractmethod
59def synchronize(self, device_index=None):
60...
61
62# RNG APIs
63@abc.abstractmethod
64def random(self):
65...
66
67@abc.abstractmethod
68def set_rng_state(self, new_state, device_index=None):
69...
70
71@abc.abstractmethod
72def get_rng_state(self, device_index=None):
73...
74
75@abc.abstractmethod
76def manual_seed(self, seed):
77...
78
79@abc.abstractmethod
80def manual_seed_all(self, seed):
81...
82
83@abc.abstractmethod
84def initial_seed(self):
85...
86
87@abc.abstractmethod
88def default_generator(self, device_index):
89...
90
91# Streams/Events
92@property
93@abc.abstractmethod
94def Stream(self):
95...
96
97@abc.abstractmethod
98def stream(self, stream):
99...
100
101@abc.abstractmethod
102def current_stream(self, device_index=None):
103...
104
105@abc.abstractmethod
106def default_stream(self, device_index=None):
107...
108
109@property
110@abc.abstractmethod
111def Event(self):
112...
113
114# Memory management
115@abc.abstractmethod
116def empty_cache(self):
117...
118
119@abc.abstractmethod
120def memory_allocated(self, device_index=None):
121...
122
123@abc.abstractmethod
124def max_memory_allocated(self, device_index=None):
125...
126
127@abc.abstractmethod
128def reset_max_memory_allocated(self, device_index=None):
129...
130
131@abc.abstractmethod
132def memory_cached(self, device_index=None):
133...
134
135@abc.abstractmethod
136def max_memory_cached(self, device_index=None):
137...
138
139@abc.abstractmethod
140def reset_max_memory_cached(self, device_index=None):
141...
142
143@abc.abstractmethod
144def memory_stats(self, device_index=None):
145...
146
147@abc.abstractmethod
148def reset_peak_memory_stats(self, device_index=None):
149...
150
151@abc.abstractmethod
152def memory_reserved(self, device_index=None):
153...
154
155@abc.abstractmethod
156def max_memory_reserved(self, device_index=None):
157...
158
159@abc.abstractmethod
160def total_memory(self, device_index=None):
161...
162
163@abc.abstractmethod
164def available_memory(self, device_index=None):
165...
166
167# Data types
168@abc.abstractmethod
169def is_bf16_supported(self):
170...
171
172@abc.abstractmethod
173def is_fp16_supported(self):
174...
175
176@abc.abstractmethod
177def supported_dtypes(self):
178...
179
180# Misc
181@abc.abstractmethod
182def amp(self):
183...
184
185@abc.abstractmethod
186def is_available(self):
187...
188
189@abc.abstractmethod
190def range_push(self, msg):
191...
192
193@abc.abstractmethod
194def range_pop(self):
195...
196
197@abc.abstractmethod
198def lazy_call(self, callback):
199...
200
201@abc.abstractmethod
202def communication_backend_name(self):
203...
204
205@abc.abstractmethod
206def is_triton_supported(self):
207...
208
209# Graph operations
210@abc.abstractmethod
211def create_graph(self):
212...
213
214@abc.abstractmethod
215def capture_to_graph(self, graph, pool=None, stream=None):
216...
217
218@abc.abstractmethod
219def replay_graph(self, graph):
220...
221
222# Tensor operations
223@property
224@abc.abstractmethod
225def BFloat16Tensor(self):
226...
227
228@property
229@abc.abstractmethod
230def ByteTensor(self):
231...
232
233@property
234@abc.abstractmethod
235def DoubleTensor(self):
236...
237
238@property
239@abc.abstractmethod
240def FloatTensor(self):
241...
242
243@property
244@abc.abstractmethod
245def HalfTensor(self):
246...
247
248@property
249@abc.abstractmethod
250def IntTensor(self):
251...
252
253@property
254@abc.abstractmethod
255def LongTensor(self):
256...
257
258@abc.abstractmethod
259def pin_memory(self, tensor, align_bytes=1):
260...
261
262@abc.abstractmethod
263def is_pinned(self, tensor):
264...
265
266@abc.abstractmethod
267def on_accelerator(self, tensor):
268...
269
270@abc.abstractmethod
271def op_builder_dir(self):
272...
273
274# create an instance of op builder, specified by class_name
275@abc.abstractmethod
276def create_op_builder(self, class_name):
277...
278
279# return an op builder class, specified by class_name
280@abc.abstractmethod
281def get_op_builder(self, class_name):
282...
283
284@abc.abstractmethod
285def build_extension(self):
286...
287
288@abc.abstractmethod
289def export_envs(self):
290...
291
292@abc.abstractmethod
293def visible_devices_envs(self):
294...
295
296@abc.abstractmethod
297def set_visible_devices_envs(self, current_env, local_accelerator_ids):
298...
299
300@abc.abstractmethod
301def get_compile_backend(self):
302...
303
304@abc.abstractmethod
305def set_compile_backend(self, backend):
306...
307