python_code
stringlengths
0
992k
repo_name
stringlengths
8
46
file_path
stringlengths
5
162
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] from io import open from setuptools import find_packages, setup setup( name="torchscale", version="0.1.1", author="TorchScale Team", author_email="Shuming.Ma@microsoft.com", description="Transformers at any ...
KosmosX-API-main
kosmosX/torchscale/setup.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/torchscale/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch import torch.nn as nn def fixed_pos_embedding(x): seq_len, dim = x.shape inv_freq = 1.0 / (10000 ** (torch.arange(0, dim) / dim)) sinusoid_inp = ( torch.einsum("i , j -> i j", torch.arange(0, se...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/sope_relative_position.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import copy import torch import torch.nn as nn def MultiwayWrapper(args, module, dim=0): if args.multiway: return MultiwayNetwork(module, dim=dim) return module def set_split_position(position): def apply...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/multiway_network.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import math import torch import torch.nn.functional as F from apex.normalization import FusedLayerNorm as LayerNorm from torch import nn from .multiway_network import MultiwayWrapper from xformers.ops import memory_efficient_at...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/multihead_attention.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import math import torch import torch.nn as nn class RelativePositionBias(nn.Module): def __init__( self, bidirectional=True, num_buckets=32, max_distance=128, n_heads=12 ): super().__init__() s...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/relative_position_bias.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch import torch.nn as nn import torch.nn.functional as F class VisionLanguageEmbedding(nn.Module): def __init__(self, text_embed, vision_embed): super().__init__() self.text_embed = text_embed ...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/embedding.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch.nn as nn from timm.models.layers import drop_path class DropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" def __init__(self, drop_prob=Non...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/droppath.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/torchscale/component/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch import torch.nn as nn import torch.nn.functional as F from apex.normalization import FusedLayerNorm as LayerNorm class set_torch_seed(object): def __init__(self, seed): assert isinstance(seed, int) ...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/feedforward_network.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/torchscale/component/xmoe/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. # NOTE: This is a mirror of th...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/xmoe/moe_layer.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # # This source code is licensed under the BSD license found in the # LICENSE file in the root directory of this source tree. # Implementation of Top2Gating...
KosmosX-API-main
kosmosX/torchscale/torchscale/component/xmoe/routing.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import math import numpy as np import torch import torch.nn as nn from apex.normalization import FusedLayerNorm as LayerNorm from fairscale.nn import checkpoint_wrapper, wrap from torchscale.architecture.utils import init_bert_...
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/decoder.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] class EncoderConfig(object): def __init__(self, **kwargs): self.encoder_embed_dim = kwargs.pop("encoder_embed_dim", 768) self.encoder_attention_heads = kwargs.pop("encoder_attention_heads", 12) self.e...
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/config.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch.nn as nn from torchscale.architecture.decoder import Decoder from torchscale.architecture.encoder import Encoder class EncoderDecoder(nn.Module): def __init__( self, args, encoder_embed...
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/encoder_decoder.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import math import numpy as np import torch import torch.nn as nn from apex.normalization import FusedLayerNorm as LayerNorm from fairscale.nn import checkpoint_wrapper, wrap from torchscale.architecture.utils import init_bert_...
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/encoder.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch.nn as nn from torchscale.component.multihead_attention import MultiheadAttention from torchscale.component.multiway_network import MultiwayNetwork def init_bert_params(module): def normal_(data): data....
KosmosX-API-main
kosmosX/torchscale/torchscale/architecture/utils.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch import torch.nn as nn from torchscale.architecture.encoder import Encoder from torchscale.component.embedding import ( PositionalEmbedding, TextEmbedding, VisionEmbedding, ) from torchscale.component.mul...
KosmosX-API-main
kosmosX/torchscale/torchscale/model/BEiT3.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/torchscale/model/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/examples/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # flake8: noqa import models import tasks from fairseq_cli.generate import cli_main if __name__ == "__main__": cli_main()
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/generate.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # flake8: noqa import models import tasks from fairseq_cli.interactive import cli_main if __name__ == "__main__": cli_main()
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/interactive.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # flake8: noqa import models import tasks from fairseq_cli.train import cli_main if __name__ == "__main__": cli_main()
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/train.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import json import logging import os from argparse import Namespace # 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 t...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/pretraining.py
import os import json from argparse import Namespace import torch from fairseq import utils from fairseq.data import Dictionary from fairseq.tasks import register_task from fairseq.tasks.language_modeling import LanguageModelingTask, LanguageModelingConfig from fairseq.data.encoders.gpt2_bpe import GPT2BPE from datacl...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/gpt_base.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import argparse import importlib import os # register dataclass TASK_DATACLASS_REGISTRY = {} TASK_REGISTRY = {} TASK_CLASS_NAMES = set() # automatically import any Python files in the tasks/ directory tasks_dir = os.path.dirnam...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/__init__.py
import os import json from argparse import Namespace import torch from fairseq import utils from fairseq.data import Dictionary from fairseq.tasks import register_task from fairseq.tasks.language_modeling import LanguageModelingTask from fairseq.data.encoders.gpt2_bpe import GPT2BPE from dataclasses import dataclass, ...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/vl_gpt_base.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import torch from infinibatch.iterators import CheckpointableIterator from . import utils from .utils import ConcatIterator class BaseBatchGen(CheckpointableIterator): """ This is a base class for batch generators that...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/basic_loader.py
import sys,os sys.path.append(os.getcwd()) from typing import NamedTuple import os import argparse import json import sentencepiece as spm # from fairseq.data.dictionary import Dictionary # from laion_loader import LaionLoader def image_code_to_token(code): return "<image{}>".format(code) def to_word(item, dict...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/laion_loader_test.py
import sys,os sys.path.append(os.getcwd()) from typing import NamedTuple import os import argparse import json import sentencepiece as spm from fairseq.data.dictionary import Dictionary from wild_loader import WildLoader def image_code_to_token(code): return "<image{}>".format(code) def to_word(item, diction...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/wild_loader_test_2.py
IMAGE_KEY="Images" TEXT_KEY="Extracted" import os, json, random, re max_image_num = 5 tokens_per_sample = 2048 from spacy.lang.en import English import sentencepiece as spm nlp_sentencizer = English() nlp_sentencizer.add_pipe("sentencizer") spm_tokenizer = spm.SentencePieceProcessor(model_file=r"C:\Users\shaohanh\D...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/wild_loader_test.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/__init__.py
import json import os import random import re from infinibatch import iterators from tasks.data.lm_loader import LMLoader from tasks.data.utils import NativeCheckpointableIterator, WeightIterator, BOI_SYMBOL, EOI_SYMBOL, image_code_to_token from fairseq.data.encoders.gpt2_bpe import GPT2BPE from spacy.lang.en import E...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/wild_loader.py
import os import numpy as np import json from infinibatch import iterators from .basic_loader import BaseBatchGen from .utils import EOL_SYMBOL from .utils import safe_getattr class LMLoader(BaseBatchGen): def __init__( self, args, dataset, dictionary, ...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/lm_loader.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import collections from random import Random from typing import Dict, Iterable, Optional import numpy as np from infinibatch import iterators EOL_SYMBOL = "</line>" BOI_SYMBOL = "<image>" EOI_SYMBOL = "</image>" def apply_to...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/utils.py
import json import os import random from infinibatch import iterators from tasks.data.lm_loader import LMLoader from tasks.data.utils import NativeCheckpointableIterator, WeightIterator, BOI_SYMBOL, EOI_SYMBOL, image_code_to_token from fairseq.data.encoders.gpt2_bpe import GPT2BPE class LaionLoader(LMLoader): de...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/laion_loader.py
import json import os from infinibatch import iterators from .lm_loader import LMLoader from .utils import NativeCheckpointableIterator, WeightIterator, EOL_SYMBOL from fairseq.data.encoders.gpt2_bpe import GPT2BPE class SpmLmLoader(LMLoader): def _tokenize(self): multilingual_iters = [] weights ...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/spm_lm_loader.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import copy import itertools import os import numpy as np from infinibatch import iterators from .basic_loader import BaseBatchGen from .utils import NativeCheckpointableIterator, WeightIterator class MLMLoader(BaseBatchGen):...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/tasks/data/mlm_loader.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import math import warnings import torch import torch.distributed as dist from fairseq.utils import multi_tensor_l2norm_available, multi_tensor_total_norm @torch.no_grad() def clip_grad_norm_( params, max_norm, moe_expert_...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/utils/sparse_clip.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details]
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/utils/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # 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 dataclasses import dataclass, f...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/models/language_modeling.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import argparse import importlib import os MODEL_REGISTRY = {} MODEL_DATACLASS_REGISTRY = {} ARCH_MODEL_REGISTRY = {} ARCH_MODEL_NAME_REGISTRY = {} ARCH_MODEL_INV_REGISTRY = {} ARCH_CONFIG_REGISTRY = {} # automatically import a...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/models/__init__.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] # 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 Dict, List, Optio...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/models/machine_translation.py
# Copyright (c) 2022 Microsoft # Licensed under The MIT License [see LICENSE for details] import logging from dataclasses import dataclass, field from typing import Optional import torch import torch.nn as nn import torch.nn.functional as F from apex.normalization import FusedLayerNorm as LayerNorm from fairseq impor...
KosmosX-API-main
kosmosX/torchscale/examples/fairseq/models/bert.py
KosmosX-API-main
kosmosX/unilm/__init__.py
import logging import os from dataclasses import dataclass, field import numpy as np import torch from fairseq import utils from fairseq.data import ( FairseqDataset, AppendTokenDataset, Dictionary, IdDataset, NestedDictionaryDataset, NumelDataset, PadDataset, StripTokenDataset, T...
KosmosX-API-main
kosmosX/unilm/tasks/generation_obj.py
import os from fairseq.tasks import import_tasks tasks_dir = os.path.dirname(__file__) import_tasks(tasks_dir, "unilm.tasks")
KosmosX-API-main
kosmosX/unilm/tasks/__init__.py
from dataclasses import dataclass, field import logging import copy import torch import torch.nn as nn import torch.nn.functional as F from fairseq import checkpoint_utils from fairseq import utils from fairseq.utils import safe_getattr from fairseq.models import ( BaseFairseqModel, register_model, register...
KosmosX-API-main
kosmosX/unilm/models/unigpt.py
import os from fairseq.models import import_models models_dir = os.path.dirname(__file__) import_models(models_dir, "unilm.models")
KosmosX-API-main
kosmosX/unilm/models/__init__.py
import torch import torch.nn as nn from fairseq.modules import MultiheadAttention from fairseq import utils def build_connector(args, input_dim, output_dim): if isinstance(args, str): connector_name = args else: connector_name = args.text_connector if hasattr(args, "text_connector") else args...
KosmosX-API-main
kosmosX/unilm/models/connector.py
from dataclasses import dataclass, field from typing import Optional from torch import Tensor import torch from fairseq import distributed_utils from fairseq.utils import safe_getattr from fairseq.models import ( register_model, register_model_architecture, ) from fairseq.models.transformer_lm import ( Transf...
KosmosX-API-main
kosmosX/unilm/models/gpt.py
KosmosX-API-main
kosmosX/unilm/models/vl/__init__.py
# TODO load openai model
KosmosX-API-main
kosmosX/unilm/models/vl/openai.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, List, Optional import sys import torch import torch.nn as nn from fairseq import search from fairseq.mod...
KosmosX-API-main
kosmosX/unilm/models/vl/vlm_generator.py
import logging import os import torch from copy import deepcopy from typing import Callable from torch import nn from torch.nn import functional as F from open_clip.model import CLIPVisionCfg, QuickGELU, TimmModel, ModifiedResNet, to_2tuple, LayerNorm, Transformer from open_clip.factory import _MODEL_CONFIGS, list_mod...
KosmosX-API-main
kosmosX/unilm/models/vl/clip.py
KosmosX-API-main
kosmosX/unilm/data/__init__.py
import numpy as np from random import Random from typing import Dict, Iterable, Optional import collections from infinibatch import iterators EOD_SYMBOL = "</doc>" BOI_SYMBOL = "<image>" EOI_SYMBOL = "</image>" EOC_SYMBOL = "</chunk>" EOL_SYMBOL = "</line>" GRD_SYMBOL="<grounding>" BOP_SYMBOL="<phrase>" EOP_SYMBOL="<...
KosmosX-API-main
kosmosX/unilm/data/utils.py
from dataclasses import dataclass, field import math from omegaconf import II import torch.nn.functional as F from fairseq import metrics, utils from fairseq.criterions import FairseqCriterion, register_criterion from fairseq.dataclass import FairseqDataclass LOSS_NAMES = ["gpt", "image_wild", "image_laion"] @datacl...
KosmosX-API-main
kosmosX/unilm/criterions/unigpt.py
import importlib import os # automatically import any Python files in the criterions/ directory for file in sorted(os.listdir(os.path.dirname(__file__))): if file.endswith(".py") and not file.startswith("_"): file_name = file[: file.find(".py")] importlib.import_module("unilm.criterions." + file_na...
KosmosX-API-main
kosmosX/unilm/criterions/__init__.py
from setuptools import setup, find_packages import site site.ENABLE_USER_SITE = True setup( name='infinibatch', version='0.1.0', url='https://github.com/microsoft/infinibatch', author='Frank Seide', author_email='fseide@microsoft.com', description='Infinibatch is a library of checkpointable ite...
KosmosX-API-main
kosmosX/infinibatch/setup.py
import copy import itertools import multiprocessing from random import Random import unittest import torch from infinibatch.iterators import * if __name__ == "__main__": unittest.main() class TestBase(unittest.TestCase): def setUp(self): self.lengths = [1, 2, 3, 42, 57] self.world_sizes = [...
KosmosX-API-main
kosmosX/infinibatch/test/test_iterators.py
import gzip import itertools from random import Random import os import shutil import tempfile from typing import Iterator import unittest import gc from infinibatch.datasets import chunked_dataset_iterator class TestBase(unittest.TestCase): def setUp(self): self.test_data = [ ["item number o...
KosmosX-API-main
kosmosX/infinibatch/test/test_datasets.py
""" This file causes the doctests to be included as part of unit tests. To make sure the doctests of a specific module are included, please replicate the `addTests` call for the iterators module below. """ import doctest import infinibatch.iterators def load_tests(loader, tests, ignore): tests.addTests(doctest.D...
KosmosX-API-main
kosmosX/infinibatch/test/test_doctests.py
from .iterators import create_source_iterator, CheckpointableIterator, SelectManyIterator, PrefetchIterator, BufferedShuffleIterator, BlockwiseShuffleIterator, MapIterator from typing import List, Iterator, Callable, Any, Optional """ This module contains common datasets, which are implemented as convenience functions...
KosmosX-API-main
kosmosX/infinibatch/infinibatch/datasets.py
""" Infinibatch is a library of checkpointable iterators for randomized data loading of massive data sets in deep neural network training. ## Features * support for corpora much larger than fit into RAM * hierarchical block+sentence-level randomization over the whole corpus, different randomization in each epoch...
KosmosX-API-main
kosmosX/infinibatch/infinibatch/__init__.py
""" ## Overview This part of the documentation covers the __advanced usage__ of Infinibatch by assembling __custom data loading pipelines__. Before you continue, please go through the tutorial on the top-level of the documentation of the `infinibatch` module. Two of the main features of Infinibatch are __lazy evaluat...
KosmosX-API-main
kosmosX/infinibatch/infinibatch/iterators.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 import subprocess import sys from setuptools import Extension, find_packages, setup if sys.version_info < (...
KosmosX-API-main
kosmosX/fairseq/setup.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. """ Legacy entry point. Use fairseq_cli/train.py or fairseq-train instead. """ from fairseq_cli.train import cli_mai...
KosmosX-API-main
kosmosX/fairseq/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. """isort:skip_file""" import functools import importlib dependencies = [ "dataclasses", "hydra", "numpy", "omegaconf", "...
KosmosX-API-main
kosmosX/fairseq/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 argparse from pathlib import Path from typing import Callable, List, Optional, Union import torch from fairseq import utils from fairs...
KosmosX-API-main
kosmosX/fairseq/fairseq/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. from collections import namedtuple import numpy as np import torch from fairseq import utils DecoderOut = namedtuple( "IterativeRefinem...
KosmosX-API-main
kosmosX/fairseq/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. import logging import torch logger = logging.getLogger(__name__) class NanDetector: """ Detects the first NaN or Inf in forward a...
KosmosX-API-main
kosmosX/fairseq/fairseq/nan_detector.py
# Originally from Microsoft Corporation. # Licensed under the MIT License. """ Wrapper for ngram_repeat_block cuda extension """ import math import warnings from typing import Dict, List import torch from torch import nn try: from fairseq import ngram_repeat_block_cuda EXTENSION_BUILT = True except ImportEr...
KosmosX-API-main
kosmosX/fairseq/fairseq/ngram_repeat_block.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 argparse import Namespace from typing import Union from fairseq.dataclass import FairseqDataclass from fairseq.dataclass.utils import me...
KosmosX-API-main
kosmosX/fairseq/fairseq/registry.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 numpy as np from fairseq.data.audio.speech_to_text_dataset import S2TDataConfig class SpeechGenerator(object): def ...
KosmosX-API-main
kosmosX/fairseq/fairseq/speech_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 os import typing as tp def _safe_readline(fd) -> str: pos = fd.tell() while True: try: return fd.readline...
KosmosX-API-main
kosmosX/fairseq/fairseq/file_chunker_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. """isort:skip_file""" import os import sys try: from .version import __version__ # noqa except ImportError: version_txt = os.path.jo...
KosmosX-API-main
kosmosX/fairseq/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. import math from typing import Dict, List, Optional import sys import torch import torch.nn as nn from fairseq import search, utils from fair...
KosmosX-API-main
kosmosX/fairseq/fairseq/sequence_generator.py
""" DeepSpeed trainer """ import os import sys import torch import time import logging import deepspeed import json from typing import Any, Dict, List from itertools import chain from argparse import Namespace import torch.distributed as dist from fairseq import optim, utils from fairseq.distributed import utils as ...
KosmosX-API-main
kosmosX/fairseq/fairseq/ds_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. import multiprocessing import os import pdb import sys __all__ = ["set_trace"] _stdin = [None] _stdin_lock = multiprocessing.Lock() try: ...
KosmosX-API-main
kosmosX/fairseq/fairseq/pdb.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 re SPACE_NORMALIZER = re.compile(r"\s+") def tokenize_line(line): line = SPACE_NORMALIZER.sub(" ", line) line = line.strip(...
KosmosX-API-main
kosmosX/fairseq/fairseq/tokenizer.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. import argparse import copy import logging import os from typing import Any, Dict, Iterator, List import torch from...
KosmosX-API-main
kosmosX/fairseq/fairseq/hub_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 sys import torch from fairseq import utils class SequenceScorer(object): """Scores the target for a given source sentence.""" ...
KosmosX-API-main
kosmosX/fairseq/fairseq/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 uuid from typing import Dict, Optional from torch import Tensor class FairseqIncrementalState(object): def __init__(self, *args,...
KosmosX-API-main
kosmosX/fairseq/fairseq/incremental_decoding_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 contextlib import copy import importlib import logging import os import sys import warnings from itertools import accum...
KosmosX-API-main
kosmosX/fairseq/fairseq/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 ast import collections import contextlib import logging import numpy as np import os import re import time import traceback from collec...
KosmosX-API-main
kosmosX/fairseq/fairseq/checkpoint_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 from omegaconf import DictConfig logger = logging....
KosmosX-API-main
kosmosX/fairseq/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. """ Utilities for working with the local dataset cache. This file is adapted from `AllenNLP <https://github.com/allenai/allennlp>`_. and `hugg...
KosmosX-API-main
kosmosX/fairseq/fairseq/file_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 math from typing import List, Optional import torch import torch.nn as nn from fairseq.token_generation_constraints import ( Const...
KosmosX-API-main
kosmosX/fairseq/fairseq/search.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 logging import os import shutil from typing import List, Optional logger = logging.getLogger(__file__) try:...
KosmosX-API-main
kosmosX/fairseq/fairseq/file_io.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 import logging import os import sys import time from argparse import Namespac...
KosmosX-API-main
kosmosX/fairseq/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. import logging import os import typing as tp from abc import ABC, abstractmethod from collections import Counter from dataclasses import datac...
KosmosX-API-main
kosmosX/fairseq/fairseq/binarizer.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. """Implements tracking of constraints for a beam item. A list of constraints is given as a list of one or more token sequences, each of lengt...
KosmosX-API-main
kosmosX/fairseq/fairseq/token_generation_constraints.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 dataclasses import dataclass, field from typing import Optional import torch from omegaconf import II from .dummy_datase...
KosmosX-API-main
kosmosX/fairseq/fairseq/benchmark/dummy_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 logging from dataclasses import dataclass, field from typing import Optional import torch from .dummy_dataset import DummyDataset from...
KosmosX-API-main
kosmosX/fairseq/fairseq/benchmark/dummy_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 logging import numpy as np import torch from fairseq.data import Dictionary, FairseqDataset from fairseq.tasks import LegacyFairseqTa...
KosmosX-API-main
kosmosX/fairseq/fairseq/benchmark/dummy_mt.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 models/tasks to register them from . import dummy_dataset, dummy_lm, dummy_masked_lm, dummy_model, dummy_mt # noqa
KosmosX-API-main
kosmosX/fairseq/fairseq/benchmark/__init__.py