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 |
|---|---|---|---|---|---|---|
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/parallel/sync_batchnorm_kernel.py | import torch
from torch.autograd.function import Function
from apex.parallel import ReduceOp
class SyncBatchnormFunction(Function):
@staticmethod
def forward(ctx, input, weight, bias, running_mean, running_variance, eps, process_group, world_size):
torch.cuda.nvtx.range_push("sync_BN_fw")
# ... | 3,761 | 41.75 | 106 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/RNN/cells.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from .RNNBackend import RNNCell
from torch.nn._functions.thnn import rnnFusedPointwise as fusedBackend
import math
class mLSTMRNNCell(RNNCell):
"""
mLSTMRNNCell
"""
def __init__(self, input_size, hidden_size, bias = False, output_... | 2,550 | 29.011765 | 156 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/RNN/RNNBackend.py | import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.nn.functional as F
import math
def is_iterable(maybe_iterable):
return isinstance(maybe_iterable, list) or isinstance(maybe_iterable, tuple)
def flatten_list(tens_list):
"""
flatten_list
"""
if not is_iterable(... | 11,578 | 30.636612 | 126 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/RNN/models.py | import torch
from torch.nn._functions.rnn import LSTMCell, RNNReLUCell, RNNTanhCell, GRUCell
from .RNNBackend import bidirectionalRNN, stackedRNN, RNNCell
from .cells import mLSTMRNNCell, mLSTMCell
def toRNNBackend(inputRNN, num_layers, bidirectional=False, dropout = 0):
"""
:class:`toRNNBackend`
"""
... | 2,137 | 37.872727 | 129 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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,652 | 48.548837 | 149 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/optimizers/fused_mixed_precision_lamb.py | import torch
from copy import deepcopy
from itertools import chain
from collections import defaultdict, abc as container_abcs
from apex.multi_tensor_apply import multi_tensor_applier
class FusedMixedPrecisionLamb(torch.optim.Optimizer):
def __init__(self, params, lr=1e-3, step=0, bias_correction=True,
... | 11,231 | 42.70428 | 111 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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... | 8,483 | 42.731959 | 151 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/sparsity/asp.py | import types
import torch
from .sparse_masklib import create_mask
from .permutation_lib import Permutation
torchvision_imported=True
try:
import torchvision
except ImportError:
print("[ASP][Warning] torchvision cannot be imported.")
torchvision_imported=False
import json
import os
import string
import tim... | 19,277 | 59.432602 | 307 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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,433 | 38.542553 | 103 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/sparsity/permutation_lib.py | import os
import torch
import json
import string
import time
try:
from .permutation_search_kernels import accelerated_search_for_good_permutation, sum_after_2_to_4
print("[ASP][Info] permutation_search_kernels can be imported.")
except ImportError:
print("[ASP][Warning] permutation_search_kernels cannot be ... | 72,979 | 77.642241 | 329 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/clip_grad/clip_grad.py | import torch
from torch._six import inf
from typing import Union, Iterable
_kernel_import_succeeded = False
try:
import amp_C
from apex.multi_tensor_apply import multi_tensor_applier
_kernel_import_succeeded = True
except:
_kernel_import_succeeded = False
_tensor_or_tensors = Union[torch.Tensor, Itera... | 4,373 | 33.171875 | 87 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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... | 9,934 | 49.688776 | 102 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/transducer/_transducer_ref.py | import torch
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, f_len, y_len, blank_idx):
... | 4,621 | 41.018182 | 104 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/bottleneck/test.py | import torch
from bottleneck import Bottleneck
torch.manual_seed(23337)
# use True to print layerwise sum for all outputs in reference code path
DEBUG = False#True
for stride, o_channel in [(1,32), (1,128), (2,32)]:
print("testing stride ==", stride, ", in_channel == 32 , out_channel ==", o_channel)
a_ = torc... | 3,070 | 41.652778 | 131 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/bottleneck/bottleneck.py | import functools as func
import torch
import torch.distributed as dist
from torch import nn
from apex import check_cudnn_version_and_warn
import fast_bottleneck
import nccl_p2p_cuda as inc
assert check_cudnn_version_and_warn(__name__, 8400)
def kaiming_uniform_(tensor, a=0, mode='fan_in', nonlinearity='leaky_relu... | 36,558 | 47.745333 | 222 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/bottleneck/halo_exchangers.py | import torch
import torch.distributed as dist
from torch import nn
import nccl_p2p_cuda as inc
import peer_memory_cuda as pm
# Communication free halo exchanger.
# NB! This halo exchanger does not exchange halos with neighbors as it should, it merely swaps the inputs
# NB! This is only useful for performance testing.
... | 9,599 | 54.813953 | 216 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/cudnn_gbn/batch_norm.py | import torch
from torch.nn.modules.batchnorm import _BatchNorm
from torch.nn import functional as F
from torch import Tensor
import peer_memory_cuda as pm
import cudnn_gbn_lib
from torch.cuda.amp import custom_fwd, custom_bwd
class _GroupBatchNorm2d(torch.autograd.Function):
@staticmethod
@custom_fwd
def ... | 6,725 | 45.386207 | 144 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/clip_grad/test_clip_grad.py | import random
import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.clip_grad import clip_grad_norm_
except ImportError as e:
SKIP_TEST = e
def make_params(
num_params,
sizes=[1,2,3,4,5],
num_dims=[1,2,3],
dtypes=[torch.float32],
devices=['cuda'],
... | 4,983 | 27.809249 | 80 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/transducer/test_transducer_joint.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.transducer import TransducerJoint
from apex.contrib.transducer import _transducer_ref as transducer_ref
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class TransducerJointTest(unittest.TestCase):
... | 7,232 | 42.053571 | 103 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/transducer/test_transducer_loss.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.transducer import TransducerLoss
from apex.contrib.transducer import _transducer_ref as transducer_ref
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class TransducerLossTest(unittest.TestCase):
... | 6,972 | 48.807143 | 100 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/bottleneck/test_bottleneck_module.py | import unittest
import torch
from torch.testing._internal import common_utils
from apex.transformer.testing.distributed_test_base import NcclDistributedTestBase
SKIP_TEST = None
try:
from apex.contrib.bottleneck import Bottleneck, SpatialBottleneck
from apex.contrib.bottleneck import HaloExchangerPeer
fro... | 11,597 | 34.46789 | 117 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/cudnn_gbn/test_cudnn_gbn_with_two_gpus.py | import copy
import typing
import unittest
import torch
import torch.nn as nn
from torch.testing._internal import common_utils
SKIP_TEST = None
from apex.transformer.testing.distributed_test_base import NcclDistributedTestBase
try:
from apex.contrib.cudnn_gbn import GroupBatchNorm2d as GBN
except ImportError as e:... | 4,902 | 32.128378 | 114 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/xentropy/test_label_smoothing.py | import unittest
import random
import time
import numpy as np
import torch
SKIP_TEST = None
try:
from apex.contrib import xentropy as label_smoothing
except ImportError as e:
SKIP_TEST = e
def label_smoothing_raw(x, target, padding_idx, smoothing):
logprobs = torch.nn.functional.log_softmax(x, dim=-1, d... | 4,852 | 34.423358 | 85 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/conv_bias_relu/test_conv_bias_relu.py | import copy
import math
import random
import unittest
import torch
import torch.nn.functional as F
HAS_CONV_BIAS_RELU = None
try:
from apex.contrib.conv_bias_relu import ConvBiasReLU, ConvBias, ConvBiasMaskReLU
except ImportError as e:
HAS_CONV_BIAS_RELU = False
else:
HAS_CONV_BIAS_RELU = True
@unittest... | 5,275 | 48.308411 | 147 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_encdec_multihead_attn_norm_add.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import EncdecMultiheadAttn
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class EncdecMultiheadAttnNormAddTest(unittest.TestCase):
def setUp(self, seed=1234):
torch.manual_seed... | 4,036 | 45.94186 | 110 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_fast_self_multihead_attn_bias.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import SelfMultiheadAttn
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class SelfMultiheadAttnTest(unittest.TestCase):
def setUp(self, seed=1234):
torch.manual_seed(seed)
... | 3,730 | 43.416667 | 108 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_self_multihead_attn.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import SelfMultiheadAttn
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class SelfMultiheadAttnTest(unittest.TestCase):
def setUp(self, seed=1234):
torch.manual_seed(seed)
... | 6,689 | 47.832117 | 147 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_encdec_multihead_attn.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import EncdecMultiheadAttn
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class EncdecMultiheadAttnTest(unittest.TestCase):
def setUp(self, seed=1234):
torch.manual_seed(seed)
... | 7,468 | 51.598592 | 152 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_self_multihead_attn_norm_add.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import SelfMultiheadAttn
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class SelfMultiheadAttnNormAddTest(unittest.TestCase):
def setUp(self, seed=1234):
torch.manual_seed(see... | 3,430 | 41.8875 | 108 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/multihead_attn/test_mha_fused_softmax.py | import unittest
import torch
import torch.nn.functional as F
SKIP_TEST = None
try:
from apex.contrib.multihead_attn import fast_mask_softmax_dropout_func
except ImportError as e:
SKIP_TEST = e
@unittest.skipIf(SKIP_TEST, f"{SKIP_TEST}")
class FusedSoftmaxTest(unittest.TestCase):
def setUp(self, seed=123... | 1,891 | 36.098039 | 108 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/focal_loss/test_focal_loss.py | import unittest
import torch
import torch.nn.functional as F
reference_available = True
try:
from torchvision.ops.focal_loss import sigmoid_focal_loss
except ImportError:
reference_available = False
SKIP_TEST = None
try:
from apex.contrib.focal_loss import focal_loss
except ImportError as e:
SKIP_TES... | 2,253 | 29.053333 | 135 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/layer_norm/test_fast_layer_norm.py | import unittest
import torch
SKIP_TEST = None
try:
from apex.contrib.layer_norm.layer_norm import FastLayerNorm
import fast_layer_norm as fln
except ImportError as e:
SKIP_TEST = e
class GPUTimer:
def __init__(self, stream):
self.start_ = torch.cuda.Event(enable_timing=True)
self.sto... | 8,127 | 28.028571 | 96 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/optimizers/test_dist_adam.py | from contextlib import contextmanager
import io
import unittest
import torch
from torch.testing._internal import common_utils
SKIP_TEST = None
try:
from apex.contrib.optimizers.distributed_fused_adam import DistributedFusedAdam
except ImportError as e:
SKIP_TEST = e
from apex.transformer.testing.distributed_t... | 15,196 | 32.771111 | 87 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/peer_memory/test_peer_halo_exchange_module.py | import unittest
import torch
from torch.testing._internal import common_utils
SKIP_TEST = None
from apex.transformer.testing.distributed_test_base import NcclDistributedTestBase
try:
from apex.contrib.peer_memory import PeerMemoryPool, PeerHaloExchanger1d
except ImportError as e:
SKIP_TEST = e
# How to run:
... | 10,139 | 29.820669 | 111 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/index_mul_2d/test_index_mul_2d.py | import random
import unittest
import torch
HAS_INDEX_MUL_2D_RELU = None
try:
from apex.contrib.index_mul_2d import index_mul_2d
except ImportError as e:
HAS_INDEX_MUL_2D_RELU = False
else:
HAS_INDEX_MUL_2D_RELU = True
@unittest.skipIf(not HAS_INDEX_MUL_2D_RELU, "`apex.contrib.index_mul_2d` is not found.... | 4,377 | 40.695238 | 126 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/test/fmha/test_fmha.py | ###############################################################################
# Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistribution... | 5,412 | 35.086667 | 90 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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)
l... | 1,025 | 32.096774 | 88 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/conv_bias_relu/conv_bias_relu.py | import pdb
import torch
from torch.autograd import gradcheck
from apex import check_cudnn_version_and_warn
import fused_conv_bias_relu
check_cudnn_version_and_warn(__name__, 8400)
class ConvBiasReLU_(torch.autograd.Function):
@staticmethod
@torch.cuda.amp.custom_fwd(cast_inputs=torch.half)
def forward(... | 2,493 | 29.414634 | 93 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/multihead_attn/fast_encdec_multihead_attn_func.py | import torch
import fast_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,
... | 2,974 | 23.385246 | 63 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/multihead_attn/fast_self_multihead_attn_norm_add_func.py | import torch
import fast_multihead_attn
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... | 3,492 | 24.683824 | 71 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/multihead_attn/fast_self_multihead_attn_func.py | import torch
import fast_multihead_attn
class FastSelfAttnFunc(torch.autograd.Function):
@staticmethod
def forward(
ctx,
use_time_mask,
is_training,
heads,
inputs,
input_weights,
output_weights,
input_biases,
output_biases,
pad_m... | 7,679 | 30.47541 | 106 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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_multihea... | 4,258 | 25.61875 | 78 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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_norm_add_func
from apex.no... | 10,097 | 38.6 | 118 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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_w... | 16,844 | 46.184874 | 131 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/multihead_attn/mask_softmax_dropout_func.py | import torch
import fast_multihead_attn
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 = torch.tensor([dropout_prob])
null_tensor = tor... | 2,456 | 36.8 | 119 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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_encdec_attn_norm_add_func
... | 7,546 | 38.931217 | 118 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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... | 14,144 | 44.776699 | 133 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/focal_loss/focal_loss.py | import torch
import focal_loss_cuda
class FocalLoss(torch.autograd.Function):
@staticmethod
def forward(
ctx,
cls_output,
cls_targets_at_level,
num_positives_sum,
num_real_classes,
alpha,
gamma,
label_smoothing=0.0,
):
loss, partial_... | 1,499 | 23.590164 | 89 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/focal_loss/__init__.py | try:
import torch
import focal_loss_cuda
from .focal_loss import focal_loss
del torch
del focal_loss_cuda
del focal_loss
except ImportError as err:
print("apex was installed without --focal_loss flag, apex.contrib.focal_loss is not available")
| 272 | 26.3 | 99 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/layer_norm/layer_norm.py | import torch
from torch.nn import init
from apex._autocast_utils import _cast_if_autocast_enabled
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.c... | 1,737 | 31.185185 | 91 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/optimizers/distributed_fused_adam.py | import collections
import contextlib
import enum
import inspect
import io
import itertools
import threading
import torch
from torch.distributed.distributed_c10d import _get_default_group, _get_global_rank
from apex.multi_tensor_apply import multi_tensor_applier
import amp_C
import distributed_adam_cuda
_FOUND_DEPRECA... | 59,432 | 40.416725 | 96 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/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 |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/optimizers/distributed_fused_lamb.py | import os
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
_make_nccl_premul_sum = getattr(torch.distributed, "_make_nccl_premul_sum", None)
# Ref: https://github.com/pytorch/pytorch/pull/81272
if _make_nc... | 53,733 | 53.441743 | 262 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/peer_memory/peer_halo_exchanger_1d.py | import torch
from apex.contrib.peer_memory import PeerMemoryPool
import peer_memory_cuda as pm
class PeerHaloExchanger1d:
def __init__(self, ranks, rank_in_group, peer_pool, half_halo):
self.peer_group_size = len(ranks)
self.ranks = ranks
self.peer_rank = rank_in_group
self.low_neig... | 3,995 | 59.545455 | 131 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/peer_memory/peer_memory.py | import torch
import numpy as np
import peer_memory_cuda as pm
class PeerMemoryPool(object):
def __init__(self, static_size, dynamic_size, peer_ranks=None):
rank = torch.distributed.get_rank()
world_size = torch.distributed.get_world_size()
ngpus = min(torch.cuda.device_count(), world_size)... | 4,748 | 52.965909 | 165 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/index_mul_2d/index_mul_2d.py | import torch
import fused_index_mul_2d
class IndexMul2d_(torch.autograd.Function):
'''
Currently only support index in dimension 0 with a 2-dimension tensor.
The shape of indexed in1 must be same with in2. Now this kernel does not support broadcast.
The datatype must be float32 or float16.
'''
... | 4,594 | 30.689655 | 115 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/contrib/fmha/fmha.py | ###############################################################################
# Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributio... | 3,577 | 45.467532 | 122 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/utils.py | """Utility functions used by both `pipeline_parallel` and `tensor_parallel`"""
import torch
from apex.transformer import parallel_state
def ensure_divisibility(numerator, denominator):
"""Ensure that numerator is divisible by the denominator."""
assert numerator % denominator == 0, "{} is not divisible by {}... | 1,576 | 31.183673 | 82 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/parallel_state.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 28,418 | 40.609078 | 184 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/arguments.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 50,546 | 51.003086 | 111 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/standalone_gpt.py | # Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by ap... | 3,935 | 34.142857 | 118 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/commons.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 9,603 | 31.228188 | 108 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/global_vars.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 8,862 | 31.704797 | 100 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/standalone_transformer_lm.py | # coding=utf-8
# Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless... | 60,815 | 37.613333 | 136 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/standalone_bert.py | import contextlib
import torch
from apex.transformer import tensor_parallel
from apex.transformer.enums import AttnMaskType
from apex.transformer.enums import ModelType
from apex.transformer.layers import FusedLayerNorm as LayerNorm
from apex.transformer.testing.global_vars import get_args
from apex.transformer.testi... | 9,945 | 37.851563 | 104 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/testing/distributed_test_base.py | import os
import sys
import unittest
from packaging.version import Version, parse
import torch
from torch import distributed as dist
from torch.utils import collect_env
from torch.testing._internal import common_utils
from torch.testing._internal import common_distributed
HAS_TORCH_UCC = None
try:
import torch_uc... | 4,029 | 29.763359 | 127 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/amp/grad_scaler.py | # Copyright (c) 2022, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 5,335 | 43.466667 | 118 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/_data/_batchsampler.py | """BatchSampler implementations for POC of dynamic batch size or rampup_batch_size support.
Implementations are based on https://github.com/NVIDIA/Megatron-LM/blob/bcd605f8570ebeeb0436c115ebbfafc3c5a40ae5/megatron/data/data_samplers.py.
""" # NOQA
import abc
import torch
__all__ = [
"MegatronPretrainingSampler... | 7,203 | 38.801105 | 145 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/layers/layer_norm.py | # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
# NOTE(mkozuki): This file defines two LayerNorm that are compatible with Megatron-LM.
# while avoiding introducing the breaking change of `"sequence_parallel_enabled"` attribute into apex.normalization.FusedLayerNorm
# and apex.contrib.layer_norm.FastLaye... | 3,456 | 33.57 | 141 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/_timers.py | import time
import torch
class _Timer:
"""Timer."""
def __init__(self, name):
self.name_ = name
self.elapsed_ = 0.0
self.started_ = False
self.start_time = time.time()
def start(self):
"""Start the timer."""
assert not self.started_, "timer has already be... | 2,538 | 29.22619 | 88 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/utils.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 12,563 | 34.094972 | 102 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/p2p_communication.py | # coding=utf-8
# Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless... | 23,172 | 39.022453 | 199 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/schedules/fwd_bwd_pipelining_with_interleaving.py | from typing import List, Union, Optional, Sequence
import warnings
import torch
from apex.transformer import parallel_state
from apex.transformer.pipeline_parallel import p2p_communication
from apex.transformer.pipeline_parallel.schedules.common import Batch
from apex.transformer.pipeline_parallel.schedules.common im... | 18,475 | 43.413462 | 119 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/schedules/fwd_bwd_no_pipelining.py | import contextlib
from typing import List, Union, Optional
import torch
from apex.transformer.pipeline_parallel.utils import listify_model
from apex.transformer.pipeline_parallel.utils import get_num_microbatches
from apex.transformer.pipeline_parallel.utils import get_kth_microbatch
from apex.transformer.pipeline_pa... | 4,663 | 36.312 | 103 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/schedules/common.py | from typing import Any, Callable, Dict, List, Tuple, Union, Optional, Sequence
import torch
from torch.autograd.variable import Variable
from apex.normalization.fused_layer_norm import FusedLayerNorm
from apex.transformer import parallel_state
from apex.transformer.enums import ModelType
from apex.transformer.pipelin... | 15,542 | 37.954887 | 136 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/pipeline_parallel/schedules/fwd_bwd_pipelining_without_interleaving.py | import contextlib
from typing import Union, List, Optional, Sequence
import warnings
import torch
from apex.transformer import parallel_state
from apex.transformer.enums import ModelType
from apex.transformer.pipeline_parallel import p2p_communication
from apex.transformer.pipeline_parallel.p2p_communication import F... | 20,328 | 38.245174 | 152 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/memory.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless r... | 5,203 | 33.236842 | 85 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/mappings.py | # coding=utf-8
# Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless... | 10,372 | 33.009836 | 111 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/cross_entropy.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 6,446 | 46.755556 | 115 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/utils.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 2,396 | 35.876923 | 112 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/data.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 4,047 | 31.910569 | 85 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/layers.py | # coding=utf-8
# Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless... | 28,979 | 36.106274 | 141 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/tensor_parallel/random.py | # coding=utf-8
# Copyright (c) 2021-22, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless... | 11,852 | 36.990385 | 106 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/transformer/functional/fused_softmax.py | # coding=utf-8
# Copyright (c) 2021, 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 the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless re... | 9,931 | 36.479245 | 141 | py |
TokenMixup | TokenMixup-main/experiments/apex_copy/build/lib/apex/mlp/mlp.py | from copy import copy
import math
import torch
from torch import nn
from apex._autocast_utils import _cast_if_autocast_enabled
import mlp_cuda
class MlpFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, bias, activation, *args):
output = mlp_cuda.forward(bias, activation, args)
... | 2,757 | 30.701149 | 115 | py |
TokenMixup | TokenMixup-main/experiments/cct/eval.py | ###############################################################################
# This contains implementation of CCT + TokenMixup #
# Code modified from https://github.com/SHI-Labs/Compact-Transformers #
# Copyright MLV Lab @ Korea University #
... | 12,062 | 37.417197 | 130 | py |
TokenMixup | TokenMixup-main/experiments/cct/train.py | ###############################################################################
# This contains implementation of CCT + TokenMixup #
# Code modified from https://github.com/SHI-Labs/Compact-Transformers #
# Copyright MLV Lab @ Korea University #
... | 44,581 | 46.989236 | 144 | py |
TokenMixup | TokenMixup-main/experiments/cct/src/cvt.py | from torch.hub import load_state_dict_from_url
import torch.nn as nn
from .utils.transformers import TransformerClassifier
from .utils.tokenizer import Tokenizer
from .utils.helpers import pe_check
try:
from timm.models.registry import register_model
except ImportError:
from .registry import register_model
mo... | 7,316 | 35.954545 | 101 | py |
TokenMixup | TokenMixup-main/experiments/cct/src/vit.py | from torch.hub import load_state_dict_from_url
import torch.nn as nn
from .utils.transformers import TransformerClassifier
from .utils.tokenizer import Tokenizer
from .utils.helpers import pe_check
try:
from timm.models.registry import register_model
except ImportError:
from .registry import register_model
mo... | 7,375 | 37.217617 | 101 | py |
TokenMixup | TokenMixup-main/experiments/cct/src/cct.py | from torch.hub import load_state_dict_from_url
import torch.nn as nn
from .utils.transformers import TransformerClassifier
from .utils.tokenizer import Tokenizer
from .utils.helpers import pe_check, fc_check
try:
from timm.models.registry import register_model
except ImportError:
from .registry import register... | 14,777 | 40.745763 | 127 | py |
TokenMixup | TokenMixup-main/experiments/cct/src/utils/transformers.py | ###############################################################################
# This contains implementation of CCT + TokenMixup #
# Code modified from https://github.com/SHI-Labs/Compact-Transformers #
# Copyright MLV Lab @ Korea University #
... | 18,230 | 39.876682 | 152 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.