repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/a2c.py
import numpy import torch import torch.nn.functional as F from torch_ac.algos.base import BaseAlgo class A2CAlgo(BaseAlgo): """The Advantage Actor-Critic algorithm.""" def __init__(self, envs, acmodel, device=None, num_frames_per_proc=None, discount=0.99, lr=0.01, gae_lambda=0.95, entropy_co...
3,659
31.972973
117
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/ppo.py
import numpy import torch import torch.nn.functional as F from torch.distributions import Categorical, Normal from torch_ac.algos.base import BaseAlgo class PPOAlgo(BaseAlgo): """The Proximal Policy Optimization algorithm ([Schulman et al., 2015](https://arxiv.org/abs/1707.06347)).""" def __init__(self, e...
7,578
40.190217
146
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/hier_base.py
from abc import ABC, abstractmethod import torch from envs.wrappers import WaitWrapper from torch_ac.format import default_preprocess_obss from torch_ac.torch_utils import DictList, ParallelEnv import numpy as np # PPO with a high level and low level policy. The high level policy only takes a step every `skill_len` s...
15,578
45.924699
141
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/_hier_policy_opt.py
import torch, torch.nn.functional as F from torch_ac.torch_utils import DictList, ParallelEnv import numpy as np import pdb import copy import random ## Samples the environment using the policy. Uses the standard RL framework where the policy observes each observation. def collect_experiences(self): # Reset the e...
21,280
39.768199
156
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/__init__.py
from torch_ac.algos.a2c import A2CAlgo from torch_ac.algos.ppo import PPOAlgo from torch_ac.algos.hier_ppo import HierPPOAlgo from torch_ac.algos.hrl_policy_planner import HierPolicyAlgo
187
36.6
60
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/torch_ac/algos/hrl_policy_planner.py
import torch from envs.wrappers import WaitWrapper from torch_ac.format import default_preprocess_obss from torch_ac.torch_utils import DictList, ParallelEnv import numpy as np # PPO with a high level and low level policy. The high level policy only takes a step every `skill_len` steps. class HierPolicyAlgo: """T...
6,453
44.77305
180
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/storage.py
import csv import os import torch import logging import sys import utils def create_folders_if_necessary(path): dirname = os.path.dirname(path) if not os.path.isdir(dirname): os.makedirs(dirname) def get_storage_dir(): if "RL_STORAGE" in os.environ: return os.environ["RL_STORAGE"] r...
2,148
22.877778
102
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/format.py
import os import json import numpy as np import re import torch import torch_ac import gym import utils def get_obss_preprocessor(obs_space): # # LidarEnv-v0 if isinstance(obs_space, gym.spaces.Box): obs_space = {'obs': obs_space.shape} def preprocess_obss(obss, device=None): ret...
5,197
41.606557
172
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/agent.py
import torch import utils from flat_model import ACModel class Agent: """An agent. It is able: - to choose an action given an observation, - to analyze the feedback (i.e. reward and done state) of its action.""" def __init__(self, obs_space, action_space, model_dir, device=None...
2,002
34.767857
117
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/hier_agent.py
import torch import torch.nn.functional as F import utils from hier_policy_value_models import HighPolicyValueModel, LoPolicyValueModel from dynamics_model import LatentDynamicsModel from env_model import getHiEnvEncoder class HierAgent: """An agent. It is able: - to choose an action given an observation...
1,973
34.890909
105
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/__init__.py
from torch_ac.torch_utils.dictlist import DictList from torch_ac.torch_utils.penv import ParallelEnv from .agent import * from .hier_agent import * from .format import * from .other import * from .storage import *
215
23
50
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/src/utils/other.py
import random import numpy import torch import collections def seed(seed): random.seed(seed) numpy.random.seed(seed) torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed) def synthesize(array): d = collections.OrderedDict() d["mean"] = numpy.mean(arra...
434
18.772727
40
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/measure_env_variance.py
import argparse import time import numpy import torch import pickle import os import utils from envs.make_env import make_test_env, make_fixed_env # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--env", required=True, help="name of the environment to be run (REQUIRED)") ...
2,010
26.175676
101
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/evaluate.py
import argparse import time import numpy import torch import os import pickle import utils from envs.make_env import make_test_env, make_fixed_env # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--env", required=True, help="name of the environment to be run (REQUIRED)") ...
2,193
26.425
101
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/train_ppo.py
import argparse import time import datetime import torch import torch_ac import wandb import sys import os import utils from envs.make_env import make_train_env from flat_model import ACModel # Parse arguments parser = argparse.ArgumentParser() ## General parameters parser.add_argument("--env", required=True, ...
8,577
40.043062
153
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/train_skill_planner.py
import argparse import time import datetime import torch import torch_ac import wandb import sys import os import utils from envs.make_env import make_train_env from hier_policy_value_models import HighPolicyValueModel, LoPolicyValueModel from env_model import getHiEnvEncoder from inverse_model import InverseModel #...
12,187
43.32
193
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/evaluate_hier.py
import argparse import time import numpy import torch import os import pickle import utils from envs.make_env import make_test_env, make_fixed_env # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--env", required=True, help="name of the environment to be run (REQUIRED)") ...
2,217
25.094118
95
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/visualize_hier.py
import argparse import time import numpy as np import torch import torch.nn.functional as F import utils from envs.make_env import make_test_env # from sequence.sequence_helper import * # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--env", required=True, help="name of t...
3,077
29.475248
88
py
combinatorial-rl-tasks
combinatorial-rl-tasks-master/main/scripts/visualize.py
import argparse import time import numpy import torch import utils from envs.make_env import make_test_env, make_fixed_env # Parse arguments parser = argparse.ArgumentParser() parser.add_argument("--env", required=True, help="name of the environment to be run (REQUIRED)") parser.add_argument("--m...
2,487
27.597701
101
py
xformers
xformers-main/setup.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...
15,382
35.452607
103
py
xformers
xformers-main/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. # A MinGPT + Lightning + xFormers example Code from Sean Naren (@seannaren) # This is an hommage to https://github.com/ka...
11,054
32.704268
108
py
xformers
xformers-main/examples/cifar_ViT.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...
7,146
28.411523
117
py
xformers
xformers-main/examples/cifar_MetaFormer.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...
6,263
32.859459
120
py
xformers
xformers-main/.github/run_benchmark_wrapper.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 glob import os import shlex import subprocess import sys import torch import xformers # Build failed - return e...
1,831
24.09589
94
py
xformers
xformers-main/xformers/_cpp_lib.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 dataclasses import json import logging import os import platform from typing import Any, Dict, Optional import to...
4,479
30.77305
115
py
xformers
xformers-main/xformers/info.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 Dict import torch from . import ( __version__, _cpp_lib, _is_functorch_available, _...
2,566
31.0875
82
py
xformers
xformers-main/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. import logging import os import torch from . import _cpp_lib try: from .version import __version__ # noqa: F401 e...
1,715
23.514286
113
py
xformers
xformers-main/xformers/factory/weight_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. # CREDITS: Reusing a lot of code from the Timm repo # main difference is probably the handling of deepnorm init, and adap...
9,988
32.97619
109
py
xformers
xformers-main/xformers/factory/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 logging from dataclasses import dataclass from typing import Any, Dict, List, Optional, Union import torch from...
11,811
36.980707
115
py
xformers
xformers-main/xformers/factory/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 logging from dataclasses import asdict from typing import Optional, Tuple, Union import torch import torch.nn as...
12,830
35.042135
136
py
xformers
xformers-main/xformers/factory/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. # register components configs into Hydra ConfigStore # component config classes could be used to validate configs import ...
1,312
34.486486
87
py
xformers
xformers-main/xformers/sparse/blocksparse_tensor.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 from xformers.ops import masked_matmul logger = logging.getLogger("xformers") try: f...
11,427
31.191549
111
py
xformers
xformers-main/xformers/sparse/csr_tensor.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.ops import masked_matmul from xformers.sparse import _csr_ops from xformers.sparse.utils imp...
14,276
31.52164
93
py
xformers
xformers-main/xformers/sparse/_csr_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 torch from .utils import _csr_to_coo, _transpose_with_info def _should_use_coo(a, sparsity): if not a.is_c...
4,873
28.185629
84
py
xformers
xformers-main/xformers/sparse/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 torch def _coo_to_csr(m, n, row_indices, column_indices): # assumes coalesced coo row_offsets = row_ind...
4,274
33.475806
96
py
xformers
xformers-main/xformers/benchmarks/benchmark_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. from typing import Any, Dict, Optional import torch import triton from xformers.benchmarks.utils import TestCase, pret...
3,477
28.982759
87
py
xformers
xformers-main/xformers/benchmarks/benchmark_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. from typing import Any, Dict, List, Optional import torch import triton from xformers.benchmarks.utils import TestCase...
5,639
34.031056
87
py
xformers
xformers-main/xformers/benchmarks/benchmark_multi_head_dispatch.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 import torch import torch.nn as nn import triton from xformers.benchmarks.utils import Te...
3,365
30.754717
85
py
xformers
xformers-main/xformers/benchmarks/benchmark_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 itertools from functools import partial, reduce import timm import torch import torch.nn as nn from timm.models....
4,385
27.115385
85
py
xformers
xformers-main/xformers/benchmarks/benchmark_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. from typing import Any, Dict import torch import triton from xformers.benchmarks.utils import TestCase, pretty_plot, p...
2,683
27.860215
87
py
xformers
xformers-main/xformers/benchmarks/benchmark_revnet.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 import torch import triton from xformers.benchmarks.utils import TestCase, pretty_plot, p...
2,671
30.809524
83
py
xformers
xformers-main/xformers/benchmarks/benchmark_pytorch_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 random import time from typing import Any, Dict, List, Tuple import torch import triton from torch.cuda.amp impor...
7,631
31.067227
116
py
xformers
xformers-main/xformers/benchmarks/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 argparse import contextlib import copy import csv import glob import logging import math import os import tempfile...
21,567
31.878049
98
py
xformers
xformers-main/xformers/benchmarks/benchmark_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 itertools import random import torch from torch.utils import benchmark from utils import benchmark_main_helper ...
6,921
27.603306
110
py
xformers
xformers-main/xformers/benchmarks/benchmark_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 itertools import random from functools import partial import torch from torch.utils import benchmark from utils ...
8,889
27.222222
88
py
xformers
xformers-main/xformers/benchmarks/benchmark_sddmm.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 torch from torch.utils import benchmark from xformers.components.attention._sputnik_sparse impo...
3,658
30.008475
83
py
xformers
xformers-main/xformers/benchmarks/benchmark_encoder.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 json import time from contextlib import suppress from typing import Any, Dict, List, Optional imp...
11,164
27.775773
92
py
xformers
xformers-main/xformers/benchmarks/benchmark_nystrom_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. from typing import Callable import torch from torch.utils import benchmark from xformers.components.attention.utils imp...
3,174
30.75
88
py
xformers
xformers-main/xformers/benchmarks/benchmark_nvfuser.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 partial from typing import Any, Dict, List, Optional import torch import torch.nn as nn import tri...
8,431
32.460317
87
py
xformers
xformers-main/xformers/benchmarks/benchmark_core.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 torch from torch.utils import benchmark from xformers.components.attention.core import ( Sp...
8,527
31.926641
93
py
xformers
xformers-main/xformers/benchmarks/benchmark_mlp.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 from typing import Any, Dict import torch import triton from xformers.benchmarks.utils import TestCase...
4,199
31.8125
86
py
xformers
xformers-main/xformers/benchmarks/benchmark_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 from contextlib import nullcontext from functools import partial from typing import Any import torch f...
4,181
24.975155
87
py
xformers
xformers-main/xformers/benchmarks/benchmark_causal_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 os from typing import Any, Dict import torch import triton from xformers.benchmarks.utils import TestCase, pret...
4,885
34.405797
93
py
xformers
xformers-main/xformers/benchmarks/benchmark_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. import torch from xformers.benchmarks.utils import TestCase, bench_functions from xformers.triton.softmax import log_sof...
2,182
22.728261
79
py
xformers
xformers-main/xformers/benchmarks/benchmark_triton_stride_sum.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, List import torch import triton from xformers.benchmarks.utils import TestCase, pretty_pl...
1,823
24.333333
80
py
xformers
xformers-main/xformers/benchmarks/benchmark_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. # Benchmark the blocksparse operations: # matrix multiply and softmax # Matmul can be of three types: # - Dense x Dense...
5,099
32.774834
88
py
xformers
xformers-main/xformers/benchmarks/benchmark_blocksparse_transformers.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 gc import math from collections import namedtuple from dataclasses import dataclass import matplotlib.pyplot as ...
37,508
34.186679
114
py
xformers
xformers-main/xformers/benchmarks/LRA/run_tasks.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 json import logging import os from enum import Enum from pathlib import Path from typing import D...
9,230
29.87291
87
py
xformers
xformers-main/xformers/benchmarks/LRA/code/model_wrapper.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: adapted from the Nystromformer repo # https://github.com/mlpen/Nystromformer from enum import Enum from typi...
9,777
32.83391
94
py
xformers
xformers-main/xformers/benchmarks/LRA/code/dataset.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: Almost as-is from the Nystromformer repo # https://github.com/mlpen/Nystromformer import logging import pick...
1,403
28.87234
88
py
xformers
xformers-main/xformers/helpers/timm_sparse_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 torch from xformers.components.attention.core import scaled_dot_product_attention class TimmSparseAttention(to...
1,528
26.303571
75
py
xformers
xformers-main/xformers/helpers/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. import sys import tempfile import torch is_windows = False if sys.platform == "win32": # pytorch on windows uses gloo...
800
23.272727
71
py
xformers
xformers-main/xformers/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. import logging from typing import Optional import torch import triton from torch.cuda.amp import custom_bwd, custom_fwd...
6,377
30.264706
108
py
xformers
xformers-main/xformers/triton/sum_strided.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 from xformers.triton.k_sum import k_sum_0 def sum_2d_dim_0(x: torch.Tensor): """ S...
1,457
22.901639
93
py
xformers
xformers-main/xformers/triton/k_fused_matmul_bw.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 Optional import torch import triton import triton.language as tl from xformers.triton.k_activations...
5,155
30.82716
106
py
xformers
xformers-main/xformers/triton/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 from typing import Optional import torch logger = logging.getLogger("xformers") _gpu_is_old: Optional[...
1,187
27.97561
87
py
xformers
xformers-main/xformers/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. # CREDITS: This is heavily inspired by the Triton dropout tutorial # https://raw.githubusercontent.com/openai/triton/mas...
7,615
30.213115
104
py
xformers
xformers-main/xformers/triton/k_fused_matmul_fw.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 Optional import torch import triton import triton.language as tl from xformers.triton.k_activations ...
8,426
32.177165
102
py
xformers
xformers-main/xformers/triton/__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 torch _triton_available = torch.cuda.is_available() if _triton_available: try: from .dropout import ...
803
27.714286
71
py
xformers
xformers-main/xformers/triton/layer_norm.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: the underlying kernel comes straight from the Triton tutorials # see https://github.com/openai/triton/blob/mas...
7,659
31.320675
115
py
xformers
xformers-main/xformers/triton/fused_linear_layer.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 Any, Optional import torch import torch.nn as nn from torch.cuda.amp import custom_bwd, c...
3,931
31.766667
101
py
xformers
xformers-main/xformers/triton/k_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. import triton import triton.language as tl # CREDITS: This is adapted from the vanilla Triton example. See https://open...
5,068
27.801136
119
py
xformers
xformers-main/xformers/triton/k_activations.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 Optional import triton import triton.language as tl from xformers.components import Acti...
3,552
22.222222
93
py
xformers
xformers-main/xformers/components/simplicial_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. from dataclasses import asdict, dataclass from typing import Optional, Type, TypeVar import torch from xformers import ...
2,323
30.405405
103
py
xformers
xformers-main/xformers/components/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. from typing import List import torch import torch.nn as nn from torch.autograd.function import Function from torch.util...
5,260
32.297468
91
py
xformers
xformers-main/xformers/components/input_projection.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/pytorch/text/blob/master/torchtext/nn/modules/multiheadattention.py # and the M...
3,024
29.25
109
py
xformers
xformers-main/xformers/components/multi_head_dispatch.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 from dataclasses import asdict, dataclass from typing import Optional, Tuple import torch import torch.n...
10,169
36.666667
109
py
xformers
xformers-main/xformers/components/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. from enum import Enum from typing import List, Optional, Tuple, Union import torch import torch.nn as nn from xformers...
6,125
28.594203
87
py
xformers
xformers-main/xformers/components/activations.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 enum import Enum from typing import Optional import torch from torch import nn class Activation(str, Enum): ...
1,837
24.527778
71
py
xformers
xformers-main/xformers/components/patch_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 math from dataclasses import dataclass from enum import Enum import torch class PoolType(str, Enum): Conv2D...
2,269
27.375
105
py
xformers
xformers-main/xformers/components/positional_embedding/base.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 abc import ABCMeta, abstractmethod from dataclasses import asdict, dataclass from typing import Type, TypeVar impo...
972
26.027778
78
py
xformers
xformers-main/xformers/components/positional_embedding/rotary.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: This implementation is inspired by GPT-NeoX https://github.com/EleutherAI/gpt-neox # NOTE: Almost the same ri...
3,274
34.597826
110
py
xformers
xformers-main/xformers/components/positional_embedding/vocab.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 Optional import torch import torch.nn as nn from xformers.compone...
1,768
25.80303
83
py
xformers
xformers-main/xformers/components/positional_embedding/sine.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. # Silence Mypy errors in this file. # type: ignore import math import torch from xformers.components.positional_embed...
1,365
28.06383
81
py
xformers
xformers-main/xformers/components/positional_embedding/param.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 import torch from xformers.components.positional_embedding import ( PositionEmbe...
1,544
27.090909
83
py
xformers
xformers-main/xformers/components/feedforward/fused_mlp.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 from dataclasses import dataclass import torch import torch.nn as nn from xformers.components import Ac...
2,579
31.25
80
py
xformers
xformers-main/xformers/components/feedforward/base.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 abc import ABCMeta, abstractmethod from dataclasses import asdict, dataclass from typing import Optional, Type, Typ...
1,498
26.759259
94
py
xformers
xformers-main/xformers/components/feedforward/mlp.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 import torch import torch.nn as nn import xformers from xformers.components import A...
2,592
30.621951
82
py
xformers
xformers-main/xformers/components/feedforward/conv_mlp.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: Largely reusing the code from the reference VAN implementation # see https://github.com/Visual-Attention-Netw...
3,011
29.734694
100
py
xformers
xformers-main/xformers/components/feedforward/mixture_of_experts.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 from dataclasses import dataclass from enum import Enum from typing import Any, Callable, Optional, Union...
5,343
33.701299
115
py
xformers
xformers-main/xformers/components/attention/scaled_dot_product.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 from dataclasses import dataclass from typing import Optional, Union import torch from torch import nn f...
4,504
32.37037
115
py
xformers
xformers-main/xformers/components/attention/pooling.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 dataclasses import dataclass from typing import Optional import torch import torch.nn as nn from xfor...
2,490
29.012048
102
py
xformers
xformers-main/xformers/components/attention/base.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 abc import ABCMeta, abstractmethod from dataclasses import asdict, dataclass from typing import Optional, Type, Typ...
3,209
33.148936
120
py
xformers
xformers-main/xformers/components/attention/_sputnik_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 torch from xformers.ops import masked_matmul from xformers.sparse import SparseCSRTensor # TODO: this is here f...
3,164
24.942623
82
py
xformers
xformers-main/xformers/components/attention/compositional.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: this is heavily inspired by the official implementation, present in # https://github.com/sarthmit/Composition...
12,954
36.880117
120
py
xformers
xformers-main/xformers/components/attention/core.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 math from contextlib import nullcontext from functools import lru_cache from typing import Optiona...
10,782
30.437318
104
py
xformers
xformers-main/xformers/components/attention/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. from dataclasses import dataclass from typing import Optional, Union import torch import torch.nn as nn from xformers....
3,815
30.53719
116
py
xformers
xformers-main/xformers/components/attention/nystrom.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 from dataclasses import dataclass from typing import Optional import torch import torch.nn as nn from x...
11,405
37.533784
119
py
xformers
xformers-main/xformers/components/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. from typing import Optional import torch # Reshapes key padding mask from (batch_size, src_len) -> (batch_size * num_...
3,803
33.899083
109
py
xformers
xformers-main/xformers/components/attention/lambda_layer.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 import torch from xformers.components.attention import Attention, AttentionConfig, r...
2,814
34.632911
97
py