repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/partition_parameters.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import math import os import types from typing import Callable, Iterable from enum import Enum import functools import itertools from typing import List import logging import torch from torch import Tensor from deepspeed imp...
87,015
44.062662
182
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/offload_config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from pydantic import Field, validator from enum import Enum from pathlib import Path from deepspeed.runtime.config_utils import DeepSpeedConfigModel, pp_int class OffloadDeviceEnum(str, Enum): """ Enum for valid offloa...
2,931
29.863158
80
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/stage3.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import sys import gc import collections from typing import Deque, Dict, Tuple from deepspeed import comm as dist from deepspeed.utils import groups from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors f...
118,239
45.241689
219
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os from typing import List import torch from deepspeed import comm as dist from deepspeed.utils import logger from deepspeed.ops.adam import DeepSpeedCPUAdam from deepspeed.ops.adagrad import DeepSpeedCPUAdagrad from...
3,033
33.477273
115
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/tiling.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import deepspeed from deepspeed.runtime.utils import partition_uniform as partition def split_tensor_along_last_dim(tensor, partitions, contiguous_split_chunks=False): """Split a tensor along its last dime...
11,727
38.488215
115
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/partitioned_param_coordinator.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from dataclasses import dataclass import collections from collections import UserDict from typing import Deque, Set from deepspeed import comm as dist from deepspeed.utils.logging import logger from deepspeed.runtime.zero.o...
25,138
48.978131
150
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/linear.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team #Linear Module to use with ZeRO Stage 3 to allow for parameter memory release #after the module execution during forward #Instead of saving variables using save_for_backward, we save variable ids #Allowing us to retrieve the...
7,403
41.068182
162
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/partitioned_param_profiler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from dataclasses import dataclass from deepspeed.utils import log_dist class PartitionedParameterProfiler(object): @dataclass class EventCounter: name: str count: int num_elem: int ...
1,801
27.15625
122
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from pydantic import Field, validator import sys from typing import Optional from enum import Enum from deepspeed.runtime.config_utils import get_scalar_param, pp_int, DeepSpeedConfigModel from deepspeed.utils import logger ...
10,692
36.651408
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .partition_parameters import ZeroParamType from .partition_parameters import ZeroParamStatus from .partition_parameters import Init from .partition_parameters import GatheredParameters from .partition_parameters import ...
452
27.3125
61
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/mics.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import sys from typing import List import deepspeed import torch from deepspeed import comm as dist from deepspeed....
22,259
46.061311
138
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/checkpoint_engine/checkpoint_engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os class CheckpointEngine(object): # init checkpoint engine for save/load def __init__(self, config_params=None): pass def create(self, tag): # create checkpoint on give tag for save/lo...
653
20.096774
61
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/checkpoint_engine/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team '''Copyright The Microsoft DeepSpeed Team'''
140
22.5
44
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/checkpoint_engine/torch_checkpoint_engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed.utils import logger, log_dist from deepspeed.runtime.checkpoint_engine.checkpoint_engine import \ CheckpointEngine class TorchCheckpointEngine(CheckpointEngine): def __init__(self, conf...
1,060
29.314286
78
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/checkpoint_engine/nebula_checkpoint_engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import torch import torch_nebula from deepspeed.runtime.checkpoint_engine.checkpoint_engine import \ CheckpointEngine from deepspeed.utils import logger, log_dist from deepspeed.nebula.constants import * def...
4,975
45.074074
150
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from types import MethodType import torch from deepspeed import comm as dist from deepspeed.utils import logger from deepspeed.utils.timer import ThroughputTimer from deepspeed.accelerator import get_accelerator from ..en...
56,886
42.49159
128
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/p2p.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import pickle import typing import torch from deepspeed import comm as dist # To query whether we have send/recv support from packaging.version import Version from deepspeed.git_version_info import torch_info from deepspee...
5,477
28.294118
98
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/topology.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed import comm as dist from collections import namedtuple from itertools import product as cartesian_product class ProcessTopology: """ Manages the mapping of n-dimensional Cartesian coordinates to linear ...
17,167
36.56674
116
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/module.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import glob import re as regex from functools import partial import torch import torch.nn as nn from deepspeed import comm as dist from deepspeed.utils import logger from .. import utils as ds_utils from ..acti...
27,190
42.998382
171
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .module import PipelineModule, LayerSpec, TiedLayerSpec from .topology import ProcessTopology
195
23.5
60
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/pipe/schedule.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from ..utils import call_to_str from abc import ABC, abstractmethod class PipeSchedule(ABC): """Directs the execution of a pipeline engine by generating sequences of :class:`PipeInstruction`. Schedules are ge...
15,546
30.408081
103
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/layer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed.utils import log_dist from deepspeed.utils import groups from .sharded_moe import MOELayer, TopKGate from .experts import Experts import typing class MoE(torch.nn.Module): """Initialize an...
6,082
47.664
151
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/mappings.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # The file has been adapted from the following Megatron-LM file: # https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/mpu/mappings.py # Git commit hash: 9dc3c42a84aa656f583703cf8b6b4f79f712b796 # We retain the followin...
3,529
31.990654
144
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/sharded_moe.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ The file has been adapted from two fairscale files: (1) https://github.com/facebookresearch/fairscale/blob/master/fairscale/nn/moe/moe_layer.py (2) https://github.com/facebookresearch/fairscale/blob/master/fairscale/nn/...
20,621
36.494545
151
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from typing import List, Tuple, Dict import torch from .layer import MoE def has_moe_layers(m): has_moe = False num_experts = 0 for _, module in m.named_modules(): if isinstance(module, MoE): ...
5,214
34.719178
98
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team '''Copyright The Microsoft DeepSpeed Team'''
140
22.5
44
py
DeepSpeed
DeepSpeed-master/deepspeed/moe/experts.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import copy class Experts(torch.nn.Module): def __init__(self, expert, num_local_experts=1, expert_group_name=None): super(Experts, self).__init__() self.deepspeed_experts = torch.nn.Modu...
1,223
33
111
py
DeepSpeed
DeepSpeed-master/deepspeed/launcher/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team PDSH_LAUNCHER = 'pdsh' PDSH_MAX_FAN_OUT = 1024 OPENMPI_LAUNCHER = 'openmpi' MPICH_LAUNCHER = 'mpich' IMPI_LAUNCHER = 'impi' SLURM_LAUNCHER = 'slurm' MVAPICH_LAUNCHER = 'mvapich' MVAPICH_TMP_HOSTFILE = '/tmp/deepspeed_mvapic...
375
21.117647
56
py
DeepSpeed
DeepSpeed-master/deepspeed/launcher/launch.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ DeepSpeed launcher, this is similar to torch's distributed.launch but supports additional features such as arbitrary gpu exclusion. deepspeed.launcher.launch is intended to be run on a single worker node and will spawn s...
14,654
40.16573
117
py
DeepSpeed
DeepSpeed-master/deepspeed/launcher/runner.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ DeepSpeed runner is the main front-end to launching multi-worker training jobs with DeepSpeed. By default this uses pdsh to parallel ssh into multiple worker nodes and launch all the necessary processes per rank for train...
24,150
40.567986
225
py
DeepSpeed
DeepSpeed-master/deepspeed/launcher/multinode_runner.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import sys import shutil import subprocess import warnings from shlex import split from abc import ABC, abstractmethod from deepspeed.accelerator import get_accelerator from ..utils import logger, get_numactl_cmd f...
16,568
36.150224
119
py
DeepSpeed
DeepSpeed-master/deepspeed/launcher/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team '''Copyright The Microsoft DeepSpeed Team'''
140
22.5
44
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/module_quantize.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch def quantize_transformer_layer(orig_layer_impl, model, megatron=False, preln=False): """ Quantize bert-style transformer layers with DeepSpeed's transformer layer Arguments: orig_layer_impl (to...
3,107
41.575342
120
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/load_checkpoint.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from torch import nn from deepspeed.model_implementations.transformers.ds_bloom import DeepSpeedBloomInference from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference from deepspeed.model_implem...
14,745
53.817844
134
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.utils import log_dist # helper function to map between DS policies and DS containers def policy_to_ds_container(**kwargs): from .containers import HFGPT2LayerPolicy, DS_GPT2Container from .containers...
1,762
37.326087
75
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/policy.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from abc import ABC, abstractmethod from deepspeed.utils.types import ActivationFuncType, NormType import torch from deepspeed.accelerator import get_accelerator transformer_param_names = ( 'attn_qkvw', \ 'a...
8,259
35.711111
155
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/auto_tp.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # Automatic Tensor Parallelism import re from torch import nn from .replace_policy import replace_policies class AutoTP(): def in_module_list(module, module_list): for item in module_list: if type...
5,353
41.832
144
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/layers.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed import comm as dist from torch import nn from torch.nn import functional as F from torch.nn.parameter import Parameter from deepspeed.accelerator import get_accelerator class LinearAllreduce(nn...
4,592
33.276119
116
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .replace_module import replace_transformer_layer, revert_transformer_layer, ReplaceWithTensorSlicing, GroupQuantizer, generic_injection from .module_quantize import quantize_transformer_layer from .replace_policy import...
444
39.454545
140
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/inject.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import copy import torch from deepspeed.ops.transformer import DeepSpeedTransformerLayer, DeepSpeedTransformerConfig def module_inject(layer_obj, model, config, micro_batch_size, max_seq_length, seed, preln, fp16=True): ...
4,719
40.769912
108
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/replace_module.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os from typing import Optional import torch import tqdm import deepspeed import deepspeed.ops.transformer as transformer_inference from deepspeed.ops.transformer.inference.diffusers_attention import DeepSpeedDiffusers...
43,185
47.144928
156
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/replace_policy.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .containers import HFGPT2LayerPolicy from .containers import HFBertLayerPolicy from .containers import BLOOMLayerPolicy from .containers import HFGPTJLayerPolicy from .containers import HFGPTNEOLayerPolicy from .contain...
989
34.357143
119
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/distil_bert.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from deepspeed.model_implementations.transformers.ds_bert import DeepSpeedBERTInference import torch from torch.nn.parameter import Parameter from ..policy import TransformerPolicy class DS_DistilBERTCo...
3,188
37.421687
88
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/bert.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from deepspeed.model_implementations.transformers.ds_bert import DeepSpeedBERTInference import torch from torch.nn.parameter import Parameter from ..policy import TransformerPolicy class DS_BERTContaine...
3,769
39.106383
87
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/base.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # Create a container object to save model-specific tensors using the policy file above. from abc import ABC import torch import deepspeed from deepspeed.ops.transformer.inference.config import DeepSpeedInferenceConfig from...
13,564
41.523511
126
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/llama.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features import HybridSplitQKVContainer, HybridGatedMLPContainer from deepspeed.utils.types import ActivationFuncType, NormType from deepspeed.model_implementations.transformers.ds_gpt import DeepSp...
6,180
38.621795
123
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/clip.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference import torch from torch.nn.parameter import Parameter from ..policy import TransformerPolicy class DS_CLIPContainer(...
2,822
37.148649
109
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/vae.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from ..policy import DSPolicy from ...model_implementations.diffusers.vae import DSVAE class VAEPolicy(DSPolicy): def __init__(self): super().__init__() try: import diffusers if...
1,163
30.459459
86
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/opt.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features import MetaTensorContainer, HybridSplitQKVContainer from deepspeed.model_implementations.transformers.ds_opt import DeepSpeedOPTInference import torch from torch.nn.parameter import Paramet...
6,905
41.89441
111
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/megatron_gpt.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features.megatron import MegatronContainer from deepspeed.model_implementations.transformers.ds_megatron_gpt import DeepSpeedMegatronGPTInference import torch from ..policy import TransformerPolicy ...
5,017
44.207207
121
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/gptneox.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features.meta_tensor import MetaTensorContainer from .features.hybrid_megatron import HybridMegatronContainer from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference im...
5,897
39.122449
117
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/gptneo.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features.meta_tensor import MetaTensorContainer from .features.split_qkv import HybridSplitQKVContainer from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference import t...
5,790
38.664384
114
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/unet.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from torch.nn.parameter import Parameter from ..policy import DSPolicy from ...model_implementations.diffusers.unet import DSUNet class UNetPolicy(DSPolicy): def __init__(self): super().__init__(...
1,732
30.509091
92
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/gptj.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features.meta_tensor import MetaTensorContainer from .features.split_qkv import HybridSplitQKVContainer from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference import t...
5,074
37.157895
112
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/megatron_gpt_moe.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .base_moe import * from .features.megatron import MegatronContainer from deepspeed.model_implementations.transformers.ds_megatron_gpt import DeepSpeedMegatronGPTInference import torch from .megatron_...
3,936
44.252874
117
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/gpt2.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from deepspeed.model_implementations.transformers.ds_gpt import DeepSpeedGPTInference from ..policy import TransformerPolicy class DS_GPT2Container(BaseTransformerContainer): def __init__(self, **k...
2,221
35.42623
98
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .bert import DS_BERTContainer, HFBertLayerPolicy from .bloom import DS_BloomContainer, BLOOMLayerPolicy, supported_models from .distil_bert import DS_DistilBERTContainer, HFDistilBertLayerPolicy from .gpt2 import DS_GPT...
893
43.7
80
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/base_moe.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # Create a container object to save model-specific tensors using the policy file above. from .base import * from deepspeed import comm as dist import deepspeed.ops.transformer as transformer_inference from deepspeed.accelera...
5,756
42.946565
126
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/bloom.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .base import * from .features.meta_tensor import MetaTensorContainer from .features.hybrid_engine import HybridEngineContainer from deepspeed.model_implementations.transformers.ds_bloom import DeepSpeedBloomInference fr...
5,615
42.2
118
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/hybrid_megatron.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from .hybrid_engine import HybridEngineContainer from .megatron import MegatronContainer class HybridMegatronContainer(MegatronContainer, HybridEngineContainer): def _align_qkv(self, x: torch.Tensor): ...
4,129
45.931818
158
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/meta_tensor.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from abc import ABC, abstractmethod from packaging import version as pkg_version import torch class MetaTensorContainer(ABC): """ NOTE: If you are using this feature with a container that also inherits from `Hy...
2,930
40.28169
109
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/split_qkv.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from abc import abstractmethod import torch from .hybrid_engine import HybridEngineContainer class HybridSplitQKVContainer(HybridEngineContainer): def set_attention(self, qkvw, qkvb, dense_w, dense_b): super(...
7,136
43.60625
98
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/megatron.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from abc import ABC class MegatronContainer(ABC): def __init__(self, **kwargs): super().__init__(**kwargs) self.megatron_v2 = self.policy.is_megatron_v2 def _align_qkv_transposed(self...
1,200
36.53125
111
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/gated_mlp.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from abc import abstractmethod from .hybrid_engine import HybridEngineContainer class HybridGatedMLPContainer(HybridEngineContainer): """ The HybridGatedMLPContainer supports models for which the first MLP layer ...
5,397
44.361345
116
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .gated_mlp import HybridGatedMLPContainer from .megatron import MegatronContainer from .meta_tensor import MetaTensorContainer from .split_qkv import HybridSplitQKVContainer
275
26.6
46
py
DeepSpeed
DeepSpeed-master/deepspeed/module_inject/containers/features/hybrid_engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from abc import ABC, abstractmethod from typing import List, Tuple import torch class HybridEngineContainer(ABC): """ This container identifies which methods need to be overridden in addition to the base conta...
8,374
38.319249
110
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/ccl.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team ''' Copyright 2021 The Microsoft DeepSpeed Team ''' import torch from deepspeed.accelerator import get_accelerator from .reduce_op import ReduceOp from .torch import TorchBackend def build_ccl_op(): builder = get_accel...
2,248
34.698413
101
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/torch.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed import utils from .utils import * from .backend import * from .comm import * import os DS_COMM_ALL_GATHER_OFF = False DS_COMM_REDUCE_SCATTER_OFF = False DS_COMM_BROADCAST_OFF = False DS_COMM_ALL_REDUCE_OFF =...
15,854
42.557692
119
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team NCCL_BACKEND = 'nccl' CCL_BACKEND = 'ccl' MPI_BACKEND = 'mpi' GLOO_BACKEND = 'gloo' SCCL_BACKEND = 'sccl' DEFAULT_AML_MASTER_PORT = "54965" DEFAULT_AML_NCCL_SOCKET_IFNAME = "^docker0,lo" ###################################...
1,276
24.039216
57
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/comm.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ DeepSpeed Communication Package: deepspeed.comm deepspeed.comm -- import and use deepspeed.ops.comm -- use torch.distributed directly if both this package and torch.distributed use the same NCCL ve...
28,373
36.983936
209
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import inspect from deepspeed.utils import get_caller_func def get_local_rank_from_launcher(): # DeepSpeed launcher will set it so get from there rank = os.environ.get('LOCAL_RANK') if rank is None:...
3,842
27.679104
176
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/reduce_op.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from enum import Enum class ReduceOp(Enum): SUM = 0 PRODUCT = 1 MIN = 2 MAX = 3 BAND = 4 BOR = 5 BXOR = 6 AVG = 7 UNUSED = 8
259
12.684211
38
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from pydantic import BaseModel from .constants import * class CommsConfig(BaseModel): class Config: validate_all = True validate_assignment = True use_enum_values = True extra = 'forbid...
855
24.176471
78
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/backend.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ DeepSpeed Communication Backend. In the future, directly use NCCL/MPI/Gloo/etc without requiring torch.distributed. Simply wrap torch.distributed for now. # Custom DS Backends -- Direct C/Ops - NCCL -- [EXPERIMENTAL] ...
1,416
28.520833
137
py
DeepSpeed
DeepSpeed-master/deepspeed/comm/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .utils import * from .comm import *
137
16.25
38
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/tensorboard.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .utils import check_tb_availability from .monitor import Monitor import os import deepspeed.comm as dist class TensorBoardMonitor(Monitor): def __init__(self, tensorboard_config): super().__init__(tensor...
2,227
38.087719
181
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team def check_tb_availability(): try: # torch.utils.tensorboard will fail if `tensorboard` is not available, # see their docs for more details: https://pytorch.org/docs/1.8.0/tensorboard.html import ...
754
29.2
138
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/csv_monitor.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .monitor import Monitor import os import deepspeed.comm as dist class csvMonitor(Monitor): def __init__(self, csv_config): super().__init__(csv_config) self.filenames = [] self.enabled = ...
2,907
41.764706
193
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from pydantic import root_validator from deepspeed.runtime.config_utils import DeepSpeedConfigModel def get_monitor_config(param_dict): monitor_dict = {key: param_dict.get(key, {}) for key in ("tensorboard", "wandb", "...
2,481
30.025
107
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/monitor.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Support different forms of monitoring such as wandb and tensorboard """ from abc import ABC, abstractmethod import deepspeed.comm as dist class Monitor(ABC): @abstractmethod def __init__(self, monitor_config):...
1,604
28.722222
80
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/wandb.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .utils import check_wandb_availability from .monitor import Monitor import deepspeed.comm as dist class WandbMonitor(Monitor): def __init__(self, wandb_config): super().__init__(wandb_config) che...
1,150
28.512821
80
py
DeepSpeed
DeepSpeed-master/deepspeed/monitor/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team '''Copyright The Microsoft DeepSpeed Team'''
140
22.5
44
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/elastic_agent.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from torch.distributed.elastic.agent.server.local_elastic_agent import LocalElasticAgent from typing import Any, Dict, Optional, Tuple from datetime import datetime from torch.distributed.elastic.agent.server.api import log,...
7,762
41.653846
105
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team ######################################### # Elasticity ######################################### ''' Elasticity Utility in DeepSpeed can be used to create highly elastic jobs compatible with a large number of GPUs. For elast...
2,454
28.939024
91
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch def is_torch_elastic_compatible(): ''' Helper to lookup torch version. Elastic training is introduced in 1.11.x ''' TORCH_MAJOR = int(torch.__version__.split('.')[0]) TORCH_MINO...
459
22
59
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import json from .constants import * class ElasticityError(Exception): """ Base exception for all elasticity related errors """ class ElasticityConfigError(ElasticityError): """ Elasticity configurati...
4,703
41.378378
115
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .elasticity import compute_elastic_config, elasticity_enabled, ensure_immutable_elastic_config from .utils import is_torch_elastic_compatible from .constants import ENABLED, ENABLED_DEFAULT, ELASTICITY if is_torch_elast...
383
33.909091
99
py
DeepSpeed
DeepSpeed-master/deepspeed/elasticity/elasticity.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import json import numpy as np import math from packaging import version as pkg_version from .config import ElasticityConfig, ElasticityConfigError, ElasticityError, \ ElasticityIncompatibleWorldSize from .con...
17,374
44.844327
119
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/timer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import time from numpy import mean from deepspeed.utils.logging import log_dist from deepspeed.accelerator import get_accelerator from deepspeed import comm as dist try: import psutil PSUTILS_INSTALLED = True excep...
9,477
34.766038
115
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/comms_logging.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import math from deepspeed.utils import log_dist def get_caller_func(frame=3): import sys return sys._getframe(frame).f_code.co_name def print_rank_0(message): import deepspeed.comm as dist if dist.get_ra...
8,024
42.61413
212
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/exceptions.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team class DeprecatedException(Exception): pass
144
15.111111
38
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/nvtx.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.accelerator import get_accelerator def instrument_w_nvtx(func): """decorator that causes an NVTX range to be recorded for the duration of the function call.""" def wrapped_fn(*args, **kwargs): ...
499
24
81
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/logging.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import functools import logging import sys import os log_levels = { "debug": logging.DEBUG, "info": logging.INFO, "warning": logging.WARNING, "error": logging.ERROR, "critical": logging.CRITICAL, } cla...
4,375
27.601307
127
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/mixed_precision_linkage.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import types from deepspeed.utils import get_full_hp_param, get_full_hp_grad, get_hp_fragment_mapping def link_hp_params(lp_param_list, flat_hp_partition, gradient_dict, offload_gradient_dict, use_offload, ...
2,041
46.488372
114
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/groups.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # The file has been adapted from https://github.com/NVIDIA/Megatron-LM and retains the following license from the original file # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache L...
19,762
39.664609
187
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/types.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from enum import IntEnum class ActivationFuncType(IntEnum): UNKNOWN = 0 GELU = 1 ReLU = 2 GATED_GELU = 3 GATED_SILU = 4 GATED_ACTIVATION_TYPES = [ ActivationFuncType.GATED_GELU, ActivationFunc...
434
14.535714
38
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/init_on_device.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from typing import Callable from torch import Tensor from packaging import version as pkg_version class OnDevice(object): """ Create modules/tensors w. specific devices and dtypes. Examples: Creat...
3,004
35.646341
112
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/numa.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # return a list of list for cores to numa mapping # [ # [ cores for numa 0 ] # [ cores belong to numa 1 ] # ... # ] import distutils import os import psutil import subprocess # return a list of list for cores t...
5,162
33.651007
111
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/tensor_fragment.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from dataclasses import dataclass from deepspeed import comm as dist from typing import Dict @dataclass class fragment_address: numel: int start: int @dataclass class tensor_fragment: lp_fragment...
8,027
29.876923
117
py
DeepSpeed
DeepSpeed-master/deepspeed/utils/zero_to_fp32.py
#!/usr/bin/env python # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets # copied into the top level checkpoint dir, so the user can easily do the conversion at any point ...
23,610
39.778929
197
py