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 |
|---|---|---|---|---|---|---|
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_taiyi_clip/flickr_datasets.py | # 这里这个dataset只是临时测试用的,所以暂时用最简陋的方式放在这里,后续会优化
from torch.utils.data import Dataset
from PIL import Image
class flickr30k_CNA(Dataset):
def __init__(self, img_root_path=None,
text_annot_path=None,
data_process_fn=None):
self.images = []
self.captions = []
sel... | 1,241 | 33.5 | 68 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/summary/seq2seq_summary.py |
import torch
import os
import argparse
import json
import pytorch_lightning as pl
from fengshen.models.model_utils import add_module_args
from fengshen.data.task_dataloader.task_datasets import AbstractCollator
from fengshen.data.universal_datamodule import UniversalDataModule
from fengshen.utils.universal_checkpoint ... | 9,184 | 45.388889 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/mt5_summary/mt5_summary.py | from fengshen.data.task_dataloader.task_datasets import LCSTSDataModel
from transformers import T5Tokenizer, MT5ForConditionalGeneration
from transformers.optimization import get_linear_schedule_with_warmup
from pytorch_lightning import Trainer, loggers
from pytorch_lightning.callbacks import ModelCheckpoint
from trans... | 9,924 | 41.41453 | 112 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/mt5_summary/fastapi_mt5_summary.py | import os
import sys
import uvicorn
import torch
from fastapi import Body, FastAPI
from transformers import T5Tokenizer, MT5ForConditionalGeneration
import pytorch_lightning as pl
sys.path.append(os.path.abspath(os.path.join(
os.path.dirname(__file__), os.path.pardir)))
os.environ["CUDA_VISIBLE_DEVICES"] = '5'
os.e... | 3,393 | 35.106383 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_taiyi_stable_diffusion/finetune.py | import os
import torch
import argparse
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import (
LearningRateMonitor,
)
from fengshen.data.universal_datamodule import UniversalDataModule
from fengshen.models.model_utils import (
add_module_args,
configure_... | 7,853 | 39.484536 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/finetune_taiyi_stable_diffusion/evaluate_model.py | import pytorch_lightning as pl
import torch.nn as nn
import torch.nn.functional as F
import torch
import timm
from torchvision import transforms as T
import open_clip
import sys
import torch
import json
from transformers import BertModel, BertTokenizer
from PIL import Image
from diffusers import StableDiffusionPipeline... | 11,944 | 39.491525 | 187 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pegasus/pretrain_pegasus.py | # -*- coding: utf-8 -*-
from fengshen.models.model_utils import add_module_args
from transformers import PegasusForConditionalGeneration, PegasusConfig
from pytorch_lightning import Trainer, loggers, LightningModule
from pytorch_lightning.callbacks import LearningRateMonitor
from tokenizers_pegasus import PegasusToke... | 7,247 | 38.824176 | 92 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pegasus/data_utils.py | # -*- coding: utf-8 -*-
import re
import six
import unicodedata
import torch
import rouge
import numpy as np
import random
# from fengshen.examples.pegasus.pegasus_utils import text_segmentate
import sys
sys.path.append('../../../')
rouge = rouge.Rouge()
is_py2 = six.PY2
if not is_py2:
basestring = str
def ... | 9,799 | 29.625 | 80 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clip_finetune/clip_finetune_flickr.py | import sys
sys.path.append('../../')
from data.clip_dataloader.flickr import FlickrDataModule
import pytorch_lightning as pl
import numpy as np
import torch
from torch.optim.lr_scheduler import CosineAnnealingWarmRestarts
import torch.nn.functional as F
import math
import copy
import argparse
from transformers import C... | 11,460 | 43.080769 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/llama_generate.py |
import torch
from transformers import LlamaForCausalLM, AutoTokenizer
from typing import List
import torch.nn.functional as F
def zero_pad_sequences(sequences: List[torch.Tensor], side: str = 'left', padding_value: int = 0) -> torch.Tensor:
assert side in ('left', 'right')
max_len = max(seq.size(0) for seq in... | 2,398 | 35.348485 | 118 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/finetune_ziya_llama.py | from asyncio.log import logger
from cgitb import lookup
from dataclasses import dataclass
import os
import deepspeed
import torch
import pytorch_lightning as pl
from pytorch_lightning.callbacks import LearningRateMonitor
from pytorch_lightning.loggers import WandbLogger
import argparse
from fengshen.models.model_utils ... | 9,179 | 38.74026 | 135 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/ziya_llama/sample_test.py | from transformers import LlamaTokenizer
import torch
def pad(ids, pad_id, max_length):
if len(ids) > max_length:
return ids[:max_length]
return ids + [pad_id] * (max_length - len(ids))
prompt_without_output = "<human>:{prompt}\n<bot>:"
def generate_samples(s, tokenizer, max_seq_length):
max_leng... | 2,660 | 39.938462 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/sequence_tagging/finetune_sequence_tagging.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 12,218 | 37.545741 | 159 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/translate/finetune_deltalm.py | # !/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import json
import argparse
import torch
import os
import logging
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from pytorch_lightning.utilities import rank_zero_info
from sacrebleu.metrics import BLEU
from fengshen.utils.utils import ch... | 18,263 | 39.586667 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_randeng_bart/pretrain_bart.py | from transformers import AutoTokenizer, BartForConditionalGeneration, BartConfig
from pytorch_lightning import (
LightningModule,
Trainer,
)
from pytorch_lightning.callbacks import LearningRateMonitor
from dataclasses import dataclass
import os
import argparse
import torch
import math
import time
from torch.uti... | 11,778 | 40.769504 | 107 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/GAVAE/generate.py | import torch
from transformers import BertTokenizer,T5Tokenizer
from fengshen.models.GAVAE.GAVAEModel import GAVAEModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
encoder_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-GAVAE-1.2B-Augmentation-Chinese")
decoder_tokenizer = T5Toke... | 1,783 | 73.333333 | 188 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/main.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 5,531 | 40.283582 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/finetune_clue_sim.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 13,899 | 41.638037 | 114 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/clue_sim/loss.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 2,693 | 33.538462 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/deepVAE/vae_pl_module.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. 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
#
... | 14,840 | 52.193548 | 175 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/deepVAE/pretrain_deep_vae.py | import torch
import os
import random
import math
import argparse
from fengshen.data.fs_datasets.fs_datamodule import FSDataModule
from fengshen.example.deepVAE.vae_pl_module import DeepVAEModule
from pytorch_lightning import (
Trainer,
loggers,
)
from pytorch_lightning.callbacks import ModelCheckpoint, Learni... | 6,369 | 43.859155 | 126 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/PPVAE/generate.py | import torch
from transformers import BertTokenizer,T5Tokenizer
from fengshen.models.PPVAE.pluginVAE import PPVAEModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
encoder_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-PPVAE-1.2B-Augmentation-Chinese")
decoder_tokenizer = T5Token... | 1,807 | 74.333333 | 188 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/examples/pretrain_bert/pretrain_bert.py | from data.bert_dataloader.load import BertDataModule
from transformers import (
BertTokenizer,
BertConfig,
BertForPreTraining,
BertModel,
BertForMaskedLM
)
from pytorch_lightning import (
LightningDataModule,
LightningModule,
loggers,
Trainer,
)
from pytorch_lightning.callbacks impor... | 10,636 | 37.125448 | 100 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/metric/utils_ner.py | import csv
import json
import torch
from transformers import BertTokenizer
class CNerTokenizer(BertTokenizer):
def __init__(self, vocab_file, do_lower_case=True):
super().__init__(vocab_file=str(vocab_file), do_lower_case=do_lower_case)
self.vocab_file = str(vocab_file)
self.do_lower_case ... | 8,822 | 32.675573 | 110 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/metric/metric.py | # coding=utf-8
from collections import Counter
import torch
from torch import nn
# import seqeval
from .utils_ner import get_entities
class metrics_mlm_acc(nn.Module):
def __init__(self):
super().__init__()
def forward(self, logits, labels, masked_lm_metric):
# if len(list(logits.shape))==3... | 4,970 | 37.238462 | 111 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/model_utils.py | from pytorch_lightning import LightningModule
from pytorch_lightning.strategies import DeepSpeedStrategy
from deepspeed.ops.adam import DeepSpeedCPUAdam, FusedAdam
from transformers.optimization import AdamW, TYPE_TO_SCHEDULER_FUNCTION
from torch.optim import Optimizer
from torch.optim.lr_scheduler import _LRScheduler
... | 11,270 | 43.2 | 157 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/bart/modeling_bart.py | import warnings
from pytorch_lightning import LightningModule
from fengshen.models import transformer_utils
import torch
import torch.utils.checkpoint
from torch import nn
import torch.nn.functional as F
from dataclasses import dataclass
from typing import Optional, Tuple
from transformers.file_utils import *
from t... | 17,777 | 40.929245 | 149 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/run_latent_generation.py | import re
import torch
import torch.nn.functional as F
from torch.nn.utils.rnn import pad_sequence
import numpy as np
import json
import jsonlines
from tqdm import tqdm, trange
def set_seed(args):
np.random.seed(args.seed)
torch.manual_seed(args.seed)
if args.n_gpu > 0:
torch.cuda.manual_seed_all(a... | 13,632 | 43.993399 | 212 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/BertForLatentConnector.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 7,251 | 51.550725 | 134 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/DAVAEModel.py | import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import BertConfig,TransfoXLConfig
from transformers.configuration_utils import PretrainedConfig
from transformers.modeling_utils import PreTrainedModel
from transformers.utils import cached_path,hf_bucket_url
from fengshen.mo... | 10,280 | 42.563559 | 186 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/DAVAE/GPT2ModelForLatent.py | # coding=utf-8
# Copyright (c) 2019, 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 re... | 27,514 | 41.925117 | 139 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/processing_taiyi_clip.py | # coding=utf-8
# Copyright 2022 The OFA-Sys Team Authors and The HuggingFace Team. 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/... | 5,784 | 48.87069 | 136 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/clip/modeling_taiyi_clip.py | import torch
from torch import nn
from transformers import BertTokenizer
from transformers.models.clip.modeling_clip import (
add_start_docstrings,
add_start_docstrings_to_model_forward,
CLIP_START_DOCSTRING,
CLIP_TEXT_INPUTS_DOCSTRING,
CLIP_VISION_INPUTS_DOCSTRING,
CLIP_INPUTS_DOCSTRING,
re... | 11,583 | 39.362369 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/modeling_longformer.py | # coding=utf-8
# Copyright 2020 The Allen Institute for AI team and The HuggingFace Inc. team.
#
# 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... | 118,901 | 46.82864 | 222 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/longformer/__init__.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 1,823 | 31.571429 | 91 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/bert_for_tagging.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from .layers.crf import CRF
from .layers.bert_output import BiaffineClassifierOutput, TokenClassifierOutput, SpanClassifierOutput
from transformers import BertPreTrainedModel
from transformers import BertModel
from .layers.linears import PoolerEndLogit... | 9,885 | 47.460784 | 147 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/linears.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class FeedForwardNetwork(nn.Module):
def __init__(self, input_size, hidden_size, output_size, dropout_rate=0):
super(FeedForwardNetwork, self).__init__()
self.dropout_rate = dropout_rate
self.linear1 = nn.Linear(input_size, ... | 2,701 | 39.328358 | 102 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/bert_output.py | import torch
from dataclasses import dataclass
from typing import Optional
@dataclass
class TokenClassifierOutput:
"""
Base class for outputs of token classification models.
"""
loss: Optional[torch.FloatTensor] = None
logits: torch.FloatTensor = None
@dataclass
class SpanClassifierOutput:
""... | 721 | 22.290323 | 58 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/layers/crf.py | import torch
import torch.nn as nn
from typing import List, Optional
class CRF(nn.Module):
"""Conditional random field.
This module implements a conditional random field [LMP01]_. The forward computation
of this class computes the log likelihood of the given sequence of tags and
emission score tensor. ... | 19,972 | 47.596107 | 99 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/losses/label_smoothing.py | import torch.nn as nn
import torch.nn.functional as F
class LabelSmoothingCrossEntropy(nn.Module):
def __init__(self, eps=0.1, reduction='mean',ignore_index=-100):
super(LabelSmoothingCrossEntropy, self).__init__()
self.eps = eps
self.reduction = reduction
self.ignore_index = ignore... | 841 | 39.095238 | 103 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tagging_models/losses/focal_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class FocalLoss(nn.Module):
'''Multi-class Focal loss implementation'''
def __init__(self, gamma=2, weight=None,ignore_index=-100):
super(FocalLoss, self).__init__()
self.gamma = gamma
self.weight = weight
self.i... | 707 | 28.5 | 84 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/transfo_xl_denoise/generate.py | import torch
import torch.nn.functional as F
from fengshen.models.transfo_xl_denoise.tokenization_transfo_xl_denoise import TransfoXLDenoiseTokenizer
from fengshen.models.transfo_xl_denoise.modeling_transfo_xl_denoise import TransfoXLDenoiseModel
from fengshen.utils import top_k_logits, get_masks_and_position_ids
def... | 2,934 | 42.80597 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/transfo_xl_denoise/modeling_transfo_xl_denoise.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. 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
#
... | 33,182 | 42.094805 | 120 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/zen1/tokenization.py | # coding=utf-8
# This file is derived from the code at
# https://github.com/huggingface/transformers/blob/master/transformers/tokenization_bert.py
#
# Original copyright notice:
#
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the ... | 18,927 | 42.116173 | 179 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/zen1/modeling.py | # coding: utf-8
# Copyright 2019 Sinovation Ventures AI Institute
#
# 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 app... | 54,948 | 49.597606 | 171 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/tcbert/modeling_tcbert.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 13,919 | 36.929155 | 130 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/albert/modeling_albert.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and the HuggingFace Inc. team.
#
# 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
#
# U... | 56,887 | 40.706745 | 168 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/transfo_xl_paraphrase/generate.py | import torch
import torch.nn.functional as F
from fengshen.models.transfo_xl_paraphrase import TransfoXLModel
from fengshen.utils import top_k_logits, get_masks_and_position_ids
from transformers import T5Tokenizer
def get_batch(context_tokens, mem_length, batch_size=1):
tokens = context_tokens
tokens = token... | 3,069 | 42.857143 | 117 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/auto/__init__.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 2,003 | 34.157895 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/auto/auto_factory.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 35,460 | 53.978295 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron_t5/configuration_megatron_t5.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 10,955 | 41.796875 | 119 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron_t5/__init__.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 1,425 | 27.52 | 74 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron_t5/modeling_megatron_t5.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 90,226 | 42.23287 | 143 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/roformer/__init__.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 1,785 | 29.793103 | 74 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/roformer/modeling_roformer.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 82,128 | 41.009719 | 213 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/flash_attention.py | # Based on: https://github.com/HazyResearch/flash-attention/blob/4a6eaa9f27df6fff7ffb2c24e894938a687dd870/flash_attn/flash_attn_interface.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import flash_attn_cuda
def _flash_attn_forward(
q,
k,
v,
out,
cu_seqlens_q,
cu_seqle... | 4,804 | 24.833333 | 140 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/positional_embeddings.py | # Copyright (c) 2021, EleutherAI
#
# 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 applicable law or agreed to in writi... | 7,894 | 44.373563 | 142 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/fused_bias_dropout.py | # Copyright (c) 2021, EleutherAI contributors
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# 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 L... | 1,871 | 32.428571 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/utils.py | # Copyright (c) 2021 EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complianc... | 11,316 | 37.104377 | 139 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/norms.py | # Copyright (c) 2021, EleutherAI
#
# 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 applicable law or agreed to in writi... | 2,075 | 31.4375 | 85 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/init_functions.py | # Copyright (c) 2021, EleutherAI
#
# 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 applicable law or agreed to in writi... | 4,653 | 31.545455 | 118 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/transformer.py | # Copyright (c) 2021 EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complianc... | 29,401 | 35.031863 | 159 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/gmlp.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# 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
#
#... | 4,997 | 34.197183 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/fused_softmax.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 6,992 | 32.946602 | 138 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/activations.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 4,034 | 29.338346 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/layers/word_embeddings.py | # Copyright (c) 2021, EleutherAI
#
# 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 applicable law or agreed to in writi... | 8,382 | 37.810185 | 145 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/mappings.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 5,182 | 25.854922 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/initialize.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 10,377 | 33.478405 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/cross_entropy.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 4,799 | 39.677966 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/utils.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 3,041 | 34.788235 | 106 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/data.py | # Copyright (c) 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 appli... | 3,886 | 31.123967 | 85 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/mpu/layers.py | # Copyright (c) 2021, EleutherAI
# This file is based on code by the authors denoted below and has been modified from its original version.
#
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in complian... | 17,089 | 35.284501 | 154 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/fused_kernels/setup.py | from setuptools import setup, find_packages
from torch.utils import cpp_extension
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
from pathlib import Path
import subprocess
def _get_cuda_bare_metal_version(cuda_dir):
raw_output = subprocess.check_output(
[cuda_dir + "/bin/nvcc", "-V"],... | 2,105 | 29.521739 | 78 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/fused_kernels/__init__.py | # Copyright (c) 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 appli... | 1,534 | 33.111111 | 137 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/megatron/fused_kernels/tests/test_fused_kernels.py | import math
import torch
from torch.nn import LayerNorm
from megatron.model.fused_softmax import FusedScaleMaskSoftmax
from megatron.model.gpt2_model import gpt2_attention_mask_func
def test_load_fused_kernels():
try:
import scaled_masked_softmax_cuda
import scaled_upper_triang_masked_softmax_cu... | 9,169 | 29.875421 | 87 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/ubert/modeling_ubert.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 30,911 | 39.673684 | 160 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/uniex/modeling_uniex.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 96,133 | 46.995007 | 191 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/GAVAE/gans_model.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import Dataset, DataLoader
import numpy as np
class MyDataset(Dataset):
def __init__(self, x, y):
self.x = x
self.y = y
self.len = self.x.size(0)
def __getitem__(self, index):
return self... | 14,922 | 29.769072 | 115 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/GAVAE/GAVAEModel.py | # -*- encoding: utf-8 -*-
'''
Copyright 2022 The International Digital Economy Academy (IDEA). CCNL team. 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.o... | 2,706 | 38.808824 | 96 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/zen2/tokenization.py | # coding=utf-8
# This file is derived from the code at
# https://github.com/huggingface/transformers/blob/master/transformers/tokenization_bert.py
#
# Original copyright notice:
#
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the ... | 19,799 | 41.950108 | 179 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/zen2/modeling.py | # coding: utf-8
# Copyright 2019 Sinovation Ventures AI Institute
#
# 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 app... | 72,687 | 51.444444 | 187 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/zen2/ngram_utils.py | # coding: utf-8
# Copyright 2019 Sinovation Ventures AI Institute
#
# 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 app... | 8,874 | 44.984456 | 142 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/llama/modeling_llama.py | # coding=utf-8
# Copyright 2022 EleutherAI The HuggingFace Inc. team. 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
#... | 17,756 | 42.736453 | 198 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/deepVAE/latent_connector.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. 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
#
... | 18,993 | 45.214112 | 144 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/deepVAE/utils.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. 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
#
... | 5,630 | 40.711111 | 116 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/deepVAE/deep_vae.py | # coding=utf-8
# Copyright 2022 IDEA-CCNL The HuggingFace Inc. team. 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
#
... | 14,648 | 55.559846 | 182 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/deberta_v2/modeling_deberta_v2.py | # coding=utf-8
# Copyright 2020 Microsoft and the Hugging Face Inc. team.
#
# 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 require... | 66,327 | 39.99382 | 127 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/unimc/modeling_unimc.py | # coding=utf-8
# Copyright 2021 The IDEA Authors. 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 a... | 27,338 | 40.360061 | 158 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/PPVAE/utils.py | from torch.utils.data import Dataset
class CustomDataset(Dataset):
def __init__(self, data) -> None:
super().__init__()
self.data = data
def __len__(self):
return len(self.data)
def __getitem__(self, index):
# Get data
d = self.data[index]
return d
class E... | 1,264 | 32.289474 | 94 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/PPVAE/pluginVAE.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from transformers.modeling_utils import PreTrainedModel
from transformers.configuration_utils import PretrainedConfig
from fengshen.models.DAVAE.DAVAEModel import DAVAEModel
from fengshen.models.PPVAE.utils impor... | 6,649 | 35.740331 | 120 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/deltalm/modeling_deltalm.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import copy
import math
import random
import torch
import torch.nn as nn
import torch.utils.checkpoint
from torch.nn import CrossEntropyLoss
from typing import List, Optional, Tuple, Union
from transformers.modeling_utils import PreTrainedModel
from transformers.activati... | 77,342 | 48.834407 | 150 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/models/transfo_xl_reasoning/generate.py | # encoding=utf-8
from typing import List, Union
import torch
from torch.nn.utils.rnn import pad_sequence
from transformers import T5Tokenizer
from fengshen.models.transfo_xl_reasoning import TransfoXLModel
from fengshen.utils import sample_sequence_batch
def en_to_zh(sentence:str):
en_pun = u",.!?[]()<>\"\"''"
... | 3,642 | 29.107438 | 90 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/transfo_xl_utils.py | # encoding=utf-8
import torch, math
import torch.nn.functional as F
def top_k_logits(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
# This function has been mostly taken from huggingface conversational ai code at
# https://medium.com/huggingface/how-to-build-a-state-of-the-art-conversational-ai-with... | 11,388 | 44.374502 | 147 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/convert_diffusers_to_original_stable_diffusion.py | # coding=utf8
# Script for converting a HF Diffusers saved pipeline to a Stable Diffusion checkpoint.
# *Only* converts the UNet, VAE, and Text Encoder.
# Does not convert optimizer state or any other thing.
import argparse
import os.path as osp
import torch
# =================#
# UNet Conversion #
# ==============... | 8,919 | 36.79661 | 115 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/convert_py_to_npy.py | import argparse
import torch
import glob
import os
import numpy as np
class MMapIndexDataset():
def __init__(self, datapath):
self.idxfp = np.load(datapath + '.npy', mmap_mode='r')
self.binfp = np.memmap(datapath + '.bin', dtype='long', mode='r')
def __len__(self):
return self.idxfp.s... | 1,823 | 32.163636 | 100 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/utils.py | # coding=utf-8
import jieba
import torch
def jieba_tokenize(str):
return jieba.lcut(str)
_UCODE_RANGES = (
("\u3400", "\u4db5"), # CJK Unified Ideographs Extension A, release 3.0
("\u4e00", "\u9fa5"), # CJK Unified Ideographs, release 1.1
("\u9fa6", "\u9fbb"), # CJK Unified Ideographs, release 4.... | 2,431 | 31.426667 | 86 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/make_delta.py | """
Code is modified from https://github.com/lm-sys/FastChat/blob/main/fastchat/model/make_delta.py.
Make the delta weights by subtracting base weights.
Usage:
python3 -m make_delta --base ~/model_weights/llama-13b --target ~/model_weights/ziya-13b --delta ~/model_weights/ziya-13b-delta
"""
import argparse
import to... | 2,132 | 35.775862 | 127 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/universal_checkpoint.py | from pytorch_lightning.callbacks import ModelCheckpoint
import os
class UniversalCheckpoint(ModelCheckpoint):
@staticmethod
def add_argparse_args(parent_args):
parser = parent_args.add_argument_group('universal checkpoint callback')
parser.add_argument('--monitor', default='step', type=str)
... | 2,013 | 46.952381 | 91 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/convert_tf_checkpoint_to_pytorch.py | """Convert ALBERT checkpoint."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import torch
from transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert
# from models.transformers.modeling_albert_bright import AlbertCon... | 2,736 | 42.444444 | 118 | py |
Fengshenbang-LM | Fengshenbang-LM-main/fengshen/utils/apply_delta.py | """
Code is modified from https://github.com/lm-sys/FastChat/blob/main/fastchat/model/apply_delta.py
Apply the delta weights on top of a base model.
Usage:
python3 -m fastchat.model.apply_delta --base ~/model_weights/llama-7b --target ~/model_weights/vicuna-7b --delta lmsys/vicuna-7b-delta-v1.1
"""
import argparse
im... | 6,611 | 36.782857 | 139 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.