python_code stringlengths 0 992k | repo_name stringlengths 8 46 | file_path stringlengths 5 162 |
|---|---|---|
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
"""
This is a launcher script for launching mjrl training using hydra
"""
import os
import hydra
import multipro... | eai-vc-main | cortexbench/mujoco_vc/visual_imitation/hydra_launcher.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from mjrl.utils.gym_env import GymEnv
from mjrl.samplers.core import sample_paths
from mjrl.policies.gaussian_mlp... | eai-vc-main | cortexbench/mujoco_vc/visual_imitation/train_loop.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
core_model_set = [
"vc1_vitb",
"vc1_vitl",
]
print(",".join(core_model_set))
| eai-vc-main | cortexbench/mujoco_vc/visual_imitation/core_model_set.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import gym
ENV_TO_SUITE = {
"dmc_walker_stand-v1": "dmc",
"dmc_walker_walk-v1": "dmc",
"dmc_reacher_... | eai-vc-main | cortexbench/mujoco_vc/src/mujoco_vc/supported_envs.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import gym, dmc2gym, mjrl, mj_envs
| eai-vc-main | cortexbench/mujoco_vc/src/mujoco_vc/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from vc_models import vc_models_dir_path
from omegaconf import OmegaConf
from PIL import Image
import os
import h... | eai-vc-main | cortexbench/mujoco_vc/src/mujoco_vc/model_loading.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
import gym
from mjrl.utils.gym_env import GymEnv
from gym.spaces.box import Box
f... | eai-vc-main | cortexbench/mujoco_vc/src/mujoco_vc/gym_wrapper.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import logging
import numpy as np
from mjrl.utils.gym_env import GymEnv
from mjrl.utils import tensor_utils
from ... | eai-vc-main | cortexbench/mujoco_vc/src/mujoco_vc/rollout_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import random
from datetime import datetime
import os
import subprocess
import hydra
from omegaconf import DictConfig... | eai-vc-main | cortexbench/habitat2_vc/run_rearrangement_vc.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import wandb
from tqdm import tqdm
import pandas as pd
pd.set_option("display.max_colwidth", None)
class Wandb... | eai-vc-main | cortexbench/habitat2_vc/analysis/retrieve_results.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import hydra
import torch
from torch import nn as nn
from omegaconf import open_dict
from habitat_baselines.rl.d... | eai-vc-main | cortexbench/habitat2_vc/habitat2_vc/visual_encoder.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from typing import Dict, Optional, Tuple, List
import torch
from gym import spaces
from habitat_baselines.common... | eai-vc-main | cortexbench/habitat2_vc/habitat2_vc/policy.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | cortexbench/habitat2_vc/habitat2_vc/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from setuptools import setup
from setuptools import find_packages
install_requires = [
"hydra-core",
"w... | eai-vc-main | cortexbench/trifinger_vc/setup.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import sys
sys.path.append("../")
from trifinger_vc.utils import tf_test_util
import numpy as np
from trifinger_... | eai-vc-main | cortexbench/trifinger_vc/tests/test_tf.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | cortexbench/trifinger_vc/tests/__init__.py |
# w Copyright (c) Meta Platforms, Inc. and affiliates.
import random
import os
import torch
import numpy as np
import hydra
from omegaconf import OmegaConf
import logging
import json
import trifinger_vc.utils.train_utils as t_utils
from trifinger_vc.algos.bc_finetune import BCFinetune
# A logger for this file
log = l... | eai-vc-main | cortexbench/trifinger_vc/bc_experiments/train_bc.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import enum
import gym
import numpy as np
import pybullet
import torch
from dataclasses import dataclass
from sc... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/trifinger_envs/gym_cube_env.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from .cube_reach import CubeReachEnv
from .gym_cube_env import MoveCubeEnv
from gym.envs.registration import (
... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/trifinger_envs/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import enum
class ActionType(enum.Enum):
"""Different action types that can be used to control the robot.""... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/trifinger_envs/action.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import enum
import typing
import gym
import math
import numpy as np
import pybullet
import torch
import trifinge... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/trifinger_envs/cube_reach.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import os
import omegaconf
import hydra
import vc_models
vc_models_abs_path = os.path.dirname(os.path.abspath(vc... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/model_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
from hydra.core.hydra_config import HydraConfig
import wandb
import torch
import numpy as np... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/train_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import numpy as np
from PIL import Image
import trifinger_vc.utils.data_utils ... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/encoder_model.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import torch
import copy
def construct_policy(task_state_type,train_ft_state_shape, pretrained_dim,task_goal_typ... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/policy.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/__init__.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
import os
import torch
import numpy as np
import matplotlib.pyplot as plt
from trifinger_vc.utils.model_utils import MODEL_NAMES, get_vc_model_and_transform
import vc_models.transforms as vc_t
class BCFinetuneDataset(torch.utils.data.Dataset):
def __init__(
... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/dataset.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
import imageio
import torchvision.transfo... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/data_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import shutil
import hydra
from hydra import compose, initialize
import random
import numpy as np
import json
imp... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/tf_test_util.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
"""
Run MoveCubePolicy to generate cube re-posititioning demos
"""
import sys
import os
import argparse
import n... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/utils/sim_nn.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/algos/__init__.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
import os
import sys
import torch
import numpy as np
import logging
import trifinger_vc.utils.train_utils as t_utils
import trifinger_vc.utils.data_utils as d_utils
import trifinger_vc.control.cube_utils as c_utils
from trifinger_vc.utils.policy import construct_po... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/algos/bc_finetune.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from scipy.interpolate import interp1d
from scipy.spatial.transform import Rotation
from trif... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/control/cube_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
class ImpedanceController:
"""
Impedance controller for TriFinger robot
args:
... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/control/impedance_controller.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import pinocchio
from trifinger_simulation.pinocchio_utils import Kinematics
class CustomP... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/control/custom_pinocchio_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
DIST_FRAME_TO_SURFACE = 0.01
def get_ft_radius(finger_type):
# These are offsets to cub... | eai-vc-main | cortexbench/trifinger_vc/src/trifinger_vc/control/finger_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from setuptools import setup
from setuptools import find_packages
from setuptools import find_namespace_packages
... | eai-vc-main | vc_models/setup.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import pytest
def pytest_addoption(parser):
parser.addoption(
"--nocluster",
action="store_... | eai-vc-main | vc_models/tests/conftest.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import pytest
import os
import hydra
import omegaconf
import numpy as np
import torch
import torchvision
import P... | eai-vc-main | vc_models/tests/test_model_loading.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from hydra.core.config_search_path import ConfigSearchPath
from hydra.plugins.search_path_plugin import SearchPat... | eai-vc-main | vc_models/src/hydra_plugins/eaif_models_plugin/eaif_models_plugin.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | vc_models/src/hydra_plugins/eaif_models_plugin/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import os
vc_models_dir_path = os.path.dirname(os.path.abspath(__file__))
vc_models_config_files = os.listdir(vc_... | eai-vc-main | vc_models/src/vc_models/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from vc_models import vc_model_zoo
print(",".join(vc_model_zoo))
| eai-vc-main | vc_models/src/vc_models/__main__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import os
import logging
import omegaconf
log = logging.getLogger(__name__)
def setup_wandb(config):
try:... | eai-vc-main | vc_models/src/vc_models/utils/wandb.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import omegaconf
def get_model_tag(metadata: omegaconf.DictConfig):
if isinstance(metadata.data, omegaconf.... | eai-vc-main | vc_models/src/vc_models/utils/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch.nn as nn
def create_compression_layer(
embed_dim, final_spatial, after_comp... | eai-vc-main | vc_models/src/vc_models/models/compression_layer.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import logging
import torch
from PIL import Image
log = logging.getLogger(__name__)
zero_img = Image.new("RGB",... | eai-vc-main | vc_models/src/vc_models/models/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
import urllib
import vc_models
import hydra
import omegaconf
import six
VC1_BASE_NAME = "v... | eai-vc-main | vc_models/src/vc_models/models/vit/model_utils.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | vc_models/src/vc_models/models/vit/__init__.py |
# Copyright (c) Meta Platforms, Inc. and 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.
# --------------------------------------------------------
# adapted from:
# timm: https://github.com/rwightman/pytorch-im... | eai-vc-main | vc_models/src/vc_models/models/vit/vit.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from hydra.core.config_search_path import ConfigSearchPath
from hydra.plugins.search_path_plugin import SearchPat... | eai-vc-main | vc_models/src/vc_models/hydra_plugins/eaif_models_plugin/eaif_models_plugin.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
| eai-vc-main | vc_models/src/vc_models/hydra_plugins/eaif_models_plugin/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torchvision.transforms as T
class ToTensorIfNot(T.ToTensor):
def __call__(self, pic):
... | eai-vc-main | vc_models/src/vc_models/transforms/to_tensor_if_not.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
# Implementation borrowed from here:
# https://github.com/facebookresearch/drqv2/blob/main/drqv2.py
import torch... | eai-vc-main | vc_models/src/vc_models/transforms/random_shifts_aug.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
import torchvision.transforms as T
from vc_models.transforms.to_tensor_if_not import ToTensorIfNot
from vc_model... | eai-vc-main | vc_models/src/vc_models/transforms/__init__.py |
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the CC-BY-NC license found in the
# LICENSE file in the root directory of this source tree.
from typing import Optional
import torch
from vc_models.transforms.to_tensor_if_not import ToTensorIfNot
class ... | eai-vc-main | vc_models/src/vc_models/transforms/randomize_env_transform.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
from io import open
from setuptools import find_packages, setup
setup(
name="torchscale",
version="0.1.2",
author="TorchScale Team",
author_email="Shuming.Ma@microsoft.com",
description="Transformers at any ... | APAC-SCALE-master | setup.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | torchscale/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import numpy as np
import torch
import torch.nn as nn
def fixed_pos_embedding(x):
seq_len, dim = x.shape
inv_freq = 1.0 / (10000 ** (torch.arange(0, dim) / dim))
sinusoid_inp = (
torch.einsum("i , j -> i j", ... | APAC-SCALE-master | torchscale/component/xpos_relative_position.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import copy
import torch
import torch.nn as nn
def MultiwayWrapper(args, module, dim=1):
if args.multiway:
return MultiwayNetwork(module, dim=dim)
return module
def set_split_position(position):
def apply... | APAC-SCALE-master | torchscale/component/multiway_network.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import math
import torch
import torch.nn.functional as F
from torch import nn
try:
from apex.normalization import FusedLayerNorm as LayerNorm
except ModuleNotFoundError:
from torch.nn import LayerNorm
from .multiway_net... | APAC-SCALE-master | torchscale/component/multihead_attention.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import math
import torch
import torch.nn as nn
class RelativePositionBias(nn.Module):
def __init__(
self, bidirectional=True, num_buckets=32, max_distance=128, n_heads=12
):
super().__init__()
s... | APAC-SCALE-master | torchscale/component/relative_position_bias.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch
import torch.nn as nn
import torch.nn.functional as F
class VisionLanguageEmbedding(nn.Module):
def __init__(self, text_embed, vision_embed):
super().__init__()
self.text_embed = text_embed
... | APAC-SCALE-master | torchscale/component/embedding.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch.nn as nn
from timm.models.layers import drop_path
class DropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks)."""
def __init__(self, drop_prob=Non... | APAC-SCALE-master | torchscale/component/droppath.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | torchscale/component/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch
import torch.nn as nn
import torch.nn.functional as F
from flash_attn.flash_attention import FlashMHA
try:
from apex.normalization import FusedLayerNorm as LayerNorm
except ModuleNotFoundError:
from torch.nn... | APAC-SCALE-master | torchscale/component/feedforward_network.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | torchscale/component/xmoe/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
#
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
# NOTE: This is a mirror of th... | APAC-SCALE-master | torchscale/component/xmoe/moe_layer.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
#
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
# Implementation of Top2Gating... | APAC-SCALE-master | torchscale/component/xmoe/routing.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import math
import numpy as np
import torch
import torch.nn as nn
from fairscale.nn import checkpoint_wrapper, wrap
from torchscale.architecture.utils import init_bert_params
from torchscale.component.droppath import DropPath
f... | APAC-SCALE-master | torchscale/architecture/decoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
class EncoderConfig(object):
def __init__(self, **kwargs):
self.encoder_embed_dim = kwargs.pop("encoder_embed_dim", 768)
self.encoder_attention_heads = kwargs.pop("encoder_attention_heads", 12)
self.e... | APAC-SCALE-master | torchscale/architecture/config.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch.nn as nn
from torchscale.architecture.decoder import Decoder
from torchscale.architecture.encoder import Encoder
class EncoderDecoder(nn.Module):
def __init__(
self,
args,
encoder_embed... | APAC-SCALE-master | torchscale/architecture/encoder_decoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | torchscale/architecture/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import math
import numpy as np
import torch
import torch.nn as nn
from fairscale.nn import checkpoint_wrapper, wrap
try:
from apex.normalization import FusedLayerNorm as LayerNorm
except ModuleNotFoundError:
from torch.n... | APAC-SCALE-master | torchscale/architecture/encoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch.nn as nn
from torchscale.component.multihead_attention import MultiheadAttention
from torchscale.component.multiway_network import MultiwayNetwork
def init_bert_params(module):
def normal_(data):
data.... | APAC-SCALE-master | torchscale/architecture/utils.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch
import torch.nn as nn
from torchscale.architecture.encoder import Encoder
from torchscale.component.embedding import (
PositionalEmbedding,
TextEmbedding,
VisionEmbedding,
)
from torchscale.component.mul... | APAC-SCALE-master | torchscale/model/BEiT3.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | torchscale/model/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import pytest
import torch
from torchscale.architecture.config import DecoderConfig
from torchscale.architecture.decoder import Decoder
testcases = [
{},
{"vocab_size": 64000},
{"activation_fn": "relu"},
{"drop_... | APAC-SCALE-master | tests/test_decoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import pytest
import torch
from torchscale.architecture.config import EncoderConfig
from torchscale.architecture.encoder import Encoder
testcases = [
{},
{"vocab_size": 64000},
{"activation_fn": "relu"},
{"drop_... | APAC-SCALE-master | tests/test_encoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | tests/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import pytest
import torch
from torchscale.architecture.config import EncoderDecoderConfig
from torchscale.architecture.encoder_decoder import EncoderDecoder
from torchscale.component.embedding import PositionalEmbedding, TextEm... | APAC-SCALE-master | tests/test_encoder_decoder.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | examples/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# flake8: noqa
import models
import tasks
import criterions
from fairseq_cli.generate import cli_main
if __name__ == "__main__":
cli_main()
| APAC-SCALE-master | examples/fairseq/generate.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | examples/fairseq/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# flake8: noqa
import models
import tasks
import criterions
from fairseq_cli.interactive import cli_main
if __name__ == "__main__":
cli_main()
| APAC-SCALE-master | examples/fairseq/interactive.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# flake8: noqa
import models
import tasks
import criterions
from fairseq_cli.train import cli_main
if __name__ == "__main__":
cli_main()
| APAC-SCALE-master | examples/fairseq/train.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import json
import logging
import os
from argparse import Namespace
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of t... | APAC-SCALE-master | examples/fairseq/tasks/pretraining.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import argparse
import importlib
import os
# register dataclass
TASK_DATACLASS_REGISTRY = {}
TASK_REGISTRY = {}
TASK_CLASS_NAMES = set()
# automatically import any Python files in the tasks/ directory
tasks_dir = os.path.dirnam... | APAC-SCALE-master | examples/fairseq/tasks/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import torch
from infinibatch.iterators import CheckpointableIterator
from . import utils
class BaseBatchGen(CheckpointableIterator):
"""
This is a base class for batch generators that use infinibatch
"""
def ... | APAC-SCALE-master | examples/fairseq/tasks/data/basic_loader.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | examples/fairseq/tasks/data/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import collections
from random import Random
from typing import Dict, Iterable, Optional
import numpy as np
from infinibatch import iterators
def apply_to_sample(f, sample):
if hasattr(sample, "__len__") and len(sample) ==... | APAC-SCALE-master | examples/fairseq/tasks/data/utils.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import copy
import itertools
import os
import numpy as np
from infinibatch import iterators
from .basic_loader import BaseBatchGen
from .utils import NativeCheckpointableIterator, WeightIterator
class MLMLoader(BaseBatchGen):... | APAC-SCALE-master | examples/fairseq/tasks/data/mlm_loader.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import math
import warnings
import torch
import torch.distributed as dist
from fairseq.utils import multi_tensor_l2norm_available, multi_tensor_total_norm
@torch.no_grad()
def clip_grad_norm_(
params, max_norm, moe_expert_... | APAC-SCALE-master | examples/fairseq/utils/sparse_clip.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
| APAC-SCALE-master | examples/fairseq/utils/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
from dataclasses import dataclass, f... | APAC-SCALE-master | examples/fairseq/models/language_modeling.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import argparse
import importlib
import os
MODEL_REGISTRY = {}
MODEL_DATACLASS_REGISTRY = {}
ARCH_MODEL_REGISTRY = {}
ARCH_MODEL_NAME_REGISTRY = {}
ARCH_MODEL_INV_REGISTRY = {}
ARCH_CONFIG_REGISTRY = {}
# automatically import a... | APAC-SCALE-master | examples/fairseq/models/__init__.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
from typing import Dict, List, Optio... | APAC-SCALE-master | examples/fairseq/models/machine_translation.py |
# Copyright (c) 2022 Microsoft
# Licensed under The MIT License [see LICENSE for details]
import logging
from dataclasses import dataclass, field
from typing import Optional
import torch
import torch.nn as nn
import torch.nn.functional as F
from fairseq import utils
from fairseq.dataclass import ChoiceEnum, FairseqDa... | APAC-SCALE-master | examples/fairseq/models/bert.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 MoECriterion, regis... | APAC-SCALE-master | examples/fairseq/criterions/masked_lm_moe.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.