зеркало из https://github.com/microsoft/DeepSpeed.git
307 строки
5.7 KiB
Python
307 строки
5.7 KiB
Python
# Copyright (c) Microsoft Corporation.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# DeepSpeed Team
|
|
|
|
import abc
|
|
from abc import ABC
|
|
|
|
|
|
class DeepSpeedAccelerator(ABC):
|
|
|
|
def __init__(self):
|
|
self._name = None
|
|
self._communication_backend_name = None
|
|
self._compile_backend = None
|
|
|
|
@abc.abstractmethod
|
|
def is_synchronized_device(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def use_host_timers(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def resolves_data_dependency(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def handles_memory_backpressure(self):
|
|
...
|
|
|
|
# Device APIs
|
|
@abc.abstractmethod
|
|
def device_name(self, device_index):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def device(self, device_index):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def set_device(self, device_index):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def current_device(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def current_device_name(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def device_count(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def synchronize(self, device_index=None):
|
|
...
|
|
|
|
# RNG APIs
|
|
@abc.abstractmethod
|
|
def random(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def set_rng_state(self, new_state, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def get_rng_state(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def manual_seed(self, seed):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def manual_seed_all(self, seed):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def initial_seed(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def default_generator(self, device_index):
|
|
...
|
|
|
|
# Streams/Events
|
|
@property
|
|
@abc.abstractmethod
|
|
def Stream(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def stream(self, stream):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def current_stream(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def default_stream(self, device_index=None):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def Event(self):
|
|
...
|
|
|
|
# Memory management
|
|
@abc.abstractmethod
|
|
def empty_cache(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def memory_allocated(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def max_memory_allocated(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def reset_max_memory_allocated(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def memory_cached(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def max_memory_cached(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def reset_max_memory_cached(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def memory_stats(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def reset_peak_memory_stats(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def memory_reserved(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def max_memory_reserved(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def total_memory(self, device_index=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def available_memory(self, device_index=None):
|
|
...
|
|
|
|
# Data types
|
|
@abc.abstractmethod
|
|
def is_bf16_supported(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def is_fp16_supported(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def supported_dtypes(self):
|
|
...
|
|
|
|
# Misc
|
|
@abc.abstractmethod
|
|
def amp(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def is_available(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def range_push(self, msg):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def range_pop(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def lazy_call(self, callback):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def communication_backend_name(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def is_triton_supported(self):
|
|
...
|
|
|
|
# Graph operations
|
|
@abc.abstractmethod
|
|
def create_graph(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def capture_to_graph(self, graph, pool=None, stream=None):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def replay_graph(self, graph):
|
|
...
|
|
|
|
# Tensor operations
|
|
@property
|
|
@abc.abstractmethod
|
|
def BFloat16Tensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def ByteTensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def DoubleTensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def FloatTensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def HalfTensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def IntTensor(self):
|
|
...
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def LongTensor(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def pin_memory(self, tensor, align_bytes=1):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def is_pinned(self, tensor):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def on_accelerator(self, tensor):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def op_builder_dir(self):
|
|
...
|
|
|
|
# create an instance of op builder, specified by class_name
|
|
@abc.abstractmethod
|
|
def create_op_builder(self, class_name):
|
|
...
|
|
|
|
# return an op builder class, specified by class_name
|
|
@abc.abstractmethod
|
|
def get_op_builder(self, class_name):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def build_extension(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def export_envs(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def visible_devices_envs(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def set_visible_devices_envs(self, current_env, local_accelerator_ids):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def get_compile_backend(self):
|
|
...
|
|
|
|
@abc.abstractmethod
|
|
def set_compile_backend(self, backend):
|
|
...
|