Upload 8 files
Browse files- config.json +25 -0
- configuration_rwkv5.py +120 -0
- generation_config.json +12 -0
- special_tokens_map.json +1 -0
config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"RwkvForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_rwkv5.Rwkv5Config",
|
| 7 |
+
"AutoModelForCausalLM": "modeling_rwkv5.Rwkv5ForCausalLM"
|
| 8 |
+
},
|
| 9 |
+
"attention_hidden_size": 4096,
|
| 10 |
+
"bos_token_id": 0,
|
| 11 |
+
"context_length": 4096,
|
| 12 |
+
"eos_token_id": 0,
|
| 13 |
+
"head_size": 64,
|
| 14 |
+
"hidden_size": 4096,
|
| 15 |
+
"intermediate_size": null,
|
| 16 |
+
"layer_norm_epsilon": 1e-05,
|
| 17 |
+
"model_type": "rwkv5",
|
| 18 |
+
"model_version": "5_2",
|
| 19 |
+
"num_hidden_layers": 32,
|
| 20 |
+
"rescale_every": 6,
|
| 21 |
+
"tie_word_embeddings": false,
|
| 22 |
+
"transformers_version": "4.34.0",
|
| 23 |
+
"use_cache": true,
|
| 24 |
+
"vocab_size": 65536
|
| 25 |
+
}
|
configuration_rwkv5.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2023 The OpenAI Team Authors and HuggingFace Inc. team.
|
| 3 |
+
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
""" RWKV configuration"""
|
| 17 |
+
|
| 18 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 19 |
+
from transformers.utils import logging
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
RWKV5_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Rwkv5Config(PretrainedConfig):
|
| 28 |
+
"""
|
| 29 |
+
This is the configuration class to store the configuration of a [`Rwkv5Model`]. It is used to instantiate a RWKV5
|
| 30 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 31 |
+
defaults will yield a similar configuration to that of the RWVK-4
|
| 32 |
+
[RWKV/rwkv-5-world-1b5](https://huggingface.co/RWKV/rwkv-5-world-1b5) architecture.
|
| 33 |
+
|
| 34 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 35 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
vocab_size (`int`, *optional*, defaults to 65536):
|
| 40 |
+
Vocabulary size of the RWKV5 model. Defines the number of different tokens that can be represented by the
|
| 41 |
+
`inputs_ids` passed when calling [`Rwkv5Model`].
|
| 42 |
+
hidden_size (`int`, *optional*, defaults to 768):
|
| 43 |
+
Dimensionality of the embeddings and hidden states.
|
| 44 |
+
num_hidden_layers (`int`, *optional*, defaults to 24):
|
| 45 |
+
Number of hidden layers in the model.
|
| 46 |
+
attention_hidden_size (`int`, *optional*):
|
| 47 |
+
Dimensionality of the attention hidden states. Will default to `hidden_size` if unset.
|
| 48 |
+
num_attention_heads (`int`, *optional*, defaults to 64):
|
| 49 |
+
The attention heads to use in rwkv5 self_attention module.
|
| 50 |
+
head_size (`int`, *optional*, defaults to 64): head_size of rwkv5 self_attention module.
|
| 51 |
+
intermediate_size (`int`, *optional*):
|
| 52 |
+
Dimensionality of the inner feed-forward layers. Will default to 4 times `hidden_size` if unset.
|
| 53 |
+
layer_norm_epsilon (`float`, *optional*, defaults to 1e-05):
|
| 54 |
+
The epsilon to use in the layer normalization layers.
|
| 55 |
+
bos_token_id (`int`, *optional*, defaults to 0):
|
| 56 |
+
The id of the beginning of sentence token in the vocabulary. Defaults to 0 as RWKV5 uses the same tokenizer
|
| 57 |
+
as GPTNeoX.
|
| 58 |
+
eos_token_id (`int`, *optional*, defaults to 0):
|
| 59 |
+
The id of the end of sentence token in the vocabulary. Defaults to 0 as RWKV5 uses the same tokenizer as
|
| 60 |
+
GPTNeoX.
|
| 61 |
+
rescale_every (`int`, *optional*, defaults to 6):
|
| 62 |
+
At inference, the hidden states (and weights of the correponding output layers) are divided by 2 every
|
| 63 |
+
`rescale_every` layer. If set to 0 or a negative number, no rescale is done.
|
| 64 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 65 |
+
Whether or not to tie the word embeddings with the input token embeddings.
|
| 66 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 67 |
+
Whether or not the model should return the last state.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Example:
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
>>> from transformers import Rwkv5Config, Rwkv5Model
|
| 74 |
+
|
| 75 |
+
>>> # Initializing a Rwkv5 configuration
|
| 76 |
+
>>> configuration = Rwkv5Config()
|
| 77 |
+
|
| 78 |
+
>>> # Initializing a model (with random weights) from the configuration
|
| 79 |
+
>>> model = Rwkv5Model(configuration)
|
| 80 |
+
|
| 81 |
+
>>> # Accessing the model configuration
|
| 82 |
+
>>> configuration = model.config
|
| 83 |
+
```"""
|
| 84 |
+
|
| 85 |
+
model_type = "rwkv5"
|
| 86 |
+
|
| 87 |
+
def __init__(
|
| 88 |
+
self,
|
| 89 |
+
vocab_size=65536,
|
| 90 |
+
hidden_size=768,
|
| 91 |
+
num_hidden_layers=24,
|
| 92 |
+
attention_hidden_size=None,
|
| 93 |
+
num_attention_heads=64,
|
| 94 |
+
head_size=64,
|
| 95 |
+
intermediate_size=None,
|
| 96 |
+
layer_norm_epsilon=1e-5,
|
| 97 |
+
bos_token_id=0,
|
| 98 |
+
eos_token_id=0,
|
| 99 |
+
rescale_every=6,
|
| 100 |
+
tie_word_embeddings=False,
|
| 101 |
+
use_cache=True,
|
| 102 |
+
**kwargs,
|
| 103 |
+
):
|
| 104 |
+
self.vocab_size = vocab_size
|
| 105 |
+
self.hidden_size = hidden_size
|
| 106 |
+
self.num_hidden_layers = num_hidden_layers
|
| 107 |
+
self.attention_hidden_size = attention_hidden_size if attention_hidden_size is not None else hidden_size
|
| 108 |
+
self.num_attention_heads = num_attention_heads
|
| 109 |
+
self.head_size = head_size
|
| 110 |
+
self.intermediate_size = None
|
| 111 |
+
self.layer_norm_epsilon = layer_norm_epsilon
|
| 112 |
+
self.rescale_every = rescale_every
|
| 113 |
+
self.use_cache = use_cache
|
| 114 |
+
|
| 115 |
+
self.bos_token_id = bos_token_id
|
| 116 |
+
self.eos_token_id = eos_token_id
|
| 117 |
+
|
| 118 |
+
super().__init__(
|
| 119 |
+
tie_word_embeddings=tie_word_embeddings, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs
|
| 120 |
+
)
|
generation_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chat_format": "chatml",
|
| 3 |
+
"eos_token_id": 0,
|
| 4 |
+
"pad_token_id": 0,
|
| 5 |
+
"max_window_size": 4096,
|
| 6 |
+
"max_new_tokens": 4096,
|
| 7 |
+
"do_sample": true,
|
| 8 |
+
"top_k": 0,
|
| 9 |
+
"top_p": 0.1,
|
| 10 |
+
"repetition_penalty": 1.0,
|
| 11 |
+
"transformers_version": "4.31.1"
|
| 12 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|