python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
# 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. import torch import torch.nn.functional as F import numpy as np from tqdm import tqdm from scipy.spatial import KDTree ...
CT2Hair-main
CT2Hair/modules/strands_opt.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. import os import csv import torch import torch.nn as nn from modules.networks import * from utils.utils import batched...
CT2Hair-main
CT2Hair/modules/strands_codec.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. import copy import torch import inspect import numpy as np from typing import Dict, List, Optional, Tuple from torch.nn...
CT2Hair-main
CT2Hair/modules/networks.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. import os import sys import argparse from pyhocon import ConfigFactory from termcolor import colored sys.path.append('C...
CT2Hair-main
scripts/interpolation.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. import os import sys import argparse from pyhocon import ConfigFactory from termcolor import colored sys.path.append('C...
CT2Hair-main
scripts/optimization.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. import os import platform import argparse from pyhocon import ConfigFactory from termcolor import colored parser = argp...
CT2Hair-main
scripts/est_orientations.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. import os import platform import argparse from shutil import copyfile from pyhocon import ConfigFactory from termcolor i...
CT2Hair-main
scripts/gen_guide_strands.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/decoder.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/generator_attnet.py
corefnmn-main
models_vd/__init__.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/assembler.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/model.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/generator.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/modules.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_vd/executor.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/metrics.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/support.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/clean.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/convert_nmn_layouts.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/extract_coreference_supervision.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/text_processing.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/collect_glove_features.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/build_imdb_mnist.py
corefnmn-main
util/__init__.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/cnn.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/dataset_to_text.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/compress_parser_trees.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/build_imdb.py
#!/usr/bin/env python2 """Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root...
corefnmn-main
util/parse.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
util/empty_safe_conv.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
exp_mnist/options.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
exp_mnist/visualize_sl.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
exp_mnist/eval_sl.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
exp_mnist/train_sl.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
loader_mnist/data_reader.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
vis/html.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
vis/visualize_dialogs.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/decoder.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/generator_attnet.py
corefnmn-main
models_mnist/__init__.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/assembler.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/model.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/generator.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/modules.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
models_mnist/executor.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
loader_vd/data_reader.py
"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sour...
corefnmn-main
exp_vd/options.py
r"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sou...
corefnmn-main
exp_vd/visualize_sl.py
r"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sou...
corefnmn-main
exp_vd/eval_sl.py
r"""Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. This source code is licensed under the license found in the LICENSE file in the root directory of this source tree. Portions of the source code are from the n2nmn project which notice below and in LICENSE.n2nmn in the root directory of this sou...
corefnmn-main
exp_vd/train_sl.py
# -*- coding: utf-8 -*- """HyenaDNA training & inference example (Public) This code is adapted from the original colab tutorial on HyenaDNA. Check that out for an easier entry point into the code. We provide the code here as an example for those who want something outside collab, with Huggingface integration. Origin...
hyena-dna-main
standalone_hyenadna.py
#@title Huggingface Pretrained Wrapper """ This is script is a simple HuggingFace wrapper around a HyenaDNA model, to enable a one click example of how to load the pretrained weights and get embeddings. It will instantiate a HyenaDNA model (model class is in the `standalone_hyenadna.py`), and handle the downloading...
hyena-dna-main
huggingface.py
import copy import os import random import time from functools import partial, wraps from typing import Callable, List, Sequence import hydra import numpy as np import pytorch_lightning as pl import torch import torch.nn as nn import wandb from hydra.utils import get_original_cwd from omegaconf import DictConfig, Omeg...
hyena-dna-main
train.py
import torch import torch.nn.functional as F from einops import rearrange from fftconv import fftconv_fwd, fftconv_bwd def fftconv_ref(u, k, D, dropout_mask): seqlen = u.shape[-1] fft_size = 2 * seqlen k_f = torch.fft.rfft(k, n=fft_size) / fft_size u_f = torch.fft.rfft(u.to(dtype=k.dtype), n=fft_siz...
hyena-dna-main
csrc/fftconv/launch_fftconv.py
# Adapted from https://github.com/NVIDIA/apex/blob/master/setup.py import torch from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension, CUDA_HOME from setuptools import setup, find_packages import subprocess import sys import warnings import os # ninja build does not work unless include_dir...
hyena-dna-main
csrc/fftconv/setup.py
import math import re import numpy as np # N = 8192 N = 16384 # The case of 0 / N is special, we want to simplify it to 0 / 2 instead of 0 / 1 numerator = np.arange(1, N // 8 + 1) gcd = np.gcd(numerator, N) num = numerator // gcd denom = N // gcd lut_vals = ['T_2_0'] + [f'T_{d}_{n}' for n, d in zip(num, denom)] lut_...
hyena-dna-main
csrc/fftconv/lut_code_gen.py
#!/usr/bin/env python3 import argparse import yaml from tqdm import tqdm import typing as tp import numpy as np import pandas as pd from copy import deepcopy from collections import OrderedDict import torch torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = True import torch.nn.functional ...
hyena-dna-main
evals/soft_prompting_genomics.py
#!/usr/bin/env python3 import argparse import yaml from tqdm import tqdm import typing as tp import numpy as np import pandas as pd from copy import deepcopy from collections import OrderedDict import torch torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = True import torch.nn.functional ...
hyena-dna-main
evals/instruction_tuned_genomics.py
import torch import argparse import os import sys import yaml from tqdm import tqdm import json from src.models.sequence.long_conv_lm import DNAEmbeddingModel from src.tasks.decoders import SequenceDecoder from src.dataloaders import SequenceDataset import numpy as np from src.dataloaders.datasets.hg38_char_token...
hyena-dna-main
evals/hg38_inference_decoder.py
import torch import argparse import os import sys import yaml from tqdm import tqdm import json sys.path.append(os.environ.get("SAFARI_PATH", ".")) from src.models.sequence.long_conv_lm import ConvLMHeadModel # from transformers import AutoTokenizer, GPT2LMHeadModel # from spacy.lang.en.stop_words import STOP_WO...
hyena-dna-main
evals/hg38_inference.py
import math import torch import torch.nn.functional as F from sklearn.metrics import f1_score, roc_auc_score from functools import partial import torchmetrics.functional as tm_f import torch.distributions as dist from sklearn.metrics import f1_score, roc_auc_score, matthews_corrcoef from torchmetrics import Metric from...
hyena-dna-main
src/tasks/metrics.py
# Inspired by https://github.com/NVIDIA/NeMo/blob/main/nemo/collections/common/metrics/perplexity.py # But we compute the perplexity correctly: exp(average(nll)), not average(exp(nll)) # Also adapted from https://github.com/Lightning-AI/metrics/blob/master/src/torchmetrics/text/perplexity.py # But we pass in the loss t...
hyena-dna-main
src/tasks/torchmetrics.py
from typing import Optional, List, Tuple import math import functools import collections import torch import torch.nn as nn import torch.nn.functional as F from einops import rearrange from omegaconf import ListConfig from src.models.nn.components import ReversibleInstanceNorm1dInput, ReversibleInstanceNorm1dOutput, \ ...
hyena-dna-main
src/tasks/tasks.py
import torch import torch.nn as nn import torch.nn.functional as F from einops import rearrange, reduce import src.models.nn.utils as U import src.utils as utils import src.utils.config import src.utils.train log = src.utils.train.get_logger(__name__) class Decoder(nn.Module): """This class doesn't do much but ...
hyena-dna-main
src/tasks/decoders.py
import datetime import math from typing import ForwardRef import torch from torch import nn import torch.nn.functional as F from einops import rearrange, repeat import src.models.nn.utils as U import src.utils as utils import src.utils.config from src.models.sequence.block import SequenceResidualBlock from src.models...
hyena-dna-main
src/tasks/encoders.py
from typing import Any import pytorch_lightning as pl from pytorch_lightning.utilities import rank_zero_only from pytorch_lightning.utilities.parsing import AttributeDict class ParamsLog(pl.Callback): """ Log the number of parameters of the model """ def __init__( self, total: bool = True, ...
hyena-dna-main
src/callbacks/params.py
import torch from pytorch_lightning import Callback, Trainer, LightningModule import logging log = logging.getLogger(__name__) # We want a logger for each process, not just the rank 0 def l2_promote(): import ctypes _libcudart = ctypes.CDLL('libcudart.so') # Set device limit on the current device ...
hyena-dna-main
src/callbacks/gpu_affinity.py
### https://github.com/HazyResearch/transformers/blob/master/src/callbacks/wandb_callbacks.py import glob import os from typing import List import matplotlib.pyplot as plt import pandas as pd import seaborn as sn import torch import wandb from pytorch_lightning import Callback, Trainer from pytorch_lightning.loggers ...
hyena-dna-main
src/callbacks/wandb.py
### https://github.com/HazyResearch/transformers/blob/master/src/callbacks/speed_monitor.py # Adapted from https://pytorch-lightning.readthedocs.io/en/latest/_modules/pytorch_lightning/callbacks/gpu_stats_monitor.html#GPUStatsMonitor # We only need the speed monitoring, not the GPU monitoring import time from typing i...
hyena-dna-main
src/callbacks/timer.py
r""" Sequence Length Warmup by Reloading ==================== Change sequence lengths according to a stage schedule. The stage parameters sets the sequence length and batch size. TODO (not yet supported): If batch size is not provided for that stage, calculate the batch size based on the sequence length reshaping in...
hyena-dna-main
src/callbacks/seqlen_warmup_reload.py
import pytorch_lightning as pl from pytorch_lightning.utilities import rank_zero_only from pytorch_lightning.utilities.parsing import AttributeDict from omegaconf import OmegaConf class TrackNorms(pl.Callback): # TODO do callbacks happen before or after the method in the main LightningModule? # @rank_zero_onl...
hyena-dna-main
src/callbacks/norms.py
import numpy as np from pytorch_lightning.callbacks import Callback import src.utils as utils from src.utils import registry class ProgressiveResizing(Callback): def __init__(self, stage_params: list): """ stage_params is a list of dicts e.g. stage_params = [ {'resolution': 4...
hyena-dna-main
src/callbacks/progressive_resizing.py
""" ET Dataset from Informer Paper. Dataset: https://github.com/zhouhaoyi/ETDataset Dataloader: https://github.com/zhouhaoyi/Informer2020 """ from typing import List import os import numpy as np import pandas as pd from pandas.tseries import offsets from pandas.tseries.frequencies import to_offset import torch from to...
hyena-dna-main
src/dataloaders/et.py
from . import et, genomics from .base import SequenceDataset
hyena-dna-main
src/dataloaders/__init__.py
# Adapted from https://github.com/huggingface/transformers/blob/master/examples/pytorch/language-modeling/run_clm.py # Adapted from https://github.com/HazyResearch/flash-attention/blob/main/training/src/datamodules/language_modeling_hf.py from pathlib import Path from typing import Any, List, Union from torch.utils.dat...
hyena-dna-main
src/dataloaders/genomics.py
# Adapted from https://github.com/Lightning-AI/lightning/blob/2845e7565dbe6b765ae32870e7d2bc456529c30a/tests/tests_pytorch/utilities/test_auto_restart.py#L1397 from typing import Iterator import math import torch from torch.utils.data import RandomSampler, DistributedSampler class RandomFaultTolerantSampler(RandomSa...
hyena-dna-main
src/dataloaders/fault_tolerant_sampler.py
""" Datasets for core experimental results """ import os import pickle from functools import partial from pathlib import Path import numpy as np import torch import torchvision from einops import rearrange from einops.layers.torch import Rearrange from src.utils import is_list, permutations from torch.nn import funct...
hyena-dna-main
src/dataloaders/base.py
import torch import csv import pandas as pd import numpy as np from tqdm import tqdm import liftover from pathlib import Path from pyfaidx import Fasta from random import randrange, random def exists(val): return val is not None def coin_flip(): return random() > 0.5 string_complement_map = {'A': 'T', 'C': ...
hyena-dna-main
src/dataloaders/datasets/chromatin_profile_dataset.py
from pyfaidx import Fasta import torch from random import random from pathlib import Path from src.dataloaders.datasets.hg38_char_tokenizer import CharacterTokenizer def coin_flip(): return random() > 0.5 # augmentations string_complement_map = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'a': 't', 'c': 'g', 'g': ...
hyena-dna-main
src/dataloaders/datasets/nucleotide_transformer_dataset.py
from itertools import islice from functools import partial import os import functools # import json # from pathlib import Path # from pyfaidx import Fasta # import polars as pl # import pandas as pd import torch from random import randrange, random import numpy as np from pathlib import Path from src.dataloaders.data...
hyena-dna-main
src/dataloaders/datasets/genomic_bench_dataset.py
""" From: https://github.com/dariush-bahrami/character-tokenizer/blob/master/charactertokenizer/core.py CharacterTokenzier for Hugging Face Transformers. This is heavily inspired from CanineTokenizer in transformers package. """ import json import os from pathlib import Path from typing import Dict, List, Optional, S...
hyena-dna-main
src/dataloaders/datasets/hg38_char_tokenizer.py
from pathlib import Path from pyfaidx import Fasta import polars as pl import pandas as pd import torch from random import randrange, random import numpy as np """ Dataset for sampling arbitrary intervals from the human genome. """ # helper functions def exists(val): return val is not None def coin_flip():...
hyena-dna-main
src/dataloaders/datasets/hg38_dataset.py
# Inspired by https://github.com/NVIDIA/Megatron-LM/blob/main/tasks/zeroshot_gpt/datasets.py # Except we don't pad the last block and don't use overlapping eval # And we return both the input and the target import math import numpy as np import torch class LMDataset(torch.utils.data.Dataset): def __init__(self,...
hyena-dna-main
src/dataloaders/datasets/lm_dataset.py
import torch from random import random, randint import numpy as np from pathlib import Path from src.dataloaders.datasets.hg38_char_tokenizer import CharacterTokenizer from genomic_benchmarks.loc2seq import download_dataset from genomic_benchmarks.data_check import is_downloaded """ In-Context learning version of G...
hyena-dna-main
src/dataloaders/datasets/icl_genomics_dataset.py
from itertools import islice from functools import partial # import tensorflow as tf import os import functools import json from pathlib import Path from pyfaidx import Fasta import polars as pl import pandas as pd import torch from random import randrange, random, randint import numpy as np from src.dataloaders.datase...
hyena-dna-main
src/dataloaders/datasets/hg38_icl_dataset.py
import os from pathlib import Path from pyfaidx import Fasta import torch import shutil import gzip import random from typing import Optional, Union, Dict, List from src.dataloaders.datasets.hg38_char_tokenizer import CharacterTokenizer import collections """ Dataset that randomly samples sequences of length (X) from ...
hyena-dna-main
src/dataloaders/datasets/species_dataset.py
from pathlib import Path from pyfaidx import Fasta import torch """ Just a fixed length dataset for 2 test chromosomes, to ensure the test set is the same. """ # helper functions def exists(val): return val is not None class HG38FixedDataset(torch.utils.data.Dataset): ''' Loop thru bed file, retrieve...
hyena-dna-main
src/dataloaders/datasets/hg38_fixed_dataset.py
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by...
hyena-dna-main
src/dataloaders/utils/vocabulary.py
"""Utilities for special optimizer hyperparameters. group_parameters_for_optimizer is a modification of timm's optimizer logic, which is currently unused add_optimizer_hooks is an improved version that uses this codebase's _optim dictionary """ import inspect import torch.nn as nn import hydra def add_optimizer_h...
hyena-dna-main
src/utils/optim_groups.py
""" Utilities for dealing with collection objects (lists, dicts) and configs """ from typing import Sequence, Mapping, Optional, Callable import functools import hydra from omegaconf import ListConfig, DictConfig # TODO this is usually used in a pattern where it's turned into a list, so can just do that here def is_li...
hyena-dna-main
src/utils/config.py
optimizer = { "adam": "torch.optim.Adam", "adamw": "torch.optim.AdamW", "rmsprop": "torch.optim.RMSprop", "sgd": "torch.optim.SGD", "lamb": "src.utils.optim.lamb.JITLamb", } scheduler = { "constant": "transformers.get_constant_schedule", "plateau": "torch.optim.lr_scheduler.ReduceLROnPlatea...
hyena-dna-main
src/utils/registry.py
from .config import is_list, is_dict, to_list, to_dict, get_class, instantiate
hyena-dna-main
src/utils/__init__.py
import math import numpy as np import torch ### Bit reversal permutation def bitreversal_po2(n): m = int(math.log(n)/math.log(2)) perm = np.arange(n).reshape(n,1) for i in range(m): n1 = perm.shape[0]//2 perm = np.hstack((perm[:n1],perm[n1:])) return perm.squeeze(0) def bitreversal_p...
hyena-dna-main
src/utils/permutations.py
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by...
hyena-dna-main
src/utils/distributed.py
""" Utils for the training loop. Copied from https://github.com/HazyResearch/transformers/blob/master/src/utils/utils.py """ import logging import os import warnings from typing import List, Sequence import torch.nn as nn import pytorch_lightning as pl import rich.syntax import rich.tree from omegaconf import DictConf...
hyena-dna-main
src/utils/train.py
import torch import torch.utils.benchmark as benchmark def _get_gpu_mem(synchronize=True, empty_cache=True): return torch.cuda.memory_allocated() / ( (2**20) * 1000 ), torch.cuda.memory_cached() / ((2**20) * 1000) def _generate_mem_hook(handle_ref, mem, idx, hook_type, exp): def hook(self, *args...
hyena-dna-main
src/utils/profiling.py
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by...
hyena-dna-main
src/utils/optim/lamb.py
"""Custom learning rate schedulers""" import math import warnings import torch from timm.scheduler import CosineLRScheduler # https://pytorch.org/docs/stable/_modules/torch/optim/lr_scheduler.html class CosineWarmup(torch.optim.lr_scheduler.CosineAnnealingLR): def __init__(self, optimizer, T_max, eta_min=0, wa...
hyena-dna-main
src/utils/optim/schedulers.py
""" Implementations of different types of residual functions. """ import torch from torch import nn class Residual(nn.Module): """ Residual connection with constant affine weights. Can simulate standard residual, no residual, and "constant gates". """ def __init__(self, i_layer, d_input, d_model, alpha=1.0, ...
hyena-dna-main
src/models/nn/residual.py
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by...
hyena-dna-main
src/models/nn/adaptive_softmax.py