python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
# 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.data.encoders import register_bpe from fairseq.data.encoders.byte_utils import ( SPACE, SPACE_ESCAPE, byte_encode, ...
bart_ls-main
fairseq-py/fairseq/data/encoders/bytes.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 WHITESPACE_NORMALIZER = re.compile(r"\s+") SPACE = chr(32) SPACE_ESCAPE = chr(9601) # excluding non-breaking space (160) here PRIN...
bart_ls-main
fairseq-py/fairseq/data/encoders/byte_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. #!/usr/bin/env python3 class SpecialConversationSymbols: BOC = "<c>" EOC = "</c>" BOS = "<s>" EOS = "</s>" BOS0 = "<s0>...
bart_ls-main
fairseq-py/fairseq/data/fb_conversations/fb_special_symbols.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.
bart_ls-main
fairseq-py/fairseq/data/fb_conversations/__init__.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 logging import traceback from typing import Any, Dict, Optional, Tuple import numpy as np impo...
bart_ls-main
fairseq-py/fairseq/data/fb_conversations/fb_conversation_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ A standalone module for aggregating metrics. Metrics can be logged from anywhere using the `log_*` functions defined in this module. The l...
bart_ls-main
fairseq-py/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. import bisect import time from collections import OrderedDict from typing import Dict, Optional try: import torch def type_as(a, b)...
bart_ls-main
fairseq-py/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. """ Wrapper around tbwriter api for for writing to manifold-tensorboard. FB Internal (not to be open-sourced) """ import datetime import os fr...
bart_ls-main
fairseq-py/fairseq/logging/fb_tbmf_wrapper.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.
bart_ls-main
fairseq-py/fairseq/logging/__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. """ Wrapper around various loggers and progress bars (e.g., tqdm). """ import atexit import json import logging import os import sys from col...
bart_ls-main
fairseq-py/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. import inspect from typing import Any, Dict, List from fairseq import metrics, utils from fairseq.dataclass import FairseqDataclass from fair...
bart_ls-main
fairseq-py/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 math from dataclasses import dataclass import torch.nn.functional as F from fairseq import metrics, utils from fairseq.criterions impo...
bart_ls-main
fairseq-py/fairseq/criterions/cross_entropy.py
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. from typing import List, Dict, Any...
bart_ls-main
fairseq-py/fairseq/criterions/fastspeech2_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. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tr...
bart_ls-main
fairseq-py/fairseq/criterions/ctc.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 dataclasses import dataclass import torch.nn.functional as F from fairseq import metrics, utils from fairseq.criterions impo...
bart_ls-main
fairseq-py/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 logging from dataclasses import dataclass, field from typing import Dict, List from fairseq import metrics, utils from fairseq.criteri...
bart_ls-main
fairseq-py/fairseq/criterions/model_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 from dataclasses import dataclass, field from typing import List, Optional import torch import torch.nn.functional as F from fair...
bart_ls-main
fairseq-py/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, ...
bart_ls-main
fairseq-py/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, ...
bart_ls-main
fairseq-py/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. """isort:skip_file""" import importlib import os from fairseq import registry from fairseq.criterions.fairseq_criterion import ( # noqa ...
bart_ls-main
fairseq-py/fairseq/criterions/__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 dataclasses import dataclass, field import torch from fairseq import metrics, utils from fairseq.criterions import register_criterion fro...
bart_ls-main
fairseq-py/fairseq/criterions/label_smoothed_cross_entropy_latency_augmented.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 dataclasses import dataclass, field import torch from fairseq import metrics, utils from fairseq.criterions import FairseqCr...
bart_ls-main
fairseq-py/fairseq/criterions/label_smoothed_cross_entropy.py
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. import logging from typing import ...
bart_ls-main
fairseq-py/fairseq/criterions/tacotron2_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. from fairseq import utils from fairseq.criterions import LegacyFairseqCriterion, register_criterion from torch import nn @register_criterion...
bart_ls-main
fairseq-py/fairseq/criterions/composite_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 re from dataclasses import dataclass, field from typing import List, Optional import torch import torch.nn.functional as F...
bart_ls-main
fairseq-py/fairseq/criterions/hubert_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 from dataclasses import dataclass, field import torch.nn.functional as F from fairseq import metrics, utils from fairseq.criterio...
bart_ls-main
fairseq-py/fairseq/criterions/model_denoising.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 dataclasses import dataclass, field import torch import torch.nn.functional as F from fairseq import metrics, utils from fai...
bart_ls-main
fairseq-py/fairseq/criterions/sentence_prediction.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 (...
bart_ls-main
fairseq-py/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. from dataclasses import dataclass import math from omegaconf import II import torch from fairseq import metrics, modules, utils from fairseq....
bart_ls-main
fairseq-py/fairseq/criterions/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, ...
bart_ls-main
fairseq-py/fairseq/criterions/sentence_ranking.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 logging import os from fairseq.dataclass.initialize import add_defaults, hydra_init from fairseq_cli.train i...
bart_ls-main
fairseq-py/fairseq_cli/hydra_train.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. """ Data pre-processing: build vocabularies and binarize training data. """ import logging import os import shutil impo...
bart_ls-main
fairseq-py/fairseq_cli/preprocess.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate pre-processed data with a trained model. """ import ast import logging import math import os import sy...
bart_ls-main
fairseq-py/fairseq_cli/generate.py
bart_ls-main
fairseq-py/fairseq_cli/__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 argparse import logging import os import sys import tempfile from pathlib import Path from typing import Callable, Optional import tor...
bart_ls-main
fairseq-py/fairseq_cli/fb_train.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import os import sys from argparse import Namespace from itertools import chain import torch from fa...
bart_ls-main
fairseq-py/fairseq_cli/validate.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate raw text with a trained model. Batches data on-the-fly. """ import ast import fileinput import logging...
bart_ls-main
fairseq-py/fairseq_cli/interactive.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Train a new model on one or across multiple GPUs. """ import argparse import logging import math import os impor...
bart_ls-main
fairseq-py/fairseq_cli/train.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Evaluate the perplexity of a trained language model. """ import logging import math import os import sys from a...
bart_ls-main
fairseq-py/fairseq_cli/eval_lm.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. """ BLEU scoring of generated translations against reference translations. """ import argparse import os import sys fr...
bart_ls-main
fairseq-py/fairseq_cli/score.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. """ Split a large file into a train and valid set while respecting document boundaries. Documents should be separated by...
bart_ls-main
fairseq-py/scripts/split_train_valid_docs.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. """ Use this script in order to build symmetric alignments for your translation dataset. This script depends on fast_align and mosesdecoder too...
bart_ls-main
fairseq-py/scripts/build_sym_alignment.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 fairseq.average_checkpoints import main from fairseq.file_io import PathManager # support fb specific path manan...
bart_ls-main
fairseq-py/scripts/fb_average_checkpoints.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 ...
bart_ls-main
fairseq-py/scripts/spm_decode.py
bart_ls-main
fairseq-py/scripts/__init__.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 os import re import shutil import sys pt_regexp = re.compile(r"checkpoint(\d+|_\d+_\d+|_[a-z]+...
bart_ls-main
fairseq-py/scripts/rm_pt.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 ...
bart_ls-main
fairseq-py/scripts/count_docs.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 i...
bart_ls-main
fairseq-py/scripts/spm_encode.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 sys impor...
bart_ls-main
fairseq-py/scripts/spm_train.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. """ extract text from json reddit dataset """ import argparse import gzip import json import os import sys REPLACE_MA...
bart_ls-main
fairseq-py/scripts/fb_reddit_text.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import collections import os import re import torch from fairseq.file_io import PathManager def aver...
bart_ls-main
fairseq-py/scripts/average_checkpoints.py
#!/usr/bin/env python3 # # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import sys """Reads in a fairseq output file, and verifies that the constraints (C- lines) are present in the outpu...
bart_ls-main
fairseq-py/scripts/constraints/validate.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. """Extracts random constraints from reference files.""" import argparse import random import sys from sacrebleu imp...
bart_ls-main
fairseq-py/scripts/constraints/extract.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 tqdm import tqdm import json import os from nltk import word_tokenize from pathlib import Path # import stanza # nlp = stanza.Pipeline(l...
bart_ls-main
fairseq-py/scripts/summarization/qmsum_preprocess.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 argparse from tqdm import tqdm from fairseq import checkpoint_utils from fairseq.tasks.summarization import load_langpair_...
bart_ls-main
fairseq-py/scripts/summarization/qmsum_generate.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. """ Parallel testing using submitit """ from tqdm import tqdm import submitit from pathlib import Path import math import os import torch im...
bart_ls-main
fairseq-py/scripts/summarization/eval_generation_submitit.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 argparse from tqdm import tqdm from fairseq import checkpoint_utils from fairseq.tasks.summarization import load_langpair_...
bart_ls-main
fairseq-py/scripts/summarization/long_generate.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 datasets import load_dataset import torch import argparse from tqdm import tqdm from fairseq import checkpoint_utils from fairseq.tasks...
bart_ls-main
fairseq-py/scripts/qa/qa_eval.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.models.bart import BARTModel from fairseq.tasks.long_denoising import LongDenoisingTask from fairseq.tasks.denoising import Den...
bart_ls-main
fairseq-py/scripts/long_denoise/initialize_models_long_denoising.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.tasks.denoising import DenoisingTask from fairseq.dataclass.utils import convert_namespace_to_omegaconf import os import torch ...
bart_ls-main
fairseq-py/scripts/long_denoise/initialize_models_model_denoising.py
#!/usr/bin/env python3 # 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. import distutils.command.clean import glob import os import re import shutil import sys import s...
bart_ls-main
xformers/setup.py
# 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. from typing import Any, Tuple, TypeVar import torch import torch.nn as nn from pyre_extensions import TypeVarTuple, Unpa...
bart_ls-main
xformers/stubs/torch_stub_tests.py
# 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. import pytest import torch from xformers.components import Activation from xformers.components.feedforward import FEEDFO...
bart_ls-main
xformers/tests/test_feedforward.py
# 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. import math import pytest import torch from xformers.components import MultiHeadDispatch from xformers.components.atten...
bart_ls-main
xformers/tests/test_triton_blocksparse.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 xformers.components.attention import BlockSparseAttention,BlockSparseLocalAttention, BlockNoglobalAttention from xformers....
bart_ls-main
xformers/tests/test_blocksparse_local.py
# 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. import logging import pytest import torch from torch.cuda.amp.autocast_mode import autocast from xformers.components i...
bart_ls-main
xformers/tests/test_triton_dropout.py
# 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. import math import pytest import torch from xformers.components.attention import FavorAttention, ScaledDotProduct from ...
bart_ls-main
xformers/tests/test_favor.py
# 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. import logging import pytest import torch from torch.cuda.amp.autocast_mode import autocast try: from xformers.tri...
bart_ls-main
xformers/tests/test_triton_layernorm.py
# 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. import torch from xformers.components.attention.utils import ( maybe_merge_masks, reshape_key_padding_mask, ) ...
bart_ls-main
xformers/tests/test_attention_utils.py
# 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. import logging import pytest import torch from torch.cuda.amp.autocast_mode import autocast try: from xformers.trit...
bart_ls-main
xformers/tests/test_triton_softmax.py
# 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.
bart_ls-main
xformers/tests/__init__.py
# 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. import itertools import pytest import torch import xformers.components.attention.attention_patterns as AP # baseline ...
bart_ls-main
xformers/tests/test_attention_patterns.py
# 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. import pytest import torch from xformers.components.attention import AttentionMask @pytest.mark.skipif( not torch...
bart_ls-main
xformers/tests/test_attention_mask.py
# 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. import pytest import torch from xformers.components import MultiHeadDispatch # Automatically test all the registered at...
bart_ls-main
xformers/tests/test_compositional_attention.py
# 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. import pytest import torch from xformers.components.attention._sputnik_sparse import SparseCS from xformers.components.a...
bart_ls-main
xformers/tests/test_core_attention.py
# 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. import logging import pytest import torch from torch.cuda.amp.autocast_mode import autocast from xformers.components im...
bart_ls-main
xformers/tests/test_triton_fused_linear.py
# 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. import pytest import torch from xformers.components.positional_embedding import ( POSITION_EMBEDDING_REGISTRY, b...
bart_ls-main
xformers/tests/test_embedding.py
# 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. import pytest import torch # needed to register custom ops import xformers # noqa: F401 import xformers.components.atte...
bart_ls-main
xformers/tests/test_custom_ops.py
# 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. import pytest import torch # Automatically fetch all registered attentions and Feedforwards from xformers.components imp...
bart_ls-main
xformers/tests/test_block_factory.py
# 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. import pytest import torch from xformers.components.attention import maybe_sparsify from xformers.components.attention._...
bart_ls-main
xformers/tests/test_sparsecs.py
# 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. import pytest import torch # needed to register custom ops import xformers # noqa: F401 import xformers.components.atte...
bart_ls-main
xformers/tests/test_sparse_csr.py
# 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. import pytest import torch from xformers.components.positional_embedding import RotaryEmbedding DEVICES = ( [torch....
bart_ls-main
xformers/tests/test_rotary_embeddings.py
# 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. from typing import Tuple import pytest import torch from xformers.components import InProjContainer, InProjParams, Mult...
bart_ls-main
xformers/tests/test_attentions.py
# 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. import torch from xformers.components.attention import GlobalAttention, ScaledDotProduct def test_global_attention(): ...
bart_ls-main
xformers/tests/test_global_attention.py
# 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. from hydra.core.config_store import ConfigStore from xformers.factory.hydra_helper import import_xformer_config_schema ...
bart_ls-main
xformers/tests/test_hydra_helper.py
# 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. import random import pytest import torch from xformers.components.attention import OrthoFormerAttention, ScaledDotProduc...
bart_ls-main
xformers/tests/test_ortho_attention.py
# 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. import random import pytest import torch from xformers import _is_triton_available if _is_triton_available: from x...
bart_ls-main
xformers/tests/test_pytorch_transformer_parity.py
# 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. import pytest import torch SHAPES = [ (384, 128), (8 * 384, 128), (34, 128), (16, 128), (16, 512), ...
bart_ls-main
xformers/tests/test_triton_basics.py
# 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. from contextlib import nullcontext import pytest import torch from xformers.factory.model_factory import xFormer, xForm...
bart_ls-main
xformers/tests/test_model_factory.py
# 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. import random import pytest import torch from xformers.components.attention import NystromAttention, ScaledDotProduct fr...
bart_ls-main
xformers/tests/test_nystrom_attention.py
# 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. import pytest import torch try: import timm from timm.models.vision_transformer import VisionTransformer except ...
bart_ls-main
xformers/tests/test_timm_wrap.py
# 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. import random import pytest import torch from xformers.factory.model_factory import xFormer, xFormerConfig BATCH = 20 ...
bart_ls-main
xformers/tests/test_reversible.py
# 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. # type: ignore # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the...
bart_ls-main
xformers/docs/source/conf.py
# 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. # A MinGPT + Lightning + xFormers example Code from Sean Naren (@seannaren) # This is an hommage to https://github.com/ka...
bart_ls-main
xformers/examples/microGPT.py
# 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. # CREDITS: # inspired by # https://github.com/nateraw/lightning-vision-transformer # which in turn references https://gi...
bart_ls-main
xformers/examples/microViT.py
# 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. import hydra from omegaconf import DictConfig from xformers.factory.hydra_helper import import_xformer_config_schema @...
bart_ls-main
xformers/examples/build_model/my_model.py
#!/usr/bin/env python """ MIT License Copyright (c) 2017 Guillaume Papin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, m...
bart_ls-main
xformers/.circleci/run-clang-format.py
# 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. import logging import torch # Please update the doc version in docs/source/conf.py as well. __version__ = "0.0.8" _is_...
bart_ls-main
xformers/xformers/__init__.py
# 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.
bart_ls-main
xformers/xformers/test.py
# 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. import torch def masked_matmul(a, b, mask=None): if torch.overrides.has_torch_function((a, b, mask)): retu...
bart_ls-main
xformers/xformers/ops.py