repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
ELLE
ELLE-main/apex/apex/pyprof/prof/loss.py
from collections import OrderedDict from .utility import Utility from .base import OperatorLayerBase #TODO: Add support for additional loss functions. class MSELoss(OperatorLayerBase): def __init__(self, d): marker = eval(d.argMarker[0]) mod = marker['mod'] op = marker['op'] args = marker['args'] self.ma...
1,716
19.2
78
py
ELLE
ELLE-main/apex/apex/pyprof/prof/index_slice_join_mutate.py
from collections import OrderedDict from .utility import Utility import numpy as np from .base import OperatorLayerBase class Cat(OperatorLayerBase): def __init__(self, d): marker = eval(d.argMarker[0]) mod = marker['mod'] op = marker['op'] args = marker['args'] self.marker = marker self.mod_ = mod se...
8,004
18.059524
94
py
ELLE
ELLE-main/apex/apex/pyprof/prof/linear.py
from collections import OrderedDict from .utility import Utility from .base import OperatorLayerBase class Linear(OperatorLayerBase): ''' Notes: If the bias occurs before the GEMM, then its 1 write (bias expansion). If the bias occurs after, then its 1 read and 1 write. bias in bprop is a reduction and hence is ...
4,426
22.42328
133
py
ELLE
ELLE-main/apex/apex/pyprof/prof/dropout.py
from collections import OrderedDict from .utility import Utility from .base import OperatorLayerBase class Dropout(OperatorLayerBase): def __init__(self, d): marker = eval(d.argMarker[0]) mod = marker['mod'] op = marker['op'] args = marker['args'] self.marker = marker self.mod_ = mod self.op_ = op s...
999
18.607843
59
py
ELLE
ELLE-main/apex/apex/pyprof/prof/conv.py
from collections import OrderedDict from .utility import Utility from .base import OperatorLayerBase class Conv(OperatorLayerBase): """ # N = batch size # C,H,W = input channels, height, width # K,P,Q = output channels, height, width # R,S = filter height, width # g = groups """ #todo: refine winograd and FF...
6,355
25.818565
292
py
ELLE
ELLE-main/apex/apex/pyprof/prof/blas.py
from collections import OrderedDict from .utility import Utility from .base import OperatorLayerBase import numpy as np TC_GEMMS = ["884gemm", "1688gemm"] class Addmm(OperatorLayerBase): def __init__(self, d): marker = eval(d.argMarker[0]) mod = marker['mod'] op = marker['op'] args = marker['args'] self....
6,773
18.865103
96
py
ELLE
ELLE-main/apex/apex/multi_tensor_apply/multi_tensor_apply.py
import torch class MultiTensorApply(object): available = False warned = False def __init__(self, chunk_size): try: import amp_C MultiTensorApply.available = True self.chunk_size = chunk_size except ImportError as err: MultiTensorApply.availab...
991
31
82
py
ELLE
ELLE-main/apex/apex/optimizers/fused_adagrad.py
import torch from apex.multi_tensor_apply import multi_tensor_applier class FusedAdagrad(torch.optim.Optimizer): """Implements Adagrad algorithm. Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./``. This...
5,231
41.885246
145
py
ELLE
ELLE-main/apex/apex/optimizers/fused_novograd.py
import torch from apex.multi_tensor_apply import multi_tensor_applier class FusedNovoGrad(torch.optim.Optimizer): """Implements NovoGrad algorithm. Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./``. Th...
10,116
46.947867
145
py
ELLE
ELLE-main/apex/apex/optimizers/fused_sgd.py
import torch from torch.optim.optimizer import Optimizer, required from apex.multi_tensor_apply import multi_tensor_applier class FusedSGD(Optimizer): r"""Implements stochastic gradient descent (optionally with momentum). Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-...
10,041
43.04386
145
py
ELLE
ELLE-main/apex/apex/optimizers/fused_lamb.py
import torch from apex.multi_tensor_apply import multi_tensor_applier class FusedLAMB(torch.optim.Optimizer): """Implements LAMB algorithm. Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./``. This versi...
9,910
44.884259
145
py
ELLE
ELLE-main/apex/apex/optimizers/fused_adam.py
import torch from apex.multi_tensor_apply import multi_tensor_applier class FusedAdam(torch.optim.Optimizer): """Implements Adam algorithm. Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./``. This versi...
7,661
43.289017
151
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/asp.py
import types import torch from .sparse_masklib import create_mask torchvision_imported=True try: import torchvision except ImportError: print("[ASP][Warning] torchvision cannot be imported.") torchvision_imported=False def eligible_modules(model, whitelist_layer_types, allowed_layer_names, disallowed_laye...
11,740
52.857798
193
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/sparse_masklib.py
import sys import torch import numpy as np import collections from itertools import permutations """ compute density (helper fn to compute % NNZs in a tensor) """ def fill(x): return float(x.nonzero().size(0))/torch.numel(x) """ reshape matrix into m-dimensional vectors: (h,w) -> (hw/m, m) """ def reshape_1d(mat...
7,291
38.416216
103
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/test/checkpointing_test_reference.py
from collections import OrderedDict import torch from apex.optimizers import FusedAdam from apex.contrib.sparsity import ASP # # Reference run for checkpointing test (part1 + part2) # def build_model(args): od = OrderedDict() for i in range(args.num_layers): if i == 0: od['linear_layer_%d...
3,177
31.762887
125
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/test/toy_problem.py
from collections import OrderedDict import torch from apex.optimizers import FusedAdam from apex.contrib.sparsity import ASP def build_model(args): od = OrderedDict() for i in range(args.num_layers): if i == 0: od['linear_layer_%d' % (i+1)] = torch.nn.Linear(args.input_features, args.hidde...
3,217
35.568182
104
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/test/checkpointing_test_part2.py
from collections import OrderedDict import torch from apex.optimizers import FusedAdam from apex.contrib.sparsity import ASP def build_model(args): od = OrderedDict() for i in range(args.num_layers): if i == 0: od['linear_layer_%d' % (i+1)] = torch.nn.Linear(args.input_features, args.hidde...
3,131
38.15
151
py
ELLE
ELLE-main/apex/apex/contrib/sparsity/test/checkpointing_test_part1.py
from collections import OrderedDict import torch from apex.optimizers import FusedAdam from apex.contrib.sparsity import ASP def build_model(args): od = OrderedDict() for i in range(args.num_layers): if i == 0: od['linear_layer_%d' % (i+1)] = torch.nn.Linear(args.input_features, args.hidde...
3,353
34.305263
151
py
ELLE
ELLE-main/apex/apex/contrib/transducer/transducer.py
import torch import transducer_loss_cuda import transducer_joint_cuda class TransducerJoint(torch.nn.Module): """Transducer joint Detail of this loss function can be found in: Sequence Transduction with Recurrent Neural Networks Arguments: pack_output (bool, optional): whether to pack the out...
8,143
49.271605
101
py
ELLE
ELLE-main/apex/apex/contrib/groupbn/batch_norm.py
import torch import numpy as np from torch.nn.modules.batchnorm import _BatchNorm import bnp class bn_NHWC_impl(torch.autograd.Function): @staticmethod def forward(ctx, x, s, b, rm, riv, mini_m, mini_riv, ret_cta, mom, epsilon, fuse_relu, is_train, bn_group, my_data, pair_data, magic, pair_data2, pair_data3, ...
11,208
48.597345
229
py
ELLE
ELLE-main/apex/apex/contrib/groupbn/__init__.py
try: import torch import bnp from .batch_norm import BatchNorm2d_NHWC del torch del bnp del batch_norm except ImportError as err: print("apex was installed without --bnp flag, contrib.groupbn is not available")
239
23
84
py
ELLE
ELLE-main/apex/apex/contrib/examples/multihead_attn/func_test_multihead_attn.py
import torch import torch.nn.functional as F import argparse from apex.contrib.multihead_attn import SelfMultiheadAttn from apex.contrib.multihead_attn import EncdecMultiheadAttn parser = argparse.ArgumentParser(description='Multihead Attention Standalone Test') parser.add_argument('--seq-length', default=64, type=in...
5,740
51.669725
164
py
ELLE
ELLE-main/apex/apex/contrib/examples/multihead_attn/perf_test_multihead_attn.py
import torch import torch.nn.functional as F import argparse from apex.contrib.multihead_attn import SelfMultiheadAttn from apex.contrib.multihead_attn import EncdecMultiheadAttn parser = argparse.ArgumentParser(description='Multihead Attention Standalone Test') parser.add_argument('--seq-length', default=64, type=in...
6,163
52.137931
157
py
ELLE
ELLE-main/apex/apex/contrib/test/test_label_smoothing.py
import torch from apex.contrib import xentropy as label_smoothing import unittest import warnings import random import numpy as np import time def label_smoothing_raw(x, target, padding_idx, smoothing): logprobs = torch.nn.functional.log_softmax(x, dim=-1, dtype=torch.float32) non_pad_mask = (target != paddi...
4,800
36.217054
85
py
ELLE
ELLE-main/apex/apex/contrib/test/transducer/test_transducer_joint.py
import torch import unittest from apex.contrib.transducer import TransducerJoint import transducer_ref class TransducerJointTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) def gen_input(self, for_vector_kernel): self.B = 4 ...
4,367
39.82243
100
py
ELLE
ELLE-main/apex/apex/contrib/test/transducer/transducer_ref.py
import torch import numpy as np import pdb def transducer_loss_reference(x, label, f_len, y_len, blank_idx, loss_grad): def log_sum_exp(a, b): if (a >= b): return a + torch.log(1 + torch.exp(b-a)) else: return b + torch.log(1 + torch.exp(a-b)) def forward_alpha(x, label...
4,341
41.15534
104
py
ELLE
ELLE-main/apex/apex/contrib/test/transducer/test_transducer_loss.py
import torch import unittest from apex.contrib.transducer import TransducerLoss import transducer_ref class TransducerLossTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) def gen_input(self, scalar_t): self.B = 5 T_mi...
5,899
47.760331
100
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_encdec_multihead_attn_norm_add.py
import torch import unittest from apex.contrib.multihead_attn import EncdecMultiheadAttn class EncdecMultiheadAttnNormAddTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 self.sequences = 10 ...
3,875
48.692308
110
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_fast_self_multihead_attn_bias.py
import torch import unittest from apex.contrib.multihead_attn import SelfMultiheadAttn class SelfMultiheadAttnTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 self.sequences = 10 self.h...
3,668
46.038462
108
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_self_multihead_attn.py
import torch import unittest from apex.contrib.multihead_attn import SelfMultiheadAttn class SelfMultiheadAttnTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 self.sequences = 10 self.h...
6,569
49.152672
147
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_encdec_multihead_attn.py
import torch import unittest from apex.contrib.multihead_attn import EncdecMultiheadAttn class EncdecMultiheadAttnTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 self.sequences = 10 se...
7,429
53.233577
152
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_self_multihead_attn_norm_add.py
import torch import unittest from apex.contrib.multihead_attn import SelfMultiheadAttn class SelfMultiheadAttnNormAddTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 self.sequences = 10 ...
3,305
44.287671
108
py
ELLE
ELLE-main/apex/apex/contrib/test/multihead_attn/test_mha_fused_softmax.py
import torch import unittest import torch.nn.functional as F from apex.contrib.multihead_attn import fast_mask_softmax_dropout_func class FusedSoftmaxTest(unittest.TestCase): def setUp(self, seed=1234): torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) self.seq_length = 80 ...
1,800
40.883721
111
py
ELLE
ELLE-main/apex/apex/contrib/test/layer_norm/test_fast_layer_norm.py
import torch import unittest import numpy as np import torch.nn.functional as F from apex.contrib.layer_norm import FastLayerNorm import fast_layer_norm as fln class GPUTimer: def __init__(self, stream): self.start_ = torch.cuda.Event(enable_timing=True) self.stop_ = torch.cuda.Event(enable_tim...
4,960
30.00625
116
py
ELLE
ELLE-main/apex/apex/contrib/xentropy/softmax_xentropy.py
import torch import xentropy_cuda class SoftmaxCrossEntropyLoss(torch.autograd.Function): @staticmethod def forward(ctx, logits, labels, smoothing=0.0, padding_idx=0, half_to_float=False): losses, max_log_sum_exp = xentropy_cuda.forward( logits, labels, smoothing, half_to_float) los...
1,023
34.310345
88
py
ELLE
ELLE-main/apex/apex/contrib/xentropy/__init__.py
try: import torch import xentropy_cuda from .softmax_xentropy import SoftmaxCrossEntropyLoss del torch del xentropy_cuda del softmax_xentropy except ImportError as err: print("apex was installed without --xentropy flag, contrib.xentropy is not available")
284
27.5
90
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/fast_encdec_multihead_attn_func.py
import torch import fast_encdec_multihead_attn class FastEncdecAttnFunc(torch.autograd.Function): @staticmethod def forward(ctx, use_time_mask, is_training, heads, inputs_q, inputs_kv, input_weights_q, input_weights_kv, output_weights, pad_mask, dropout_prob): heads_t = torch.tensor([heads]) ...
5,447
60.213483
152
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/fast_self_multihead_attn_norm_add_func.py
import torch import fast_self_multihead_attn_norm_add class FastSelfAttnNormAddFunc(torch.autograd.Function): @staticmethod def forward(ctx, use_time_mask, is_training, heads, inputs, lyr_nrm_gamma_weights, lyr_nrm_beta_weights, input_weights, output_weights, pad_mask, dropout_prob): heads_t = ...
6,704
61.663551
164
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/fast_self_multihead_attn_func.py
import torch import fast_self_multihead_attn import fast_self_multihead_attn_bias import fast_self_multihead_attn_bias_additive_mask class FastSelfAttnFunc(torch.autograd.Function) : @staticmethod def forward(ctx, use_time_mask, is_training, heads, inputs, input_weights, output_weights, input_biases, output_bi...
13,483
67.446701
163
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/fast_encdec_multihead_attn_norm_add_func.py
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. import torch import fast_encdec_mu...
8,251
61.992366
197
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/self_multihead_attn.py
import math import torch from torch import nn from torch.nn import Parameter import torch.nn.functional as F from .self_multihead_attn_func import self_attn_func from .fast_self_multihead_attn_func import fast_self_attn_func from .fast_self_multihead_attn_norm_add_func import fast_self_attn_nor...
9,054
49.586592
301
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/encdec_multihead_attn_func.py
import torch import torch.nn.functional as F class EncdecAttnFunc(torch.autograd.Function): @staticmethod def forward(ctx, use_time_mask, is_training, heads, scale, inputs_q, inputs_kv, input_weights_q, input_weights_kv, output_weights, input_biases_q, input_biases_kv, output_b...
17,587
64.3829
178
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/mask_softmax_dropout_func.py
import torch import fast_mask_softmax_dropout import fast_additive_mask_softmax_dropout class MaskSoftmaxDropout(torch.autograd.Function) : @staticmethod def forward(ctx, is_training, heads, inputs, pad_mask, mask_additive, dropout_prob): heads_t = torch.tensor([heads]) dropout_prob_t =...
4,603
55.146341
91
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/encdec_multihead_attn.py
import math import torch from torch import nn from torch.nn import Parameter import torch.nn.functional as F from .encdec_multihead_attn_func import encdec_attn_func from .fast_encdec_multihead_attn_func import fast_encdec_attn_func from .fast_encdec_multihead_attn_norm_add_func import fast_enc...
7,043
48.605634
129
py
ELLE
ELLE-main/apex/apex/contrib/multihead_attn/self_multihead_attn_func.py
import torch import torch.nn.functional as F class SelfAttnFunc(torch.autograd.Function): @staticmethod def forward(ctx, use_time_mask, is_training, heads, scale, inputs, input_weights, output_weights, input_biases, output_biases, mask, is_additive_mask, dropout_...
14,741
61.466102
178
py
ELLE
ELLE-main/apex/apex/contrib/layer_norm/layer_norm.py
import torch from torch.nn import init import fast_layer_norm class FastLayerNormFN(torch.autograd.Function): @staticmethod def forward(ctx, x, gamma, beta, epsilon): x = x.contiguous() gamma = gamma.contiguous() beta = beta.contiguous() hidden_size = gamma.numel() xmat...
1,490
32.133333
85
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/distributed_fused_adam_v2.py
import math import torch import importlib import amp_C from apex.multi_tensor_apply import multi_tensor_applier class DistributedFusedAdamV2(torch.optim.Optimizer): """Implements Adam algorithm. Currently GPU-only. Requires Apex to be installed via ``python setup.py install --cuda_ext --cpp_ext``. It ha...
31,780
50.592532
282
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/distributed_fused_adam.py
import math import torch import importlib import amp_C from apex.multi_tensor_apply import multi_tensor_applier import torch.distributed.distributed_c10d as c10d class DistributedFusedAdam(torch.optim.Optimizer): """Implements Adam algorithm. Currently GPU-only. Requires Apex to be installed via ``python se...
34,787
53.612245
283
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/fp16_optimizer.py
import torch from apex.multi_tensor_apply import multi_tensor_applier class FP16_Optimizer(object): """ :class:`FP16_Optimizer` A cutdown version of apex.fp16_utils.FP16_Optimizer. Designed only to wrap apex.contrib.optimizers.FusedAdam, FusedSGD. Refer to apex.fp16_utils documents for more information...
10,448
41.82377
126
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/distributed_fused_adam_v3.py
import math import torch import importlib import amp_C from apex.multi_tensor_apply import multi_tensor_applier class DistributedFusedAdamV3(torch.optim.Optimizer): """Implements Adam algorithm. Currently GPU-only. Requires Apex to be installed via ``python setup.py install --cuda_ext --cpp_ext``. It ha...
15,709
47.190184
244
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/fused_sgd.py
import types import torch from torch.optim.optimizer import Optimizer, required from apex.multi_tensor_apply import multi_tensor_applier class FusedSGD(Optimizer): r"""Implements stochastic gradient descent (optionally with momentum). This version of fused SGD implements 2 fusions. * Fusion of the SGD ...
9,468
43.665094
145
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/fused_lamb.py
import torch import importlib import math from apex.multi_tensor_apply import multi_tensor_applier class FusedLAMB(torch.optim.Optimizer): """Implements LAMB algorithm. Currently GPU-only. Requires Apex to be installed via ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cu...
9,408
44.019139
145
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/fused_adam.py
import types import torch import importlib from apex.multi_tensor_apply import multi_tensor_applier class FusedAdam(torch.optim.Optimizer): """Implements Adam algorithm. Currently GPU-only. Requires Apex to be installed via ``python setup.py install --cuda_ext --cpp_ext``. It has been proposed in `Adam:...
9,284
43.855072
145
py
ELLE
ELLE-main/apex/apex/contrib/optimizers/distributed_fused_lamb.py
import math import torch import importlib import amp_C from apex.multi_tensor_apply import multi_tensor_applier import torch.distributed.distributed_c10d as c10d class DistributedFusedLAMB(torch.optim.Optimizer): """Implements LAMB algorithm. Currently GPU-only. Requires Apex to be installed via ``...
39,051
53.771388
283
py
ELLE
ELLE-main/apex/apex/reparameterization/reparameterization.py
import torch from torch.nn.parameter import Parameter import sys class Reparameterization(object): """ Class interface for performing weight reparameterizations Arguments: name (str): name of weight parameter dim (int): dimension over which to compute the norm module (nn.Module): par...
6,291
40.394737
127
py
ELLE
ELLE-main/apex/apex/reparameterization/__init__.py
from .weight_norm import WeightNorm from .reparameterization import Reparameterization def apply_weight_norm(module, name='', dim=0, hook_child=True): r""" Applies weight normalization to a parameter in the given module. If no parameter is provided, applies weight normalization to all parameters in mod...
5,374
40.992188
106
py
ELLE
ELLE-main/apex/apex/reparameterization/weight_norm.py
import torch from torch.nn.parameter import Parameter from ..fp16_utils import Fused_Weight_Norm import time from .reparameterization import Reparameterization def _norm(p, dim): """Computes the norm over all dimensions except dim""" if dim is None: return p.norm() elif dim == 0: output_si...
3,203
39.556962
84
py
ELLE
ELLE-main/apex/apex/mlp/mlp.py
from copy import copy import math import torch from torch import nn import mlp_cuda from .. import amp class MlpFunction(torch.autograd.Function): @staticmethod def forward(ctx, bias, activation, *args): output = mlp_cuda.forward(bias, activation, args) ctx.save_for_backward(*args) ctx....
2,614
31.6875
115
py
ELLE
ELLE-main/downstream/convert_roberta_to_hf_batch.py
# coding=utf-8 # Copyright 2018 The HuggingFace Inc. team. # # 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 the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
8,381
45.309392
112
py
ELLE
ELLE-main/downstream/convert_roberta_to_hf.py
# coding=utf-8 # Copyright 2018 The HuggingFace Inc. team. # # 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 the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
8,169
44.388889
117
py
ELLE
ELLE-main/downstream/scripts/mlm_study.py
from typing import Tuple, List, Dict from transformers import AutoModelWithLMHead, AutoTokenizer, PreTrainedTokenizer, PreTrainedModel, PreTrainedTokenizer from torch.utils.data import DataLoader, Dataset, RandomSampler, SequentialSampler from torch.nn.utils.rnn import pad_sequence import numpy as np import torch from...
9,100
41.528037
161
py
ELLE
ELLE-main/downstream/scripts/run_language_modeling.py
### THIS FILE IS COPIED FROM THE HUGGINGFACE REPOSITORY FOR CONVENIENCE. # coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not u...
34,477
42.643038
165
py
ELLE
ELLE-main/downstream/scripts/tapt_selection/run_vampire.py
""" The ``predict`` subcommand allows you to make bulk JSON-to-JSON or dataset to JSON predictions using a trained model and its :class:`~allennlp.service.predictors.predictor.Predictor` wrapper. .. code-block:: bash $ allennlp predict --help usage: allennlp predict [-h] [--output-file OUTPUT_FILE] ...
10,674
38.83209
115
py
ELLE
ELLE-main/downstream/scripts/tapt_selection/query_index.py
import faiss import torch import glob import argparse from tqdm import tqdm, trange import json from itertools import islice import numpy as np import logging from torch.utils.data import Dataset, DataLoader import os from tempfile import mkdtemp import re import pandas as pd logging.basicConfig(level=logging.INFO) l...
10,014
37.079848
128
py
ELLE
ELLE-main/downstream/scripts/tapt_selection/build_index.py
import faiss import torch import glob import argparse from tqdm import tqdm, trange import simplejson as json from itertools import islice import numpy as np import logging from torch.utils.data import Dataset, DataLoader import os from tempfile import mkdtemp import re logging.basicConfig(level=logging.INFO) logger ...
6,641
35.295082
113
py
ELLE
ELLE-main/downstream/scripts/tapt_selection/convert_pytorch_to_memmap.py
import glob from tqdm import tqdm import numpy as np import torch import sys from numpy.lib.format import open_memmap import os if __name__ == '__main__': input_dir = sys.argv[1] dirs = glob.glob(input_dir) for file_ in tqdm(dirs): if ".emb" not in file_ and ".id" not in file_: x = torc...
791
33.434783
117
py
ELLE
ELLE-main/downstream/dont_stop_pretraining/pnn_roberta.py
import argparse import pathlib import os import fairseq import torch from fairseq.models.roberta import RobertaModel as FairseqRobertaModel from fairseq.models.roberta.hub_interface import RobertaHubInterface from fairseq.models.pnn_roberta import PNN_Roberta from fairseq.tasks.continual_KI import Continual_KI from fai...
7,530
42.034286
136
py
ELLE
ELLE-main/downstream/dont_stop_pretraining/modules/seq2vec_encoders/cls_pooler.py
from typing import Union from overrides import overrides import torch import torch.nn from pytorch_pretrained_bert import BertModel from allennlp.modules.seq2vec_encoders.seq2vec_encoder import Seq2VecEncoder @Seq2VecEncoder.register("cls_pooler") class CLSPooler(Seq2VecEncoder): """ The pooling layer at t...
1,903
35.615385
123
py
ELLE
ELLE-main/downstream/dont_stop_pretraining/training/ft_checkpointer.py
from typing import Union, Dict, Any, List, Tuple import logging import os import re import shutil import time import torch from allennlp.common.registrable import Registrable from allennlp.nn import util as nn_util from allennlp.training.checkpointer import Checkpointer logger = logging.getLogger(__name__) @Checkpo...
7,836
49.237179
115
py
ELLE
ELLE-main/downstream/dont_stop_pretraining/models/basic_classifier_with_f1.py
from typing import Dict, Optional from overrides import overrides import torch from allennlp.data import Vocabulary from allennlp.models.model import Model from allennlp.modules import Seq2SeqEncoder, Seq2VecEncoder, TextFieldEmbedder, FeedForward from allennlp.nn import InitializerApplicator, RegularizerApplicator f...
7,368
39.712707
121
py
ELLE
ELLE-main/downstream/mlm_study/huggingface_study/mlm.py
from typing import Tuple, List from transformers import AutoModelWithLMHead, AutoTokenizer, PreTrainedTokenizer from torch.utils.data import DataLoader, Dataset, RandomSampler, SequentialSampler from torch.nn.utils.rnn import pad_sequence import numpy as np import torch from tqdm import tqdm import random import argpa...
5,944
43.699248
161
py
ELLE
ELLE-main/downstream/mlm_study/fairseq_study/validate_modified.py
#!/usr/bin/env python3 -u #!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import sys import torch from fairseq import checkpoint_utils, distributed...
3,838
30.991667
88
py
ELLE
ELLE-main/downstream/mlm_study/fairseq_study/convert_hf_to_fairseq.py
# coding=utf-8 # Copyright 2018 The HuggingFace Inc. team. # # 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 the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable...
7,266
47.771812
196
py
ELLE
ELLE-main/fairseq_ELLE/setup.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from setuptools import setup, find_packages, Extension import sys if sys.version_info < (3, 5): sys.exi...
4,357
25.736196
92
py
ELLE
ELLE-main/fairseq_ELLE/generate.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate pre-processed data with a trained model. """ import torch from fairseq import bleu, checkpoint_utils,...
8,179
39.098039
110
py
ELLE
ELLE-main/fairseq_ELLE/hubconf.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import functools from fairseq.hub_utils import BPEHubInterface as bpe # noqa from fairseq.hub_utils import TokenizerHubInterface as tokenize...
1,432
28.244898
78
py
ELLE
ELLE-main/fairseq_ELLE/validate.py
#!/usr/bin/env python3 -u #!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch from fairseq import checkpoint_utils, options, progress_bar, utils def mai...
3,163
30.64
88
py
ELLE
ELLE-main/fairseq_ELLE/eval_lm.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Evaluate the perplexity of a trained language model. """ import numpy as np import torch from fairseq import c...
8,132
34.671053
118
py
ELLE
ELLE-main/fairseq_ELLE/interactive.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate raw text with a trained model. Batches data on-the-fly. """ from collections import namedtuple import ...
6,445
32.05641
103
py
ELLE
ELLE-main/fairseq_ELLE/train.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Train a new model on one or across multiple GPUs. """ import collections import math import random import os imp...
27,316
41.816614
216
py
ELLE
ELLE-main/fairseq_ELLE/examples/roberta/commonsense_qa/commonsense_qa_task.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import json import os import numpy as np import torch from fairseq.data import ( data_utils, Dictionary, encoders, IdDataset...
5,921
32.84
103
py
ELLE
ELLE-main/fairseq_ELLE/examples/roberta/wsc/wsc_task.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import json import os import tempfile import numpy as np import torch import torch.nn.functional as F from fairseq import utils from fairseq...
13,149
33.973404
103
py
ELLE
ELLE-main/fairseq_ELLE/examples/roberta/wsc/wsc_criterion.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import torch import torch.nn.functional as F from fairseq import utils from fairseq.data import encoders from fairseq.criterions...
6,022
35.065868
88
py
ELLE
ELLE-main/fairseq_ELLE/scripts/average_checkpoints.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import collections import torch import os import re def average_checkpoints(inputs): """Loads che...
5,292
36.539007
134
py
ELLE
ELLE-main/fairseq_ELLE/scripts/wav2vec_featurize.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Helper script to pre-compute embeddings for a wav2letter++ dataset """ import argparse import glob import os from ...
7,102
28.970464
135
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_train.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import contextlib from io import StringIO import unittest from unittest.mock import MagicMock, patch import torch from fairseq import data, ...
4,691
35.092308
94
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_average_checkpoints.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import collections import os import tempfile import unittest import shutil import numpy as np import torch from torch import nn from script...
4,494
30.215278
80
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_sequence_scorer.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import unittest import torch from fairseq.sequence_scorer import SequenceScorer import tests.utils as test_utils class Te...
3,949
33.051724
75
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_memory_efficient_fp16.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import unittest import torch from fairseq.optim.adam import FairseqAdam from fairseq.optim.fp16_optimizer import MemoryEffic...
1,787
28.311475
69
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_multihead_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import unittest from fairseq.modules.multihead_attention import MultiheadAttention class TestMultiheadAttention(unittest.TestCa...
1,904
30.229508
80
py
ELLE
ELLE-main/fairseq_ELLE/tests/utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import torch from fairseq import utils from fairseq.data import Dictionary from fairseq.data.language_pair_dataset import col...
7,442
30.67234
101
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_binaries.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import contextlib from io import StringIO import os import random import sys import tempfile import unittest import torch from fairseq impor...
31,257
40.183136
115
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_concat_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import unittest import torch from fairseq.data import LanguagePairDataset, TokenBlockDataset from fairseq.data.concat_dataset import ConcatDa...
1,943
28.907692
66
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_noising.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import unittest from typing import Dict, List import tests.utils as test_utils import torch from fairseq import utils from fairseq.data impor...
19,779
36.533207
87
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_sparse_multihead_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import unittest from fairseq.modules.sparse_multihead_attention import SparseMultiheadAttention class TestSparseMultiheadAttent...
2,545
50.959184
114
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_backtranslation_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import unittest import torch from fairseq.data import ( BacktranslationDataset, LanguagePairDataset, TransformEosDataset, ) from...
4,032
33.470085
90
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_sequence_generator.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import unittest import torch from fairseq.sequence_generator import SequenceGenerator import tests.utils as test_utils cl...
14,876
38.884718
96
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_label_smoothing.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import copy import unittest import torch from fairseq.criterions.cross_entropy import CrossEntropyCriterion from fairseq.cri...
4,139
40.4
101
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_convtbc.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import unittest from fairseq.modules import ConvTBC import torch.nn as nn class TestConvTBC(unittest.TestCase): def test_c...
1,679
33.285714
102
py
ELLE
ELLE-main/fairseq_ELLE/tests/test_token_block_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import unittest import torch from fairseq.data import TokenBlockDataset import tests.utils as test_utils class TestTokenBlockDataset(unit...
2,970
36.607595
89
py