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 |
|---|---|---|---|---|---|---|
RegularizedBN | RegularizedBN-main/fairseq/__init__.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.
__all__ = ['pdb']
__version__ = '0.9.0'
import sys
# backwards compatibility to support `from fairseq.meters import AverageMeter`
from fairs... | 885 | 29.551724 | 78 | py |
RegularizedBN | RegularizedBN-main/fairseq/search.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
from typing import Optional, List
import torch
import torch.nn as nn
from torch import Tensor
from fairseq.token_generation_cons... | 27,939 | 40.0279 | 114 | py |
RegularizedBN | RegularizedBN-main/fairseq/quantization_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 logging
from fairseq.modules.quantization import pq, quantization_options, scalar
logger = logging.getLogger(__name__)
def quantiz... | 5,440 | 37.048951 | 88 | py |
RegularizedBN | RegularizedBN-main/fairseq/nan_detector.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 logging
import torch
logger = logging.getLogger(__name__)
class NanDetector:
"""
Detects the first NaN or Inf in forward... | 3,041 | 32.065217 | 119 | py |
RegularizedBN | RegularizedBN-main/fairseq/iterative_refinement_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.
from collections import namedtuple
import torch
import numpy as np
from fairseq import utils
DecoderOut = namedtuple('IterativeRefinementD... | 12,517 | 38.36478 | 122 | py |
RegularizedBN | RegularizedBN-main/fairseq/trainer.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.
"""
Train a network across multiple GPUs.
"""
import contextlib
from itertools import chain
import logging
import sys
import time
from typing... | 41,387 | 37.608209 | 117 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/transformer_sentence_encoder_layer.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.
from typing import Callable, Optional
import torch
import torch.nn as nn
from fairseq import utils
from fairseq.modules import (
LayerNo... | 4,160 | 28.721429 | 112 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/learned_positional_embedding.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.
from typing import Dict, Optional
import torch
import torch.nn as nn
import torch.nn.functional as F
from fairseq import utils
from torch imp... | 2,259 | 35.451613 | 94 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/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 math
import torch
from .multihead_attention import MultiheadAttention
class SparseMultiheadAttention(MultiheadAttention):
""" Spa... | 4,525 | 42.104762 | 100 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/statistics_utils.py | import numpy as np
import torch
from scipy import io
#save: save statistics in a file
#record: only record
def save_residual_proportion(self, x, residual, module):
# T,B,C
assert module in ['att','ffn'], "wrong module in residual proportion!"
if not self.training or not self.record_residual_proportion:
... | 14,971 | 42.397101 | 115 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/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 math
from typing import Dict, Optional, Tuple
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from torch.nn ... | 23,984 | 40.070205 | 110 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/transpose_last.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.
"""
transpose last 2 dimensions of the input
"""
import torch.nn as nn
class TransposeLast(nn.Module):
def __init__(self, deconstruct_id... | 550 | 25.238095 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm_select.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.
from .norm.mask_layernorm3d import MaskLayerNorm3d
from .norm.mask_batchnorm3d import MaskBatchNorm3d
from .norm.mask_powernorm3d import MaskP... | 2,685 | 40.323077 | 155 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/same_pad.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.
from torch import nn
class SamePad(nn.Module):
def __init__(self, kernel_size):
super().__init__()
self.remove = kernel... | 432 | 21.789474 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/multihead_attention_simple.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
from typing import Dict, Optional, Tuple
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from torch.nn ... | 13,929 | 37.480663 | 161 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/linearized_convolution.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 torch.nn.functional as F
from fairseq import utils
from .conv_tbc import ConvTBC
from fairseq.incremental_decoding_utils ... | 4,261 | 41.19802 | 95 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/downsampled_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 math
import torch
import torch.nn as nn
import torch.nn.functional as F
from fairseq.modules.scalar_bias import scalar_bias
from fai... | 9,863 | 37.381323 | 106 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/multihead_attention_relative.py | import torch
from torch import nn
import torch.nn.functional as F
import math
class RelativeEmbedding(nn.Module):
def forward(self, input):
"""Input is expected to be of size [bsz x seqlen].
"""
bsz, seq_len = input.size()
max_pos = self.padding_idx + seq_len
if max_pos > s... | 6,946 | 35.952128 | 118 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quant_noise.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 torch.nn as nn
def quant_noise(module, p, block_size):
"""
Wraps modules and applies quantization noise to the w... | 3,666 | 39.296703 | 110 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/gelu.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.
"""
See "Gaussian Error Linear Units (GELUs)" by Dan Hendrycks and Kevin Gimpel with
the corresponding GitHub repo: https://github.com/hendryck... | 706 | 26.192308 | 87 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/statistics_init.py | import numpy as np
import torch
from scipy import io
from .statistics_utils import save_forward_backward_weight_norm
#need to define self.prefix, self.id before initializing statistics
def init_residual_proportion(self, args):
self.record_residual_proportion = args.record_residual_proportion
if self.record_re... | 8,439 | 43.188482 | 144 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/positional_embedding.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.nn as nn
from .learned_positional_embedding import LearnedPositionalEmbedding
from .sinusoidal_positional_embedding import Sinuso... | 1,286 | 38 | 83 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fairseq_dropout.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 logging
from typing import List, Optional
import torch.nn as nn
import torch.nn.functional as F
logger = logging.getLogger(__name__)... | 1,687 | 30.849057 | 83 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/cross_entropy.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 logging
import torch
import torch.nn.functional as F
logger = logging.getLogger(__name__)
def _cross_entropy_pytorch(logits, targe... | 1,650 | 30.75 | 82 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/adaptive_input.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
from torch import nn
from fairseq.modules.quant_noise import quant_noise
from typing import List
class AdaptiveInput(nn.Modul... | 2,514 | 30.835443 | 92 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/gumbel_vector_quantizer.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 torch.nn as nn
import torch.nn.functional as F
class GumbelVectorQuantizer(nn.Module):
def __init__(
self,
... | 6,792 | 33.135678 | 117 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/vggblock.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.
from __future__ import absolute_import, division, print_function, unicode_literals
from collections.abc import Iterable
from itertools import... | 4,057 | 33.683761 | 88 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/character_token_embedder.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 logging
from typing import List, Tuple
import torch
from torch import nn
import torch.nn.functional as F
from fairseq.data import Dic... | 6,846 | 32.4 | 106 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/unfold.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.nn.functional as F
def unfold1d(x, kernel_size, padding_l, pad_value=0):
'''unfold T x B x C to T x B x C x K'''
if ker... | 570 | 30.722222 | 91 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fp32_group_norm.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.
"""
Layer norm done in fp32 (for fp16 training)
"""
import torch.nn as nn
import torch.nn.functional as F
class Fp32GroupNorm(nn.GroupNorm):... | 727 | 27 | 69 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/adaptive_softmax.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 operator
import functools
import torch
import torch.nn.functional as F
from fairseq.modules.quant_noise import quant_noise
from fairse... | 7,945 | 35.95814 | 137 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fc_select.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.nn as nn
from .fc.wn import CWN
from .fc.conv import Conv1d
from .fc.dropout_fc import DropoutFC
from .fc.oni_fc import ONI_Linea... | 2,654 | 38.044118 | 113 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dropout_select.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.nn as nn
from .noise_dropout import NoiseDropout
def parse_dropout(dropout_type):
args = dropout_type.split("_")
return ... | 642 | 25.791667 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/sparse_transformer_sentence_encoder_layer.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.
from fairseq.modules import TransformerSentenceEncoderLayer
from fairseq.modules.sparse_multihead_attention import SparseMultiheadAttention
... | 1,490 | 31.413043 | 80 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/conv_tbc.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
from torch.nn.modules.utils import _single
class ConvTBC(torch.nn.Module):
"""1D convolution over an input of shape (time x... | 1,356 | 35.675676 | 90 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/transformer_layer.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.
from typing import Dict, List, Optional
import torch
import torch.nn as nn
from torch.serialization import save
from fairseq import utils
fro... | 24,120 | 40.162116 | 125 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/beamable_mm.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 torch.nn as nn
class BeamableMM(nn.Module):
"""This module provides an optimized MM for beam decoding with attention... | 1,779 | 36.083333 | 80 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/__init__.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.
from .adaptive_input import AdaptiveInput
from .adaptive_softmax import AdaptiveSoftmax
from .beamable_mm import BeamableMM
from .character_to... | 2,892 | 34.716049 | 79 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/multihead_attention_ori.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
from typing import Dict, Optional, Tuple
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from torch.nn ... | 19,130 | 39.023013 | 103 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/layer_norm.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 torch.nn as nn
import torch.nn.functional as F
try:
from apex.normalization import FusedLayerNorm as _FusedLayerNorm... | 1,499 | 29 | 81 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/kmeans_vector_quantizer.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 torch.nn as nn
from fairseq.modules import Fp32GroupNorm
class KmeansVectorQuantizer(nn.Module):
def __init__(
... | 4,248 | 31.937984 | 89 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/layer_drop.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.
"""
LayerDrop as described in https://arxiv.org/abs/1909.11556.
"""
import torch
import torch.nn as nn
class LayerDropModuleList(nn.ModuleLi... | 1,409 | 30.333333 | 71 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamic_crf_layer.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.
"""
This file is to re-implemented the low-rank and beam approximation of CRF layer
Proposed by:
Sun, Zhiqing, et al.
Fast Structured Decodin... | 7,676 | 40.497297 | 99 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/scalar_bias.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
class ScalarBias(torch.autograd.Function):
"""
Adds a vector of scalars, used in self-attention mechanism to allow
... | 888 | 26.78125 | 74 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/transformer_sentence_encoder.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.
from typing import Optional, Tuple
import torch
import torch.nn as nn
from fairseq.modules import (
FairseqDropout,
LayerDropModuleLi... | 9,720 | 33.842294 | 90 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/grad_multiply.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
class GradMultiply(torch.autograd.Function):
@staticmethod
def forward(ctx, x, scale):
ctx.scale = scale
... | 442 | 22.315789 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/sparse_transformer_sentence_encoder.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.nn as nn
from fairseq.modules import TransformerSentenceEncoder
from fairseq.modules.sparse_transformer_sentence_encoder_layer im... | 2,965 | 36.075 | 107 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/activation_select.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.nn as nn
def parse_activation(activation_type):
args = activation_type.split("_")
return args
def ActivationSelect(act... | 1,317 | 28.288889 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/sinusoidal_positional_embedding.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
from typing import Any, Optional
import torch
import torch.onnx.operators
from fairseq import utils
from torch import Tensor, nn
... | 3,880 | 35.613208 | 87 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/lightweight_convolution.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 torch.nn as nn
import torch.nn.functional as F
from fairseq import utils
from fairseq.modules.unfold import unfold1d
from... | 10,496 | 39.844358 | 104 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamic_convolution.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 torch.nn as nn
import torch.nn.functional as F
from fairseq import utils
from .unfold import unfold1d
from fairseq.increm... | 11,057 | 43.95122 | 132 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/noise_dropout.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 logging
from typing import List, Optional
import torch.nn as nn
import torch.nn.functional as F
import torch
logger = logging.getLogg... | 700 | 22.366667 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/my_attention.py | 0 | 0 | 0 | py | |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_powernorm3d.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskBatchNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torch.nn.modules._functions import SyncBatchNorm as sync_batch_norm
... | 9,403 | 38.512605 | 141 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_anchornorm.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskBatchNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.nn.parameter import Parameter
import numpy as np
from scipy import io
__all__ = ['MaskAnchorNorm']
de... | 2,951 | 32.168539 | 103 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_groupnorm.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : groupnorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
def tile(a, repeats, dim):
"""
Substitute for numpy's repeat function. Taken from https://discuss.pytorch.org... | 7,391 | 43 | 131 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_layernorm3d.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskBatchNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torch.nn.modules._functions import SyncBatchNorm as sync_batch_norm
... | 2,211 | 32.515152 | 83 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_groupscale.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskPowerNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
__all__ = ['MaskGruopScale']
def _sum_ft(tensor):
"""sum over the first and last dimention"""
return ten... | 6,418 | 34.076503 | 119 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_identity.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskBatchNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
__all__ = ['MaskIdentity']
class MaskIdentityNorm(nn.Module):
"""
"""
def __init__(self, num_featur... | 790 | 23.71875 | 62 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/norm/mask_batchnorm3d.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : MaskBatchNorm.py
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torch.nn.modules._functions import SyncBatchNorm as sync_batch_norm
... | 16,604 | 41.686375 | 141 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamicconv_layer/cuda_function_gen.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.
def gen_forward():
kernels = [3, 5, 7, 15, 31, 63, 127, 255]
blocks = [32, 64, 128, 256]
head = """
/**
* Copyright (c) Facebo... | 6,866 | 29.65625 | 126 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamicconv_layer/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.
from setuptools import setup
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
setup(
name='dyna... | 613 | 24.583333 | 67 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamicconv_layer/__init__.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.
from .dynamicconv_layer import DynamicconvLayer # noqa
| 234 | 32.571429 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/dynamicconv_layer/dynamicconv_layer.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
from torch import nn
from torch.autograd import Function
import torch.nn.functional as F
import dynamicconv_cuda
from fairseq im... | 8,719 | 39.184332 | 129 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fc/oni_fc.py | """
Orthogonalization by Newton’s Iteration
"""
import torch.nn
import torch.nn.functional as F
from torch.nn import Parameter
from torch.autograd import Variable
from typing import List
from torch.autograd.function import once_differentiable
__all__ = ['WN_Conv2d', 'OWN_Conv2d', 'ONI_Conv2d','ONI_ConvTranspose2d',
... | 12,549 | 41.398649 | 146 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fc/dropout_fc.py | import torch
import torch.nn as nn
import torch.nn.functional as F
__all__ = ['DropoutFC']
class DropoutFC(nn.Linear):
def __init__(self, in_features, out_features, bias=True, dropout=0, scale=1.0):
super(DropoutFC, self).__init__(in_features, out_features, bias)
print('DropoutFC dropout:{}, sc... | 940 | 28.40625 | 83 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fc/conv.py | import torch
from torch import nn
import torch.nn.functional as F
class Conv1d(nn.Conv1d):
def __init__(self,in_channels, out_channels, kernel_size=3, stride=1):
self.padding = (kernel_size-1)//2
self.stride = stride
super(Conv1d, self).__init__(in_channels, out_channels, kernel_size, stride=stride,padding=self.... | 674 | 38.705882 | 112 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/fc/wn.py | import torch.nn
import torch.nn.functional as F
from torch.nn import Parameter
from torch.autograd import Variable
from typing import List
from torch.autograd.function import once_differentiable
__all__ = ['CWN']
# norm funcitons--------------------------------
class CWNorm(torch.nn.Module):
def forward(self, ... | 3,164 | 38.5625 | 110 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/__init__.py | 0 | 0 | 0 | py | |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/quantization_options.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.
def parse_config_yaml(yaml_data):
# Initialize to default options.
quantization_options = {
"n_centroids": {
"Lin... | 1,647 | 35.622222 | 84 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/em.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 os
import random
import logging
from collections import Counter
import torch
class EM:
"""
EM algorithm used to quantize the... | 7,333 | 33.59434 | 92 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/pq.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.
from .em import EM, EmptyClusterResolveError
class PQ(EM):
"""
Quantizes the layer weights W with the standard Product Quantization
... | 4,292 | 32.27907 | 87 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/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 logging
import re
from operator import attrgetter, itemgetter
import numpy as np
import torch.nn as nn
import torch.distributed as dis... | 11,605 | 33.541667 | 110 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/__init__.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.
from .utils import SizeTracker, quantize_model_ # NOQA
| 234 | 32.571429 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/modules/qlinear.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 torch.nn as nn
import torch.nn.functional as F
class PQLinear(nn.Module):
"""
Quantized counterpart of nn.Linear... | 2,547 | 34.388889 | 86 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/modules/qconv.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 numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
class PQConv2... | 4,245 | 35.603448 | 87 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/modules/qemb.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 torch.nn as nn
import torch.nn.functional as F
class PQEmbedding(nn.Module):
"""
Quantized counterpart of nn.Emb... | 3,515 | 38.954545 | 103 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/pq/modules/__init__.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.
from .qconv import PQConv2d # NOQA
from .qlinear import PQLinear # NOQA
from .qemb import PQEmbedding # NOQA
| 290 | 31.333333 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/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 logging
from operator import attrgetter
import torch.nn as nn
import torch.distributed as dist
from ..pq.utils import get_layers, att... | 2,323 | 33.176471 | 107 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/__init__.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.
from .utils import quantize_model_ # NOQA
| 221 | 30.714286 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/ops.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
def emulate_int(w, bits, method, scale=None, zero_point=None):
q = globals()[f"emulate_int{bits}_{method}"]
return q(w,... | 1,669 | 33.791667 | 90 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/modules/qlinear.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 torch.nn as nn
import torch.nn.functional as F
from ..ops import emulate_int
class IntLinear(nn.Module):
"""
Qu... | 3,596 | 31.405405 | 101 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/modules/qconv.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 torch.nn.functional as F
from torch.nn.modules.conv import _ConvNd
from torch.nn.modules.utils import _pair
from ..ops im... | 4,415 | 29.040816 | 95 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/modules/qemb.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 torch.nn as nn
import torch.nn.functional as F
from ..ops import emulate_int
class IntEmbedding(nn.Module):
"""
... | 4,771 | 34.879699 | 103 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/modules/__init__.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.
from .qconv import IntConv2d # NOQA
from .qlinear import IntLinear # NOQA
from .qemb import IntEmbedding # NOQA
from .qact import Activatio... | 339 | 33 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/quantization/scalar/modules/qact.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
from ..ops import emulate_int
class ActivationQuantizer:
"""
Fake scalar quantization of the activations using a forwa... | 3,033 | 36.45679 | 87 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/lightconv_layer/cuda_function_gen.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.
def gen_forward():
kernels = [3, 5, 7, 15, 31, 63, 127, 255]
seqs = [32 * x for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,... | 9,642 | 32.251724 | 141 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/lightconv_layer/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.
from setuptools import setup
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
setup(
name='ligh... | 545 | 25 | 67 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/lightconv_layer/lightconv_layer.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
from torch import nn
from torch.autograd import Function
import torch.nn.functional as F
import lightconv_cuda
from fairseq impo... | 4,679 | 35 | 104 | py |
RegularizedBN | RegularizedBN-main/fairseq/modules/lightconv_layer/__init__.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.
from .lightconv_layer import LightconvLayer # noqa
| 230 | 32 | 65 | py |
RegularizedBN | RegularizedBN-main/fairseq/logging/progress_bar.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.
"""
Wrapper around various loggers and progress bars (e.g., tqdm).
"""
import atexit
import json
import logging
import os
import sys
from col... | 11,082 | 29.786111 | 89 | py |
RegularizedBN | RegularizedBN-main/fairseq/logging/metrics.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.
"""
A standalone module for aggregating metrics.
Metrics can be logged from anywhere using the `log_*` functions defined
in this module. The l... | 9,325 | 30.938356 | 81 | py |
RegularizedBN | RegularizedBN-main/fairseq/logging/__init__.py | 0 | 0 | 0 | py | |
RegularizedBN | RegularizedBN-main/fairseq/logging/meters.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 bisect
from collections import OrderedDict
import time
from typing import Dict, Optional
try:
import torch
def type_as(a, b):... | 7,885 | 26.477352 | 79 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/fairseq_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 inspect
from typing import Any, Dict, List
from torch.nn.modules.loss import _Loss
from fairseq import metrics, utils
class Fairseq... | 4,258 | 34.491667 | 79 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/nat_loss.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.nn.functional as F
import torch
from torch import Tensor
from fairseq import metrics, utils
from fairseq.criterions... | 6,238 | 34.856322 | 98 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/wav2vec_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 metrics, utils
from fairseq.criterions import FairseqCriterion,... | 6,437 | 39.490566 | 126 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/legacy_masked_lm.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 metrics, utils
from fairseq.criterions import FairseqCriterion,... | 6,769 | 43.248366 | 136 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/label_smoothed_cross_entropy_with_alignment.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
from fairseq import metrics, utils
from fairseq.criterions import register_criterion
from .label_smoothed_cross_entropy import L... | 4,393 | 43.836735 | 114 | py |
RegularizedBN | RegularizedBN-main/fairseq/criterions/adaptive_loss.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.nn.functional as F
from fairseq import metrics, utils
from fairseq.criterions import FairseqCriterion, register_cri... | 3,981 | 38.039216 | 105 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.