This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Based upon ColossalAI OpenMoE | |
| """ | |
| from torch import nn | |
| class MOELayer(nn.Module): | |
| def __init__( | |
| self, | |
| d, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from torch import nn | |
| class MoEBlock(nn.Module): | |
| def __init__( | |
| self, | |
| d, | |
| H, | |
| C, | |
| n_exp, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| import torch | |
| from torch import nn | |
| import torch.nn.functional as F | |
| class SelfAttention(nn.Module): | |
| def __init__(self, d): | |
| """ | |
| Arguments: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| import torch | |
| from torch import nn | |
| import torch.nn.functional as F | |
| class CrossAttention(nn.Module): | |
| def __init__(self, d): | |
| """ | |
| Arguments: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import json | |
| from collections import Counter | |
| import tempfile | |
| from transformers import AutoTokenizer | |
| # load tokenizer / data | |
| enc = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", add_bos_token=False, add_eos_token=False) | |
| data_rows = [{'text': 'here is some training data'}, ...] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ast | |
| import math | |
| import random | |
| from infini_gram.engine import InfiniGramEngine | |
| from transformers import AutoTokenizer | |
| def compute_longest_prefix(query, doc): | |
| """helper function for computing longest prefix of query that exists | |
| within a document""" |
OlderNewer