python_code
stringlengths
0
992k
repo_name
stringlengths
8
46
file_path
stringlengths
5
162
""" Copyright (c) 2022, salesforce.com, inc. All rights reserved. SPDX-License-Identifier: BSD-3-Clause For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause """ import datetime import json import logging import os import time from pathlib import Path import ...
EXA-1-master
exa/libraries/LAVIS/lavis/runners/runner_base.py
""" Copyright (c) 2022, salesforce.com, inc. All rights reserved. SPDX-License-Identifier: BSD-3-Clause For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause """ import datetime import logging import os import time import torch import torch.distributed as dis...
EXA-1-master
exa/libraries/LAVIS/lavis/runners/runner_iter.py
from setuptools import setup, find_packages setup( name = 'x-transformers', packages = find_packages(exclude=['examples']), version = '1.11.0', license='MIT', description = 'X-Transformers - Pytorch', author = 'Phil Wang', author_email = 'lucidrains@gmail.com', url = 'https://github.com/lucidrains/x-tr...
EXA-1-master
exa/libraries/x-transformers/setup.py
from math import ceil import torch from torch import nn import torch.nn.functional as F from einops import rearrange, pack, unpack from x_transformers.autoregressive_wrapper import top_p, top_k, eval_decorator # helper functions def exists(val): return val is not None def divisible_by(numer, denom): return...
EXA-1-master
exa/libraries/x-transformers/x_transformers/xl_autoregressive_wrapper.py
from math import ceil import torch from torch import nn import torch.nn.functional as F from einops import rearrange, pack, unpack def exists(val): return val is not None def eval_decorator(fn): def inner(self, *args, **kwargs): was_training = self.training self.eval() out = fn(self, ...
EXA-1-master
exa/libraries/x-transformers/x_transformers/autoregressive_wrapper.py
import math from random import random import torch from torch import nn, einsum import torch.nn.functional as F from functools import partial, wraps from inspect import isfunction from collections import namedtuple from einops import rearrange, repeat, reduce from einops.layers.torch import Rearrange from x_transfo...
EXA-1-master
exa/libraries/x-transformers/x_transformers/x_transformers.py
from x_transformers.x_transformers import XTransformer, Encoder, Decoder, CrossAttender, Attention, TransformerWrapper, ViTransformerWrapper, ContinuousTransformerWrapper from x_transformers.autoregressive_wrapper import AutoregressiveWrapper from x_transformers.nonautoregressive_wrapper import NonAutoregressiveWrappe...
EXA-1-master
exa/libraries/x-transformers/x_transformers/__init__.py
import torch from torch import nn import torch.nn.functional as F def exists(val): return val is not None class ContinuousAutoregressiveWrapper(nn.Module): def __init__(self, net, ignore_index = -100, pad_value = 0): super().__init__() self.net = net self.max_seq_len = net.max_seq_len ...
EXA-1-master
exa/libraries/x-transformers/x_transformers/continuous_autoregressive_wrapper.py
import math from random import random from contextlib import nullcontext from collections import namedtuple import torch import torch.nn.functional as F from torch import nn from einops import rearrange, repeat, pack, unpack from x_transformers.x_transformers import TransformerWrapper from typing import Optional # ...
EXA-1-master
exa/libraries/x-transformers/x_transformers/nonautoregressive_wrapper.py
import tqdm import torch import torch.optim as optim from x_transformers import XTransformer # constants NUM_BATCHES = int(1e5) BATCH_SIZE = 32 LEARNING_RATE = 3e-4 GENERATE_EVERY = 100 NUM_TOKENS = 16 + 2 ENC_SEQ_LEN = 32 DEC_SEQ_LEN = 64 + 1 # helpers def cycle(): while True: prefix = torch.ones((BAT...
EXA-1-master
exa/libraries/x-transformers/examples/toy_tasks/enc_dec_copy.py
from x_transformers import ( TransformerWrapper, Encoder, NonAutoregressiveWrapper ) import random import tqdm import gzip import numpy as np import torch import torch.optim as optim from torch.nn import functional as F from torch.utils.data import DataLoader, Dataset # constants NUM_BATCHES = int(1e8) B...
EXA-1-master
exa/libraries/x-transformers/examples/enwik8_simple/train_nar.py
from x_transformers import TransformerWrapper, Decoder from x_transformers.autoregressive_wrapper import AutoregressiveWrapper import random import tqdm import gzip import numpy as np import torch import torch.optim as optim from torch.nn import functional as F from torch.utils.data import DataLoader, Dataset # const...
EXA-1-master
exa/libraries/x-transformers/examples/enwik8_simple/train.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as cudnn import torchvision.tran...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_bss.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np from itertools import chain import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as c...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_kd.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np from itertools import chain import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as c...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_ft.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as cudnn import torchvision.tran...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_dml.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np from itertools import chain import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as c...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_crd.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import numpy as np from PIL import Image import torchvision.datasets as dst ''' Modified from https://github.com/HobbitLong/RepDistiller/blob/master/dataset/cifar100.py ''' class CIFAR10IdxSample(dst...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/dataset.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import shutil import numpy as np import torch class AverageMeter(object): def __init__(self): self.reset() def reset(self): self.val = 0 self.avg = 0 self.sum = 0 self.count = 0 ...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/utils.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn def define_tsnet(name, num_class, cuda=True): if name == 'resnet20': net = resnet20(num_class=num_class) elif name == 'resnet110': net = resnet110(num_class=num_class) ...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/network.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys import time import logging import argparse import numpy as np import torch import torch.nn as nn import torch.nn.functional as F import torch.backends.cudnn as cudnn import torchvision.tran...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/train_base.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F import math ''' CC with P-order Taylor Expansion of Gaussian RBF kernel ''' class CC(nn.Module): ''' Correlation Congruence for Knowledge Di...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/cc.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F import numpy as np def conv1x1(in_channels, out_channels): return nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, p...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/vid.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class AB(nn.Module): ''' Knowledge Transfer via Distillation of Activation Boundaries Formed by Hidden Neurons https://arxiv.org/pdf/1811.0...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/ab.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F import math ''' In the original paper, AFD is one of components of AFDS. AFDS: Attention Feature Distillation and Selection AFD: Attention Fea...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/afd.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class SoftTarget(nn.Module): ''' Distilling the Knowledge in a Neural Network https://arxiv.org/pdf/1503.02531.pdf ''' def __init__(self,...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/st.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class IRG(nn.Module): ''' Knowledge Distillation via Instance Relationship Graph http://openaccess.thecvf.com/content_CVPR_2019/papers/ Li...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/irg.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F # ''' # NST with Polynomial Kernel, where d=2 and c=0 # It can be treated as matching the Gram matrix of two vectorized feature map. # ''' # c...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/nst.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class FT(nn.Module): ''' araphrasing Complex Network: Network Compression via Factor Transfer http://papers.nips.cc/paper/7541-paraphrasing...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/ft.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class SP(nn.Module): ''' Similarity-Preserving Knowledge Distillation https://arxiv.org/pdf/1907.09682.pdf ''' def __init__(self): supe...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/sp.py
from .logits import Logits from .st import SoftTarget from .at import AT from .fitnet import Hint from .nst import NST from .pkt import PKTCosSim from .fsp import FSP from .ft import FT from .dml import DML from .kdsvd import KDSVD from .rkd import RKD from .ab import AB from .sp import SP from .sobolev import Sobolev ...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/__init__.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F ''' AT with sum of absolute values with power p ''' class AT(nn.Module): ''' Paying More Attention to Attention: Improving the Performance o...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/at.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F ''' From https://github.com/lenscloth/RKD/blob/master/metric/loss.py ''' class RKD(nn.Module): ''' Relational Knowledge Distillation https:...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/rkd.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import grad ''' LwM is originally an incremental learning method with classification/distillation/attention distillation l...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/lwm.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd.gradcheck import zero_gradients ''' Modified by https://github.com/bhheo/BSS_distillation ''' def reduce_sum(x, keepdim=Tru...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/bss.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class Logits(nn.Module): ''' Do Deep Nets Really Need to be Deep? http://papers.nips.cc/paper/5484-do-deep-nets-really-need-to-be-deep.pdf ...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/logits.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F ''' Adopted from https://github.com/passalis/probabilistic_kt/blob/master/nn/pkt.py ''' class PKTCosSim(nn.Module): ''' Learning Deep Repres...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/pkt.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class FSP(nn.Module): ''' A Gift from Knowledge Distillation: Fast Optimization, Network Minimization and Transfer Learning http://openacce...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/fsp.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import grad class Sobolev(nn.Module): ''' Sobolev Training for Neural Networks https://arxiv.org/pdf/1706.04859.pdf K...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/sobolev.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F class Hint(nn.Module): ''' FitNets: Hints for Thin Deep Nets https://arxiv.org/pdf/1412.6550.pdf ''' def __init__(self): super(Hint, se...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/fitnet.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F ''' DML with only two networks ''' class DML(nn.Module): ''' Deep Mutual Learning https://zpascal.net/cvpr2018/Zhang_Deep_Mutual_Learning_C...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/dml.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F import numpy as np ''' Modified from https://github.com/clovaai/overhaul-distillation/blob/master/CIFAR-100/distiller.py ''' class OFD(nn.Modu...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/ofd.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch import torch.nn as nn import torch.nn.functional as F import math ''' Modified from https://github.com/HobbitLong/RepDistiller/tree/master/crd ''' class CRD(nn.Module): ''' Contrastive Represent...
EXA-1-master
exa/libraries/Knowledge-Distillation-Zoo/kd_losses/crd.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 datetime import distutils.command.clean import glob import importlib.util import json impo...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 subprocess from pathlib import Path from typing import Optional from packaging import version # TODO: consolidate...
EXA-1-master
exa/libraries/xformers/packaging/compute_wheel_version.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 argparse import os import shutil import subprocess from dataclasses import dataclass, field from pathlib import Pat...
EXA-1-master
exa/libraries/xformers/packaging/build_conda.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.
EXA-1-master
exa/libraries/xformers/experimental/__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. from setuptools import setup setup( name="ragged_inference", author="Facebook AI Research", version="0.0.0"...
EXA-1-master
exa/libraries/xformers/experimental/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. import pytest import torch from ragged_inference.test_utils import assert_eq, bf16_support from ragged_inference.triton_...
EXA-1-master
exa/libraries/xformers/experimental/tests/test_triton_v2_matmul.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 time import pytest import torch from ragged_inference.garbage_pad_ragged_acts import RaggedActivations from ragg...
EXA-1-master
exa/libraries/xformers/experimental/tests/test_seq_kv_cache.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 time import pytest import torch from ragged_inference.test_utils import assert_eq, bf16_support from ragged_infe...
EXA-1-master
exa/libraries/xformers/experimental/tests/test_triton_v2_qk_dotprod.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 time import pytest import torch from ragged_inference.garbage_pad_ragged_acts import RaggedActivations from ragg...
EXA-1-master
exa/libraries/xformers/experimental/tests/test_triton_v2_ragged_qk_dotprod.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, Dict, Tuple import numpy as np import torch _DTYPE_PRECISIONS = { torch.float16: (1e-3, 1e...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/test_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.
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/__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. from typing import List import numpy as np import torch import triton import triton.language as tl @triton.jit def ga...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/garbage_pad_ragged_acts.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 functools import lru_cache from typing import List, Tuple import torch from ragged_inference.garbage_pad_ragged_ac...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/seq_kv_cache.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 import triton import triton.language as tl from triton.ops.matmul_perf_model import early_config_prune, est...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/triton_v2_qk_dotprod.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 import triton import triton.language as tl from triton.ops.matmul_perf_model import early_config_prune, est...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/triton_v2_matmul.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 dataclasses import dataclass from typing import List, Optional import torch import triton import triton.language as...
EXA-1-master
exa/libraries/xformers/experimental/ragged_inference/triton_v2_ragged_qk_dotprod.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 import xformers try: import timm from timm.models.vision_transformer import VisionTr...
EXA-1-master
exa/libraries/xformers/tests/test_timm_sparse.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...
EXA-1-master
exa/libraries/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 pytest import torch import xformers from xformers.components import MultiHeadDispatch from xformers.components.at...
EXA-1-master
exa/libraries/xformers/tests/test_triton_blocksparse.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 import xformers from xform...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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 import xformers try: ...
EXA-1-master
exa/libraries/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.factory import xFormer, xFormerConfig from xformers.helpers.hierarchical_configs import ( ...
EXA-1-master
exa/libraries/xformers/tests/test_hierarchical_transformer.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, ) ...
EXA-1-master
exa/libraries/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 import xformers try: f...
EXA-1-master
exa/libraries/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.
EXA-1-master
exa/libraries/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 copy import functools import random from contextlib import nullcontext from typing import ContextManager, Optional...
EXA-1-master
exa/libraries/xformers/tests/test_swiglu.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 from xformers...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 NormalizationType, PreNorm class Passthrough(torch.nn.Modu...
EXA-1-master
exa/libraries/xformers/tests/test_residual.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...
EXA-1-master
exa/libraries/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 torch import nn from xformers import _is_triton_available from xformers.components.atten...
EXA-1-master
exa/libraries/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 import xformers from xforme...
EXA-1-master
exa/libraries/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 random import pytest import torch import xformers.ops as xops from .utils import assert_allclose cuda_only = p...
EXA-1-master
exa/libraries/xformers/tests/test_indexing.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 PatchEmbeddingConfig, build_patch_embedding from xformers.com...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 from torch.utils._python_dispatch import TorchDispatchMode, _get_current_dispatch_mode import...
EXA-1-master
exa/libraries/xformers/tests/test_profiler.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 random from typing import List, Optional, Sequence, Tuple, Type, TypeVar import pytest import torch f...
EXA-1-master
exa/libraries/xformers/tests/test_mem_eff_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 # Automatically fetch all registered attentions and Feedforwards from xformers.components imp...
EXA-1-master
exa/libraries/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 torch def assert_allclose( out: torch.Tensor, ref: torch.Tensor, msg: str = "failed", atol: floa...
EXA-1-master
exa/libraries/xformers/tests/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 pytest import torch from xformers.components.attention import maybe_sparsify from xformers.components.attention._...
EXA-1-master
exa/libraries/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 from xformers.ops import masked...
EXA-1-master
exa/libraries/xformers/tests/test_sparse_tensors.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: Initially suggested by Jason Ramapuram, see # https://github.com/facebookresearch/xformers/issues/203 import ...
EXA-1-master
exa/libraries/xformers/tests/test_pickling.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 from xformers.components...
EXA-1-master
exa/libraries/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. import math from typing import Tuple import pytest import torch from xformers.components import ( InputProjection, ...
EXA-1-master
exa/libraries/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(): ...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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 import xformers.ops @pytest.mark.parametrize("contiguous", [True, False]) @p...
EXA-1-master
exa/libraries/xformers/tests/test_unbind.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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 import xformers SHAPES = [ (384, 128), (8 * 384, 128), (34, 128), (16, 128)...
EXA-1-master
exa/libraries/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 import xformers.factory.weight_init as xformers_weight_in...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 random import pytest import torch from xformers.factory.model_factory import xFormer, xFormerConfig BATCH = 2 S...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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. import pytorch_lightning as pl import torch from pl_bolts.datamodules import CIFAR10DataModule from torch import nn from...
EXA-1-master
exa/libraries/xformers/examples/cifar_MetaFormer.py