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
SGA
SGA-main/py/SGA/webapp/__init__.py
0
0
0
py
SGA
SGA-main/py/SGA/webapp/urls.py
#!/usr/bin/env python """URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='hom...
1,221
32.027027
80
py
SGA
SGA-main/py/SGA/webapp/sample/views.py
#!/usr/bin/env python """Holds the functions that send http responses to the browser, including rendering the html pages index.html, explore.html, and sample.html, or sending a download file. All logic that must be done before the browser renders the html occurs here, including sessions, serialization, querying datab...
9,790
32.646048
90
py
SGA
SGA-main/py/SGA/webapp/sample/app.py
from django.apps import AppConfig from SGA.webapp.sample.templatetags import * class SgaApp(AppConfig): name = 'sample'
126
17.142857
44
py
SGA
SGA-main/py/SGA/webapp/sample/models.py
#!/usr/bin/env python """Each model will be written as a class here, instantiated and populated by load.py, with each model stored as a table in the database and the fields stored as columns. """ import os import numpy as np from django.db.models import (Model, IntegerField, CharField, FloatField, IPAddressField, ...
9,751
30.057325
140
py
SGA
SGA-main/py/SGA/webapp/sample/__init__.py
0
0
0
py
SGA
SGA-main/py/SGA/webapp/sample/filters.py
#!/usr/bin/env python """Custom filters for the Sample model, which work by selecting Sample objects in the database based on meeting the desired criteria. """ import django_filters from SGA.webapp.sample.models import Sample class SampleFilter(django_filters.FilterSet): """Custom filter for the Sample model. F...
2,730
41.671875
94
py
SGA
SGA-main/py/SGA/webapp/sample/templatetags/my_templatetag.py
""" This document contains our custom template tags created for use in the legacyhalos html documents. Each function must be registered before use, then loaded using {% load my_templatetag %} within the html document. These functions can then be called from within the html code. """ import os import astropy.io.fits im...
5,503
29.241758
139
py
SGA
SGA-main/py/SGA/webapp/sample/templatetags/__init__.py
0
0
0
py
SGA
SGA-main/py/SGA/sandbox/obsolete.py
def mgefit_multiband(galaxy, galaxydir, data, debug=False, nowrite=False, noellipsefit=True, verbose=False): """MGE-fit the multiband data. See http://www-astro.physics.ox.ac.uk/~mxc/software/#mge """ from mge.find_galaxy import find_galaxy from mge.sectors_photometry import s...
2,604
36.753623
103
py
SGA
SGA-main/py/SGA/sandbox/lslga-manifest.py
#!/usr/bin/env python def main(): import os import numpy as np import fitsio import astropy.table lslgadir = '/Users/ioannis/research/projects/LSLGA/sample/v2.0' lslgafile = os.path.join(lslgadir, 'LSLGA-v2.0.fits') lslga = astropy.table.Table.read(lslgafile) print('Read {} galaxi...
1,042
30.606061
84
py
SGA
SGA-main/py/SGA/sandbox/groups.py
""" LSLGA.groups ============ Code to do construct various group catalogs. """ from __future__ import absolute_import, division, print_function import os import time import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set(style='ticks', font_scale=1.4, palette='Set2') PIXSCALE = 0.262 def...
4,895
36.661538
105
py
DeepSpeed
DeepSpeed-master/setup.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ DeepSpeed library To build wheel on Windows: 1. Install pytorch, such as pytorch 1.12 + cuda 11.6. 2. Install visual cpp build tool. 3. Include cuda toolkit. 4. Launch cmd console with Administrator privilege for creatin...
11,499
36.216828
139
py
DeepSpeed
DeepSpeed-master/deepspeed/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from datetime import timedelta ############################################# # Torch distributed constants ############################################# TORCH_DISTRIBUTED_DEFAULT_PORT = 29500 # Default process group wide t...
733
33.952381
77
py
DeepSpeed
DeepSpeed-master/deepspeed/env_report.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import deepspeed import subprocess import argparse from .ops.op_builder.all_ops import ALL_OPS from .git_version_info import installed_ops, torch_info from deepspeed.accelerator import get_accelerator GREEN = '...
4,804
37.134921
136
py
DeepSpeed
DeepSpeed-master/deepspeed/git_version_info.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team try: # This is populated by setup.py from .git_version_info_installed import * # noqa: F401 except ModuleNotFoundError: import os if os.path.isfile('version.txt'): # Will be missing from checkouts t...
756
31.913043
88
py
DeepSpeed
DeepSpeed-master/deepspeed/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import sys import types import json from typing import Optional, Union import torch from torch.optim import Optimizer from torch.optim.lr_scheduler import _LRScheduler from packaging import version as pkg_version try: i...
14,510
41.06087
157
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/zero_checkpoint.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from .constants import (BASE_OPTIMIZER_STATE, GROUP_PADDINGS, OPTIMIZER_STATE_DICT, PARTITION_COUNT) from .reshape_utils import (basic_folder_validation, get_zero_files, merge_state) from .reshape_3d_utils im...
5,316
36.70922
110
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/reshape_meg_2d.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .reshape_utils import partition_data class meg_2d_parallel_map(object): def __init__(self, pp_degree, tp_degree): self.pp_degree = pp_degree self.tp_degree = tp_degree self.map = {} d...
7,885
34.363229
114
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Various symbolic constants used for model checkpointing """ ######################################### # Optimizer checkpoint keys ######################################### OPTIMIZER_STATE_DICT = "optimizer_state_dict" FP...
2,429
33.225352
83
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import torch from .constants import (MODEL_FILE_PREFIX, MODEL_FILE_SUFFIX, OPTIM_FILE_SUFFIX, ZERO_FILE_PREFIX) def get_model_ckpt_name_for_rank(base_folder, mp_rank_str): ckpt_name = os.path.join( ba...
2,534
39.238095
111
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/reshape_3d_utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .reshape_utils import (get_files, get_files_with_prefix, partition_data, get_zero_files) from .constants import (MODEL_FILE_PREFIX, LAYER_FILE_PREFIX) from .reshape_meg_2d import (reshape_meg_2d_parallel, meg_2d_paral...
4,674
40.741071
112
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/reshape_utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import torch from collections import OrderedDict from .constants import (ZERO_FILE_PREFIX, FP16_ZERO_FILE_PREFIX, BF16_ZERO_FILE_PREFIX) def basic_folder_validation(dir): assert os.path.exists(dir), f'{dir} p...
2,888
28.783505
105
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/universal_checkpoint.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import torch import types from .constants import (FP32_WEIGHT_KEY, PARAM, VOCAB_DIVISIBILITY_PADDING_TENSOR, CAT_DIM) def load_hp_checkpoint_state(self, folder, tp_rank, tp_world_size): hp_mapping = self._hp_...
4,888
49.927083
141
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .reshape_meg_2d import reshape_meg_2d_parallel from .deepspeed_checkpoint import DeepSpeedCheckpoint from .utils import (get_layer_ckpt_name_for_rank, get_model_ckpt_name_for_rank, get_zero_ckpt_name_for_rank) from ....
561
25.761905
108
py
DeepSpeed
DeepSpeed-master/deepspeed/checkpoint/deepspeed_checkpoint.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os from typing import Dict import torch from .reshape_3d_utils import model_3d_desc from .reshape_utils import (basic_folder_validation, merge_state, partition_data, get_files, get_files_with_prefix) from .constants...
12,012
41.448763
119
py
DeepSpeed
DeepSpeed-master/deepspeed/profiling/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team ######################################### # flops profiler ######################################### # Flops profiler. By default, this feature is not enabled. # Users can configure in ds_config.json as below example: FLOPS_...
1,243
24.916667
60
py
DeepSpeed
DeepSpeed-master/deepspeed/profiling/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.runtime.config_utils import get_scalar_param, DeepSpeedConfigObject from deepspeed.profiling.constants import * class DeepSpeedFlopsProfilerConfig(DeepSpeedConfigObject): def __init__(self, param_dict):...
1,959
40.702128
119
py
DeepSpeed
DeepSpeed-master/deepspeed/profiling/__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/profiling/flops_profiler/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .profiler import *
120
16.285714
38
py
DeepSpeed
DeepSpeed-master/deepspeed/profiling/flops_profiler/profiler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import time import torch import torch.nn as nn import torch.nn.functional as F from functools import partial from typing import List, Optional from collections import OrderedDict import numpy as np from deepspeed.accelerator...
51,583
39.26854
650
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team ######################################### # Compression Methods # It has several sub-components # ######################################### COMPRESSION_TRAINING = "compression_training" SHARED_PARAMETERS = "shared_parameters...
5,569
28.470899
83
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/basic_layer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import math from torch import nn from torch.nn import init import deepspeed.comm as dist from .utils import TopKBinarizer, SymQuantizer, AsymQuantizer, TernaryQuantizer, BinaryQuantizer from deepspeed.utils impo...
36,033
41.846611
169
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/compress.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import re from .helper import compression_preparation, fix_compression, recursive_getattr, is_module_compressible from .config import get_compression_config from ..runtime.config_utils import dict_raise_error_on_duplicate_ke...
11,886
48.529167
167
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from torch import autograd import math class TopKBinarizer(autograd.Function): """ Top-k Binarizer. Computes a binary mask M from a real value matrix S such that `M_{i,j} = 1` if and only if `S_{i,...
7,818
34.06278
108
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/helper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from .basic_layer import Embedding_Compress, LinearLayer_Compress, Conv2dLayer_Compress, BNLayer_Compress, ColumnParallelLinear_Compress, RowParallelLinear_Compress from .constants import * from deepspeed.utils ...
14,637
44.318885
165
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/scheduler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .compress import get_module_name from .constants import * from .helper import recursive_getattr from deepspeed.utils import logger class compression_scheduler(): ''' Used to schedule different compression meth...
8,161
45.64
112
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .constants import * import copy from ..runtime.config_utils import get_scalar_param, get_list_param def get_compression_config(param_dict): # output = {} if COMPRESSION_TRAINING not in param_dict.keys(): ...
25,067
54.337748
159
py
DeepSpeed
DeepSpeed-master/deepspeed/compression/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .compress import init_compression, redundancy_clean from .scheduler import compression_scheduler from .helper import convert_conv1d_to_linear
243
26.111111
56
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/lr_schedules.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Implementation of learning rate schedules. Taken and modified from PyTorch v1.0.1 source https://github.com/pytorch/pytorch/blob/v1.1.0/torch/optim/lr_scheduler.py """ import argparse from torch.optim import Optimizer i...
33,541
42.903141
164
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/bf16_optimizer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from collections import OrderedDict import torch import sys import os from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors from deepspeed import comm as dist from deepspeed.runtime.constants import PIPE_...
18,534
42.611765
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os import re import stat import torch import hashlib from collections import defaultdict, OrderedDict, deque from shutil import copyfile import gc from torch.nn.modules import Module from torch.nn.parameter import Pa...
157,235
45.12379
506
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team ############################################# # Routes ############################################# ROUTE_TRAIN = "train" ROUTE_EVAL = "eval" ROUTE_PREDICT = "predict" ROUTE_ENCODE = "encode" ##############################...
12,971
29.666667
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/config_utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Collection of DeepSpeed configuration utilities """ import json import collections import collections.abc from functools import reduce from pydantic import BaseModel from deepspeed.utils import logger class DeepSpeedCon...
8,199
38.805825
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/weight_quantizer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from ..module_inject.replace_policy import HFBertLayerPolicy, replace_policies from deepspeed.accelerator import get_accelerator class WeightQuantization(object): def __init__(self, mlp_extra_grouping=Tru...
7,027
44.636364
119
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/dataloader.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from torch.utils.data import DataLoader, RandomSampler from torch.utils.data.distributed import DistributedSampler from deepspeed.accelerator import get_accelerator from deepspeed.runtime.data_pipeline.data_sampling.data_sa...
6,977
41.809816
110
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/eigenvalue.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed.utils import log_dist import numpy as np import logging class Eigenvalue(object): def __init__(self, verbose=False, max_iter=100, tol=1e-2...
5,625
36.506667
211
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Copyright NVIDIA/Megatron Helper functions and classes from multiple sources. """ from collections.abc import Iterable from deepspeed.moe.utils import is_moe_param import os import psutil import gc from math import sqrt...
35,805
35.686475
116
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/progressive_layer_drop.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import numpy as np from deepspeed.utils import log_dist class ProgressiveLayerDrop(object): r""" Progressive Layer Dropping (PLD) for model training. This implements the PLD technique for compressed model train...
1,353
32.02439
111
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/state_dict_factory.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import os import copy import collections import json from abc import ABC, abstractmethod from deepspeed.utils import logger from deepspeed.runtime.checkpoint_engine.torch_checkpoint_engine import TorchCheckpoin...
18,177
41.471963
153
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os from typing import Union from enum import Enum import torch import json import hjson import copy import base64 from .constants import * from .fp16.loss_scaler import ( INITIAL_LOSS_SCALE, SCALE_WINDOW, ...
39,863
38.705179
174
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/sparse_tensor.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Implementation of a compressed sparse tensor. Similar in functionality to TensorFlow's IndexedSlices implementation. """ import torch class SparseTensor(object): """ Compressed Sparse Tensor """ def __init__(s...
2,416
34.028986
96
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team class DeepSpeedOptimizer(object): pass class ZeROOptimizer(DeepSpeedOptimizer): pass
192
13.846154
40
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/quantize.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import math from deepspeed.utils import logger from deepspeed.ops.quantizer import ds_quantizer TWO_D_PARAMS = 6 class Quantizer(object): def __init__(self, q_groups=1, ...
7,699
41.541436
171
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/hybrid_engine.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed.inference.config import DeepSpeedInferenceConfig from deepspeed.module_inject.replace_policy import replace_policies from deepspeed.module_inject.utils import policy_to_ds_container from .engine i...
20,369
45.190476
126
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/activation_checkpointing/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.runtime.config_utils import get_scalar_param, DeepSpeedConfigObject ######################################### # DeepSpeed Activation Checkpointing ######################################### # Activation Check...
3,987
40.978947
114
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/activation_checkpointing/__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/activation_checkpointing/checkpointing.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Use to partition the activations stored for backward propagation Therefore reduces the memory consumption Also implements CPU checkpointing and contiguous memory checkpointing Reduces memory consumption and memory fragmen...
32,764
36.148526
168
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/fused_optimizer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Copyright NVIDIA/apex This file is adapted from FP16_Optimizer in NVIDIA/apex """ import torch from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors from deepspeed.runtime import DeepSpeedOptimizer f...
20,052
40.346392
126
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/__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/fp16/loss_scaler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of t...
11,492
41.409594
325
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/unfused_optimizer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Copyright NVIDIA/apex This file is adapted from FP16_Optimizer in NVIDIA/apex """ from deepspeed.moe.utils import split_params_grads_into_shared_and_expert_params import torch from torch._utils import _flatten_dense_tens...
18,076
41.039535
126
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/onebit/adam.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import types import torch import numpy as np from deepspeed.accelerator import get_accelerator from deepspeed import comm as dist class OnebitAdam(torch.optim.Optimizer): """Implements the 1-bit Adam algorithm. Current...
15,258
48.381877
196
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/onebit/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .adam import OnebitAdam from .lamb import OnebitLamb from .zoadam import ZeroOneAdam
186
19.777778
38
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/onebit/zoadam.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import types import torch import numpy as np from deepspeed.accelerator import get_accelerator from deepspeed import comm as dist class ZeroOneAdam(torch.optim.Optimizer): """Implements the 0/1 Adam algorithm. Currentl...
19,112
51.798343
194
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/fp16/onebit/lamb.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import types import torch import numpy as np from deepspeed import comm as dist from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors from deepspeed.accelerator import get_accelerator class OnebitLamb(t...
23,085
50.762332
196
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ AIO """ AIO_FORMAT = ''' "aio": { "block_size": 1048576, "queue_depth": 8, "thread_count": 1, "single_submit": false, "overlap_events": true } ''' AIO = "aio" AIO_BLOCK_SIZE = "block_size" AIO_BLOCK_SIZE_DEFAULT...
596
20.321429
38
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/aio_config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.runtime.config_utils import get_scalar_param from deepspeed.runtime.swap_tensor.constants import * AIO_DEFAULT_DICT = { AIO_BLOCK_SIZE: AIO_BLOCK_SIZE_DEFAULT, AIO_QUEUE_DEPTH: AIO_QUEUE_DEPTH_DEFAULT...
1,172
38.1
106
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/optimizer_utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping tensors to/from (NVMe) storage devices. """ import os import torch from deepspeed import comm as dist from deepspeed.utils.logging import logger from deepspeed.runtime.swap_tensor.constants imp...
18,967
39.271762
206
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping tensors to/from (NVMe) storage devices. """ import torch from deepspeed.utils.logging import logger from deepspeed.accelerator import get_accelerator from deepspeed import comm as dist MIN_AIO...
7,734
31.229167
117
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/async_swapper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping tensors to/from (NVMe) storage devices. """ import torch from deepspeed import comm as dist from deepspeed.utils.logging import logger from deepspeed.runtime.swap_tensor.utils import swap_out_te...
6,282
34.902857
100
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/pipelined_optimizer_swapper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping optimizer tensors to/from (NVMe) storage devices. """ from deepspeed.ops.op_builder import AsyncIOBuilder from deepspeed import comm as dist from deepspeed.runtime.swap_tensor.constants import ...
10,793
44.931915
119
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/partitioned_param_swapper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping tensors to/from (NVMe) storage devices. """ import os import shutil from enum import Enum import torch from deepspeed import comm as dist from deepspeed.accelerator import get_accelerator from d...
17,684
42.774752
165
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/partitioned_optimizer_swapper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Functionality of swapping optimizer tensors to/from (NVMe) storage devices. """ import torch from deepspeed.utils.logging import logger from deepspeed.ops.op_builder import AsyncIOBuilder from deepspeed import comm as d...
9,654
43.086758
114
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/swap_tensor/__init__.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team
95
18.2
38
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/compression/cupy.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import cupy from torch.utils.dlpack import to_dlpack from torch.utils.dlpack import from_dlpack class CupyBackend(object): def __init__(self): pass def torch2cupy(self, tensor): return cupy.fromDl...
701
25
62
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/compression/__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/comm/nccl.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed import comm as dist import cupy import numpy as np from deepspeed.runtime.compression.cupy import CupyBackend from deepspeed.accelerator import get_accelerator class NcclBackend(object): d...
7,712
44.370588
119
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/comm/coalesced_collectives.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ batched collective operations for overhead amortization and better bandwidth utilization """ import math from typing import List import torch from torch import Tensor from deepspeed import comm as dist # NOTE: Use torch....
6,261
46.082707
119
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/comm/mpi.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import cupy import time import numpy as np from mpi4py import MPI from deepspeed.runtime.compression.cupy import CupyBackend class MpiBackend(object): def __init__(self, cuda_aware): self.comm = ...
10,062
45.587963
119
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/comm/__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/data_pipeline/curriculum_scheduler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import math from deepspeed.utils import logger from .constants import * class CurriculumScheduler(object): def __init__(self, config): super().__init__() self.state = {} assert CURRICULUM_LEARN...
10,025
62.056604
266
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/constants.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Data efficiency library See sample config at https://www.deepspeed.ai/docs/config-json/data-efficiency """ DATA_EFFICIENCY = "data_efficiency" DATA_EFFICIENCY_ENABLED = "enabled" DATA_EFFICIENCY_ENABLED_DEFAULT = False D...
4,701
39.188034
83
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/config.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .constants import * import copy from ..config_utils import get_scalar_param # TODO: Reducing config verbosity by returning None or {} when disabled. # One challenge is that we still need to somehow include the default...
6,081
34.988166
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/__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/data_pipeline/data_sampling/data_analyzer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import os from collections import defaultdict import csv import time from multiprocessing import Process, Manager import numpy as np import torch from torch.utils.data import BatchSampler, SequentialSampler, DataLoader, Subs...
25,023
58.866029
191
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_sampling/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import math import numpy as np from deepspeed.utils import logger from .indexed_dataset import MMapIndexedDatasetBuilder def find_fit_int_dtype(min_value, max_value): if min_value >= 0: if max_value <= 255: ...
1,756
30.375
102
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_sampling/data_sampler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ coding=utf-8 Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obta...
19,160
55.522124
177
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_sampling/__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/data_pipeline/data_sampling/indexed_dataset.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team """ Part of this code was adopted from https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/data/indexed_dataset.py """ # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT li...
20,614
32.357605
115
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_routing/basic_layer.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from deepspeed.utils import logger from torch import Tensor from torch.nn import Module from ..constants import * from deepspeed.ops.random_ltd.dropping_utils import gpt_sample_tokens, bert_sample_tokens, GatherTokens, Scatt...
5,638
48.464912
118
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_routing/utils.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch def bsh_decoder_gather(reserved_length, hidden_states, mask): # random-layer-token-drop rand_list = [] part_hidden_states = [] # batch, seq, hidden ## different from megatron for k in range(h...
955
33.142857
100
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_routing/helper.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team from .basic_layer import RandomLayerTokenDrop from collections import OrderedDict from deepspeed.compression.helper import recursive_getattr, recursive_setattr def convert_to_random_ltd(model, convert_type): if hasattr...
1,282
26.297872
77
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_routing/scheduler.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import math from deepspeed.utils import logger # from deepspeed.runtime.lr_schedules import WarmupLR from ..constants import * #####based on the paper random-ltd: https://arxiv.org/abs/2211.11586 class BaseScheduler(obje...
4,638
41.953704
150
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/data_pipeline/data_routing/__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/zero/stage_1_and_2.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch import os from deepspeed import comm as dist from packaging import version as pkg_version from collections import OrderedDict from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors from deeps...
110,957
46.397693
237
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/parameter_offload.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import sys import torch from collections import OrderedDict from deepspeed.runtime.utils import see_memory_usage from deepspeed.runtime.zero.offload_config import OffloadDeviceEnum from deepspeed.runtime.zero.partition_param...
22,985
42.369811
177
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/test.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed.runtime.zero.contiguous_memory_allocator import ContiguousMemoryAllocator def test1(): mem = ContiguousMemoryAllocator(1024, torch.half, 'cpu') mem.print_allocation(resolution=100) a...
2,727
33.974359
97
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/contiguous_memory_allocator.py
# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 # DeepSpeed Team import torch from deepspeed import comm as dist def print_rank_0(message): if dist.get_rank() == 0: print(message) class ContiguousMemoryAllocator(object): def __init__(self, size, dtype, device): ...
10,926
36.940972
147
py
DeepSpeed
DeepSpeed-master/deepspeed/runtime/zero/mics_utils.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 os from dataclasses import dataclass from typing import List import numpy as np import torch from torch impo...
7,500
35.769608
116
py