repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
pytorch-tutorial | tutorials/02-intermediate/language_model/data_utils.py | .py | import torch
import os
class Dictionary(object):
def __init__(self):
self.word2idx = {}
self.idx2word = {}
self.idx = 0
def add_word(self, word):
if not word in self.word2idx:
self.word2idx[word] = self.idx
self.idx2word[self.idx] = word
... | 46 | 1,301 |
pytorch-tutorial | tutorials/03-advanced/variational_autoencoder/main.py | .py | import os
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
from torchvision import transforms
from torchvision.utils import save_image
# Device configuration
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Create a directory if not exists
sample_dir = 'sam... | 101 | 3,335 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/resize.py | .py | import argparse
import os
from PIL import Image
def resize_image(image, size):
"""Resize an image to the given size."""
return image.resize(size, Image.ANTIALIAS)
def resize_images(image_dir, output_dir, size):
"""Resize the images in 'image_dir' and save into 'output_dir'."""
if not os.path.exists(o... | 42 | 1,553 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/train.py | .py | import argparse
import torch
import torch.nn as nn
import numpy as np
import os
import pickle
from data_loader import get_loader
from build_vocab import Vocabulary
from model import EncoderCNN, DecoderRNN
from torch.nn.utils.rnn import pack_padded_sequence
from torchvision import transforms
# Device configuration
de... | 101 | 4,498 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/model.py | .py | import torch
import torch.nn as nn
import torchvision.models as models
from torch.nn.utils.rnn import pack_padded_sequence
class EncoderCNN(nn.Module):
def __init__(self, embed_size):
"""Load the pretrained ResNet-152 and replace top fc layer."""
super(EncoderCNN, self).__init__()
resnet =... | 56 | 2,718 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/sample.py | .py | import torch
import matplotlib.pyplot as plt
import numpy as np
import argparse
import pickle
import os
from torchvision import transforms
from build_vocab import Vocabulary
from model import EncoderCNN, DecoderRNN
from PIL import Image
# Device configuration
device = torch.device('cuda' if torch.cuda.is_available... | 82 | 3,033 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/data_loader.py | .py | import torch
import torchvision.transforms as transforms
import torch.utils.data as data
import os
import pickle
import numpy as np
import nltk
from PIL import Image
from build_vocab import Vocabulary
from pycocotools.coco import COCO
class CocoDataset(data.Dataset):
"""COCO Custom Dataset compatible with torch.u... | 105 | 3,929 |
pytorch-tutorial | tutorials/03-advanced/image_captioning/build_vocab.py | .py | import nltk
import pickle
import argparse
from collections import Counter
from pycocotools.coco import COCO
class Vocabulary(object):
"""Simple vocabulary wrapper."""
def __init__(self):
self.word2idx = {}
self.idx2word = {}
self.idx = 0
def add_word(self, word):
if not wo... | 76 | 2,459 |
pytorch-tutorial | tutorials/03-advanced/neural_style_transfer/main.py | .py | from __future__ import division
from torchvision import models
from torchvision import transforms
from PIL import Image
import argparse
import torch
import torchvision
import torch.nn as nn
import numpy as np
# Device configuration
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
def load_image(... | 126 | 4,547 |
pytorch-tutorial | tutorials/03-advanced/generative_adversarial_network/main.py | .py | import os
import torch
import torchvision
import torch.nn as nn
from torchvision import transforms
from torchvision.utils import save_image
# Device configuration
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Hyper-parameters
latent_size = 64
hidden_size = 256
image_size = 784
num_epochs = ... | 148 | 5,096 |
fairseq | train.py | .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... | 15 | 366 |
fairseq | setup.py | .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
from torch.utils import ... | 258 | 7,642 |
fairseq | hubconf.py | .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",
"... | 74 | 2,099 |
fairseq | release_utils.py | .py | import argparse
from typing import Tuple
def get_next_version(release_type) -> Tuple[Tuple[int, int, int], str, str]:
current_ver = find_version("fairseq/version.txt")
version_list = [int(x) for x in current_ver.strip("'").split(".")]
major, minor, patch = version_list[0], version_list[1], version_list[2]... | 73 | 2,077 |
fairseq | hydra_plugins/dependency_submitit_launcher/setup.py | .py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# type: ignore
from pathlib import Path
from read_version import read_version
from setuptools import find_namespace_packages, setup
setup(
name="dependency-submitit-launcher",
version=read_version("hydra_plugins/dependency_submitit_launche... | 30 | 1,012 |
fairseq | hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/launcher.py | .py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import logging
import os
import subprocess
from pathlib import Path
from typing import Any, List, Sequence
from hydra.core.singleton import Singleton
from hydra.core.utils import JobReturn, filter_overrides
from omegaconf import OmegaConf
log = lo... | 122 | 3,909 |
fairseq | hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/__init__.py | .py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
__version__ = "0.1"
| 4 | 92 |
fairseq | hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/config.py | .py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from dataclasses import dataclass, field
from hydra.core.config_store import ConfigStore
from hydra_plugins.hydra_submitit_launcher.config import SlurmQueueConf
@dataclass
class DependencySubmititConf(SlurmQueueConf):
"""Slurm configuration ... | 24 | 652 |
fairseq | tests/test_multihead_attention.py | .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 random
import unittest
import pytest
import torch
from fairseq.modules.multihead_attention import MultiheadAttention, _mask_for_xform... | 489 | 15,845 |
fairseq | tests/test_reproducibility.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import json
import os
import tempfile
import unittest
import torch
from . import test_binaries
class TestReproducibility(unittest.TestCase... | 149 | 4,864 |
fairseq | tests/test_character_token_embedder.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from fairseq.data import Dictionary
from fairseq.modules import CharacterTokenEmbedder
class TestCharacterToke... | 49 | 1,678 |
fairseq | tests/test_plasma_utils.py | .py | import contextlib
import tempfile
import unittest
from io import StringIO
import numpy as np
from tests.utils import create_dummy_data, preprocess_lm_data, train_language_model
try:
from pyarrow import plasma
from fairseq.data.plasma_utils import PlasmaStore, PlasmaView
PYARROW_AVAILABLE = True
except ... | 128 | 4,792 |
fairseq | tests/test_roberta.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import functools
import unittest
from typing import Any, Dict, Sequence
import fairseq
import fairseq.options
import fairseq.tasks
import tor... | 345 | 11,291 |
fairseq | tests/test_metrics.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import uuid
from fairseq.logging import metrics
class TestMetrics(unittest.TestCase):
def test_nesting(self):
w... | 78 | 2,645 |
fairseq | tests/test_lm_context_window.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from fairseq.data import MonolingualDataset
from fairseq.tasks.language_modeling import LanguageModelingConfig,... | 55 | 1,865 |
fairseq | tests/test_online_backtranslation.py | .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 tempfile
import unittest
from pathlib import Path
from typing import Any, Dict, Sequence
import fairseq.data.indexed_dataset as indexe... | 207 | 7,650 |
fairseq | tests/utils.py | .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 json
import os
import random
import shutil
import string
import sys
import typing as tp
from io import StringIO
import... | 798 | 24,142 |
fairseq | tests/test_binarizer.py | .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
import unittest
from tempfile import TemporaryDirectory
from fairseq.binarizer import BinarizeSummary, FileBin... | 123 | 3,799 |
fairseq | tests/test_sequence_generator.py | .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 math
import tempfile
import unittest
import numpy as np
import torch
import tests.utils as test_utils
from fairseq im... | 745 | 27,810 |
fairseq | tests/test_file_chunker_utils.py | .py | # 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 shutil
import tempfile
import unittest
from typing import Optional
class TestFileChunker(unittest.TestCase):
_tmpdir: Optional[str] = None
_tmpfile: Optional[str] = Non... | 64 | 2,283 |
fairseq | tests/test_export.py | .py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import tempfile
import unittest
import torch
from fairseq.data.dictionary import Dictionary
from fair... | 121 | 4,002 |
fairseq | tests/test_amp_optimizer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import copy
import unittest
import torch
from torch.cuda.amp import GradScaler, autocast
from fairseq.optim import build_opt... | 76 | 2,411 |
fairseq | tests/test_token_block_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import tests.utils as test_utils
import torch
from fairseq.data import TokenBlockDataset
class TestTokenBlockDataset(unitte... | 93 | 3,629 |
fairseq | tests/test_inference_dropout.py | .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 unittest
from fairseq.dataclass.utils import convert_namespace_to_omegaconf
from fairseq.models.transformer import Tran... | 71 | 3,308 |
fairseq | tests/test_positional_encoding.py | .py | import unittest
import torch
from fairseq.modules import RelPositionalEncoding
import numpy as np
class TestRelPositionalEncoding(unittest.TestCase):
def setUp(self) -> None:
self.T = 3
self.B = 1
self.C = 2
torch.manual_seed(0)
self.sample = torch.randn(self.T, self.B, se... | 64 | 1,714 |
fairseq | tests/test_iterators.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from fairseq.data import iterators, ListDataset
class TestIterators(unittest.TestCase):
def test_counting_iterator_inde... | 195 | 7,723 |
fairseq | tests/test_resampling_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import collections
import unittest
import numpy as np
from fairseq.data import ListDataset, ResamplingDataset
class TestResamplingDataset(u... | 104 | 3,365 |
fairseq | tests/test_activation_checkpointing.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
import torch.nn as nn
from fairseq.modules.checkpoint_activations import checkpoint_wrapper
from torch.utils.che... | 80 | 2,904 |
fairseq | tests/test_noising.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from typing import Dict, List
import torch
import tests.utils as test_utils
from fairseq import utils
from fairseq.data impo... | 532 | 19,814 |
fairseq | tests/test_lstm_jitable.py | .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 tempfile
import unittest
import torch
from fairseq.data.dictionary import Dictionary
from fairseq.models.lstm import L... | 116 | 4,041 |
fairseq | tests/test_sequence_scorer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import unittest
import tests.utils as test_utils
import torch
from fairseq.sequence_scorer import SequenceScorer
class Test... | 121 | 4,150 |
fairseq | tests/test_dataclass_utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from argparse import ArgumentParser
from dataclasses import dataclass, field
from fairseq.dataclass import FairseqDataclass
f... | 88 | 2,896 |
fairseq | tests/test_fp16_optimizer.py | .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 copy
import logging
import unittest
import torch
from fairseq.optim.fp16_optimizer import FP16Optimizer, MemoryEfficientFP16Optimizer
... | 112 | 3,571 |
fairseq | tests/test_label_smoothing.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import copy
import unittest
import tests.utils as test_utils
import torch
from fairseq.criterions.cross_entropy import CrossE... | 124 | 4,629 |
fairseq | tests/test_sparse_multihead_attention.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from fairseq.modules.sparse_multihead_attention import SparseMultiheadAttention
class TestSparseMultiheadAtten... | 115 | 3,738 |
fairseq | tests/test_train.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import logging
import unittest
from io import StringIO
from unittest.mock import MagicMock, patch
import torch
from fairseq... | 248 | 9,292 |
fairseq | tests/test_huffman.py | .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
import unittest
from collections import Counter
from tempfile import NamedTemporaryFile, TemporaryDirectory
fro... | 180 | 6,039 |
fairseq | tests/test_multi_corpus_sampled_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from collections import OrderedDict
import numpy as np
import torch
from fairseq.data import LanguagePairDataset, TokenBlockD... | 96 | 3,109 |
fairseq | tests/test_hf_hub.py | .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 unittest
import torch
try:
import huggingface_hub
except ImportError:
huggingface_hub = None
from fai... | 30 | 796 |
fairseq | tests/test_binaries.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import json
import logging
import os
import random
import sys
import tempfile
import unittest
from packaging import version
... | 1,916 | 73,566 |
fairseq | tests/test_dictionary.py | .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 io
import os
import string
import tempfile
import unittest
import torch
from fairseq import tokenizer
from fairseq.data import Diction... | 146 | 4,551 |
fairseq | tests/test_checkpoint_utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import logging
import os
import tempfile
import unittest
from io import StringIO
from unittest.mock import patch
from fairs... | 126 | 4,648 |
fairseq | tests/test_convtbc.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
import torch.nn as nn
from fairseq.modules import ConvTBC
class TestConvTBC(unittest.TestCase):
def test_c... | 55 | 1,745 |
fairseq | tests/test_iopath.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from unittest import mock
class TestIOPath(unittest.TestCase):
def test_no_iopath(self):
from .test_reproducibil... | 29 | 992 |
fairseq | tests/test_valid_subset_checks.py | .py | import os
import shutil
import tempfile
import unittest
from fairseq import options
from fairseq.dataclass.utils import convert_namespace_to_omegaconf
from fairseq.data.data_utils import raise_if_valid_subsets_unintentionally_ignored
from .utils import create_dummy_data, preprocess_lm_data, train_language_model
def ... | 144 | 5,031 |
fairseq | tests/test_checkpoint_utils_for_task_level_attributes.py | .py | #!/usr/bin/env fbpython
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
import contextlib
import logging
import unittest
from io import StringIO
from unittest.mock import MagicMock, patch
import torch
from fairseq import checkpoint_utils, data
from omegaconf import OmegaConf
def mock_traine... | 173 | 5,449 |
fairseq | tests/test_transformer.py | .py | import argparse
import unittest
from typing import Any, Dict, Sequence
import torch
from fairseq.models import transformer
from tests.test_roberta import FakeTask
def mk_sample(tok: Sequence[int] = None, batch_size: int = 2) -> Dict[str, Any]:
if not tok:
tok = [10, 11, 12, 13, 14, 15, 2]
batch = t... | 66 | 1,942 |
fairseq | tests/test_ema.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from copy import deepcopy
from dataclasses import dataclass
import pytest
from typing import Optional
from unittest.mock impor... | 276 | 8,774 |
fairseq | tests/test_average_checkpoints.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import collections
import os
import shutil
import tempfile
import unittest
import numpy as np
import torch
from scripts.average_checkpoints i... | 135 | 4,385 |
fairseq | tests/test_constraints.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from typing import List
import torch
from fairseq.token_generation_constraints import (
ConstraintNode,
OrderedConst... | 276 | 10,612 |
fairseq | tests/test_concat_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from fairseq.data import LanguagePairDataset, TokenBlockDataset
from fairseq.data.concat_dataset import ConcatDa... | 59 | 1,866 |
fairseq | tests/test_file_io.py | .py | # 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 shutil
import sys
import tempfile
import unittest
from typing import Optional
from unittest.mock import MagicMock
class TestFileIO(unittest.TestCase):
_tmpdir: Optional[st... | 60 | 1,804 |
fairseq | tests/test_data_utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import numpy as np
from fairseq.data.data_utils_fast import batch_by_size_fn, batch_by_size_vec
class TestBatchBySize(unit... | 137 | 4,827 |
fairseq | tests/test_memory_efficient_fp16.py | .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 logging
import unittest
import torch
from fairseq.optim.adam import FairseqAdam
from fairseq.optim.fp16_optimizer impo... | 79 | 2,452 |
fairseq | tests/test_multi_corpus_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from collections import OrderedDict
import torch
from fairseq.data import LanguagePairDataset, TokenBlockDataset
from fairse... | 83 | 2,587 |
fairseq | tests/test_utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from fairseq import utils
class TestUtils(unittest.TestCase):
def test_convert_padding_direction(self):
... | 115 | 3,295 |
fairseq | tests/test_rotary_positional_embedding.py | .py | import torch
import numpy as np
import unittest
from fairseq.modules.rotary_positional_embedding import apply_rotary_pos_emb
from fairseq.modules import RotaryPositionalEmbedding
class TestRotaryPositionalEmbedding(unittest.TestCase):
def setUp(self) -> None:
self.T = 3
self.B = 1
self.C =... | 86 | 3,198 |
fairseq | tests/test_espnet_multihead_attention.py | .py | import torch
import numpy as np
import unittest
from fairseq.modules import (
ESPNETMultiHeadedAttention,
RelPositionMultiHeadedAttention,
RotaryPositionMultiHeadedAttention,
)
torch.use_deterministic_algorithms(True)
class TestESPNETMultiHeadedAttention(unittest.TestCase):
def setUp(self) -> None:
... | 177 | 5,548 |
fairseq | tests/test_backtranslation_dataset.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import tests.utils as test_utils
import torch
from fairseq.data import (
BacktranslationDataset,
LanguagePairDataset,... | 124 | 4,140 |
fairseq | tests/test_dataset.py | .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 unittest
from typing import Sequence
from fairseq.data import LanguagePairDataset, ListDataset, RoundRobinZipDatasets
f... | 67 | 2,916 |
fairseq | tests/gpu/test_binaries_gpu.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import contextlib
import json
import logging
import os
import tempfile
import unittest
from io import StringIO
import torch
from fairseq imp... | 591 | 20,506 |
fairseq | tests/gpu/test_ema_gpu.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from copy import deepcopy
from dataclasses import dataclass
from typing import Optional
import torch
from fairseq.models.ema... | 216 | 6,825 |
fairseq | tests/distributed/test_bmuf.py | .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 functools
import random
import unittest
from multiprocessing import Manager
import torch
import torch.nn as nn
from om... | 205 | 7,027 |
fairseq | tests/distributed/utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import functools
import tempfile
import torch
def spawn_and_init(fn, world_size, args=None):
if args is None:
args = ()
wit... | 66 | 1,765 |
fairseq | tests/distributed/test_module_proxy_wrapper.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from torch import nn
from fairseq.distributed import ModuleProxyWrapper
from .utils import objects_are_equal
... | 75 | 2,085 |
fairseq | tests/distributed/test_distributed_timeout_wrapper.py | .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 signal
import time
import unittest
import torch
from torch import nn
from fairseq.distributed import DistributedTimeou... | 53 | 1,349 |
fairseq | tests/distributed/test_utils.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import functools
import sys
import unittest
import torch
from fairseq.distributed import utils as dist_utils
from .utils import objects_are... | 125 | 3,656 |
fairseq | tests/tasks/test_denoising.py | .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 unittest
from tempfile import TemporaryDirectory
from fairseq import options
from fairseq.binarizer import FileBinarizer, Vo... | 97 | 3,441 |
fairseq | tests/tasks/test_masked_lm.py | .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 unittest
from tempfile import TemporaryDirectory
from fairseq.binarizer import FileBinarizer, VocabularyDatasetBinarizer
fro... | 79 | 2,919 |
fairseq | tests/tasks/test_span_masked_lm.py | .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 unittest
from tempfile import TemporaryDirectory
from fairseq import options
from fairseq.binarizer import FileBinarizer, Vo... | 107 | 4,130 |
fairseq | tests/tasks/test_multilingual_denoising.py | .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 unittest
from tempfile import TemporaryDirectory
from fairseq import options
from fairseq.binarizer import FileBinarizer, Vo... | 99 | 3,600 |
fairseq | tests/speech_recognition/test_vggtransformer.py | .py | #!/usr/bin/env python3
# import models/encoder/decoder to be tested
from examples.speech_recognition.models.vggtransformer import (
TransformerDecoder,
VGGTransformerEncoder,
VGGTransformerModel,
vggtransformer_1,
vggtransformer_2,
vggtransformer_base,
)
# import base test class
from .asr_test... | 136 | 4,578 |
fairseq | tests/speech_recognition/test_collaters.py | .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 unittest
import numpy as np
import torch
from examples.speech_recognition.data.collaters import Seq2SeqCollater... | 59 | 2,048 |
fairseq | tests/speech_recognition/asr_test_base.py | .py | #!/usr/bin/env python3
import argparse
import os
import unittest
from inspect import currentframe, getframeinfo
import numpy as np
import torch
from examples.speech_recognition.data.data_utils import lengths_to_encoder_padding_mask
from fairseq.data import data_utils as fairseq_data_utils
from fairseq.data.dictionary... | 558 | 19,469 |
fairseq | tests/speech_recognition/test_data_utils.py | .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 unittest
import torch
from examples.speech_recognition.data import data_utils
class DataUtilsTest(unittest.Tes... | 63 | 1,736 |
fairseq | tests/speech_recognition/test_cross_entropy.py | .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 examples.speech_recognition.criterions.cross_entropy_acc import (
CrossEntropyWithAccCriterion,
)
from .asr_t... | 38 | 1,438 |
fairseq | tests/speech/test_tts_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from tqdm import tqdm
from fairseq import utils
from fairseq.tasks.text_to_speech import batch_mel_cepstral_dis... | 54 | 1,831 |
fairseq | tests/speech/test_xm_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from tests.speech import TestFairseqSpeech
class TestXMTransformer(TestFairseqSpeech):
def setUp(self):
self.set... | 30 | 875 |
fairseq | tests/speech/test_s2t_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from tests.speech import TestFairseqSpeech
class TestS2TTransformer(TestFairseqSpeech):
def setUp(self):
self.se... | 24 | 636 |
fairseq | tests/speech/test_dualinput_s2t_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from argparse import Namespace
from collections import namedtuple
from pathlib import Path
import torch
from tqdm import tqdm... | 111 | 3,977 |
fairseq | tests/speech/__init__.py | .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
import os
import re
import unittest
from pathlib import Path
from tqdm import tqdm
from typing import List, Dic... | 211 | 7,147 |
fairseq | tests/speech/test_wav2vec2.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from tests.speech import TestFairseqSpeech
from fairseq.data.data_utils import post_process
from fairseq import u... | 91 | 2,914 |
fairseq | tests/speech/test_fastspeech2.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import torch
from tqdm import tqdm
from fairseq import utils
from fairseq.tasks.text_to_speech import batch_mel_cepstral_dis... | 54 | 1,825 |
fairseq | tests/speech/test_s2s_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from tests.speech import TestFairseqSpeech
from fairseq import utils
S3_BASE_URL = "https://dl.fbaipublicfiles.com/fairseq/"
... | 52 | 1,537 |
fairseq | tests/speech/test_convtransformer_simul_trans.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from tests.speech import TestFairseqSpeech
S3_BASE_URL = "https://dl.fbaipublicfiles.com/fairseq/"
class TestConvtransforme... | 34 | 996 |
fairseq | tests/speech/test_dual_input_wav_transformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from collections import namedtuple
from pathlib import Path
import torch
from tqdm import tqdm
import fairseq
from fairseq i... | 77 | 2,393 |
fairseq | tests/speech/test_s2t_conformer.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
from tests.speech import TestFairseqSpeech
class TestS2TConformer(TestFairseqSpeech):
def setUp(self):
self.set_... | 24 | 639 |
fairseq | scripts/spm_decode.py | .py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
... | 54 | 1,520 |
fairseq | scripts/count_docs.py | .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.
"""
Count the number of documents and average number of lines and tokens per
document in a large file. Documents should ... | 59 | 1,784 |
fairseq | scripts/check_installation.py | .py | from pathlib import Path
import os
cwd = Path(".").resolve()
print("running 'check_installation.py' from:", cwd)
# Old versions of numpy/torch can prevent loading the .so files
import torch
print("torch:", torch.__version__)
import numpy
print("numpy:", numpy.__version__)
import fairseq
print("Fairseq installed a... | 37 | 877 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.