Upload folder using huggingface_hub
Browse files- .config.json.swp +0 -0
- .gitattributes +1 -0
- README.md +61 -0
- added_tokens.json +26 -0
- all_results.json +8 -0
- chat_template.jinja +7 -0
- config.json +50 -0
- configuration_qwen2.py +362 -0
- generation_config.json +14 -0
- merges.txt +0 -0
- modeling_qwen2.py +2063 -0
- processing_qwen2_ts.py +224 -0
- processor_config.json +6 -0
- pytorch_model-00001-of-00007.bin +3 -0
- pytorch_model-00002-of-00007.bin +3 -0
- pytorch_model-00003-of-00007.bin +3 -0
- pytorch_model-00004-of-00007.bin +3 -0
- pytorch_model-00005-of-00007.bin +3 -0
- pytorch_model-00006-of-00007.bin +3 -0
- pytorch_model-00007-of-00007.bin +3 -0
- pytorch_model.bin.index.json +607 -0
- special_tokens_map.json +20 -0
- tokenizer.json +3 -0
- tokenizer_config.json +214 -0
- train_results.json +8 -0
- train_timesense.sh +76 -0
- trainer_log.jsonl +0 -0
- trainer_state.json +0 -0
- training_args.bin +3 -0
- training_loss.png +0 -0
- vocab.json +0 -0
.config.json.swp
ADDED
|
Binary file (12.3 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: other
|
| 4 |
+
base_model: Wannabtl/modeltest
|
| 5 |
+
tags:
|
| 6 |
+
- llama-factory
|
| 7 |
+
- full
|
| 8 |
+
- generated_from_trainer
|
| 9 |
+
model-index:
|
| 10 |
+
- name: ChatTS-14B-timesense
|
| 11 |
+
results: []
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 15 |
+
should probably proofread and complete it, then remove this comment. -->
|
| 16 |
+
|
| 17 |
+
# ChatTS-14B-timesense
|
| 18 |
+
|
| 19 |
+
This model is a fine-tuned version of [/xll/models/ChatTS-14B](https://huggingface.co//xll/models/ChatTS-14B) on the generated_timeseries_bench_qa_new2, the generated_timeseries_bench_plus2, the tulu_ift, the model_detect_0823, the model_qa, the new_chatts_sft and the new_chatts_ift datasets.
|
| 20 |
+
|
| 21 |
+
## Model description
|
| 22 |
+
|
| 23 |
+
More information needed
|
| 24 |
+
|
| 25 |
+
## Intended uses & limitations
|
| 26 |
+
|
| 27 |
+
More information needed
|
| 28 |
+
|
| 29 |
+
## Training and evaluation data
|
| 30 |
+
|
| 31 |
+
More information needed
|
| 32 |
+
|
| 33 |
+
## Training procedure
|
| 34 |
+
|
| 35 |
+
### Training hyperparameters
|
| 36 |
+
|
| 37 |
+
The following hyperparameters were used during training:
|
| 38 |
+
- learning_rate: 1e-05
|
| 39 |
+
- train_batch_size: 1
|
| 40 |
+
- eval_batch_size: 8
|
| 41 |
+
- seed: 42
|
| 42 |
+
- distributed_type: multi-GPU
|
| 43 |
+
- num_devices: 8
|
| 44 |
+
- gradient_accumulation_steps: 32
|
| 45 |
+
- total_train_batch_size: 256
|
| 46 |
+
- total_eval_batch_size: 64
|
| 47 |
+
- optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 48 |
+
- lr_scheduler_type: cosine
|
| 49 |
+
- lr_scheduler_warmup_ratio: 0.02
|
| 50 |
+
- training_steps: 900
|
| 51 |
+
|
| 52 |
+
### Training results
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
### Framework versions
|
| 57 |
+
|
| 58 |
+
- Transformers 4.52.4
|
| 59 |
+
- Pytorch 2.6.0+cu124
|
| 60 |
+
- Datasets 3.4.1
|
| 61 |
+
- Tokenizers 0.21.4
|
added_tokens.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</tool_call>": 151658,
|
| 3 |
+
"<tool_call>": 151657,
|
| 4 |
+
"<ts/>": 151666,
|
| 5 |
+
"<ts>": 151665,
|
| 6 |
+
"<|box_end|>": 151649,
|
| 7 |
+
"<|box_start|>": 151648,
|
| 8 |
+
"<|endoftext|>": 151643,
|
| 9 |
+
"<|file_sep|>": 151664,
|
| 10 |
+
"<|fim_middle|>": 151660,
|
| 11 |
+
"<|fim_pad|>": 151662,
|
| 12 |
+
"<|fim_prefix|>": 151659,
|
| 13 |
+
"<|fim_suffix|>": 151661,
|
| 14 |
+
"<|im_end|>": 151645,
|
| 15 |
+
"<|im_start|>": 151644,
|
| 16 |
+
"<|image_pad|>": 151655,
|
| 17 |
+
"<|object_ref_end|>": 151647,
|
| 18 |
+
"<|object_ref_start|>": 151646,
|
| 19 |
+
"<|quad_end|>": 151651,
|
| 20 |
+
"<|quad_start|>": 151650,
|
| 21 |
+
"<|repo_name|>": 151663,
|
| 22 |
+
"<|video_pad|>": 151656,
|
| 23 |
+
"<|vision_end|>": 151653,
|
| 24 |
+
"<|vision_pad|>": 151654,
|
| 25 |
+
"<|vision_start|>": 151652
|
| 26 |
+
}
|
all_results.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.3520179920307038,
|
| 3 |
+
"total_flos": 9.027346976391299e+18,
|
| 4 |
+
"train_loss": 213.8077490248945,
|
| 5 |
+
"train_runtime": 76099.1347,
|
| 6 |
+
"train_samples_per_second": 3.028,
|
| 7 |
+
"train_steps_per_second": 0.012
|
| 8 |
+
}
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% set system_message = 'You are a helpful assistant.' %}{% if messages[0]['role'] == 'system' %}{% set system_message = messages[0]['content'] %}{% endif %}{% if system_message is defined %}{{ '<|im_start|>system
|
| 2 |
+
' + system_message + '<|im_end|>
|
| 3 |
+
' }}{% endif %}{% for message in messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|im_start|>user
|
| 4 |
+
' + content + '<|im_end|>
|
| 5 |
+
<|im_start|>assistant
|
| 6 |
+
' }}{% elif message['role'] == 'assistant' %}{{ content + '<|im_end|>' + '
|
| 7 |
+
' }}{% endif %}{% endfor %}
|
config.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen2TSForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_qwen2.Qwen2TSConfig",
|
| 8 |
+
"AutoModel": "modeling_qwen2.Qwen2TSForCausalLM",
|
| 9 |
+
"AutoModelForCausalLM": "modeling_qwen2.Qwen2TSForCausalLM",
|
| 10 |
+
"AutoProcessor": "processing_qwen2_ts.Qwen2TSProcessor"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 151643,
|
| 13 |
+
"eos_token_id": 151645,
|
| 14 |
+
"hidden_act": "silu",
|
| 15 |
+
"hidden_size": 5120,
|
| 16 |
+
"ignore_index": -100,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 13824,
|
| 19 |
+
"max_position_embeddings": 32768,
|
| 20 |
+
"max_window_layers": 70,
|
| 21 |
+
"model_type": "qwen2",
|
| 22 |
+
"num_attention_heads": 40,
|
| 23 |
+
"num_hidden_layers": 48,
|
| 24 |
+
"num_key_value_heads": 8,
|
| 25 |
+
"pad_token_id": 151643,
|
| 26 |
+
"rms_norm_eps": 1e-06,
|
| 27 |
+
"rope_theta": 1000000.0,
|
| 28 |
+
"sliding_window": 131072,
|
| 29 |
+
"tie_word_embeddings": false,
|
| 30 |
+
"torch_dtype": "bfloat16",
|
| 31 |
+
"transformers_version": "4.52.4",
|
| 32 |
+
"ts": {
|
| 33 |
+
"embedding_dim": 16,
|
| 34 |
+
"hidden_size": 5120,
|
| 35 |
+
"max_length": 32768,
|
| 36 |
+
"max_sequence_length": 32768,
|
| 37 |
+
"num_features": 2,
|
| 38 |
+
"num_layers": 5,
|
| 39 |
+
"patch_size": 8,
|
| 40 |
+
"ts_loss_weight": 1.0,
|
| 41 |
+
"use_position_embedding": true,
|
| 42 |
+
"use_position_idx": false
|
| 43 |
+
},
|
| 44 |
+
"ts_loss_weight": 1.0,
|
| 45 |
+
"ts_token_end_index": 151666,
|
| 46 |
+
"ts_token_start_index": 151665,
|
| 47 |
+
"use_cache": false,
|
| 48 |
+
"use_sliding_window": false,
|
| 49 |
+
"vocab_size": 152064
|
| 50 |
+
}
|
configuration_qwen2.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
""" Qwen2 model configuration"""
|
| 16 |
+
|
| 17 |
+
from transformers import PretrainedConfig
|
| 18 |
+
from transformers.utils import logging
|
| 19 |
+
from typing import *
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class Qwen2TSConfig(PretrainedConfig):
|
| 26 |
+
r"""
|
| 27 |
+
This is the configuration class to store the configuration of a [`Qwen2Model`]. It is used to instantiate a
|
| 28 |
+
Qwen2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 29 |
+
with the defaults will yield a similar configuration to that of
|
| 30 |
+
Qwen2-7B-beta [Qwen/Qwen2-7B-beta](https://huggingface.co/Qwen/Qwen2-7B-beta).
|
| 31 |
+
|
| 32 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 33 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
vocab_size (`int`, *optional*, defaults to 151936):
|
| 38 |
+
Vocabulary size of the Qwen2 model. Defines the number of different tokens that can be represented by the
|
| 39 |
+
`inputs_ids` passed when calling [`Qwen2Model`]
|
| 40 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 41 |
+
Dimension of the hidden representations.
|
| 42 |
+
intermediate_size (`int`, *optional*, defaults to 22016):
|
| 43 |
+
Dimension of the MLP representations.
|
| 44 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 45 |
+
Number of hidden layers in the Transformer encoder.
|
| 46 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 47 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 48 |
+
num_key_value_heads (`int`, *optional*, defaults to 32):
|
| 49 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 50 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 51 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 52 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 53 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 54 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
|
| 55 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 56 |
+
The non-linear activation function (function or string) in the decoder.
|
| 57 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 58 |
+
The maximum sequence length that this model might ever be used with.
|
| 59 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 60 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 61 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 62 |
+
The epsilon used by the rms normalization layers.
|
| 63 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 64 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 65 |
+
relevant if `config.is_decoder=True`.
|
| 66 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 67 |
+
Whether the model's input and output word embeddings should be tied.
|
| 68 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 69 |
+
The base period of the RoPE embeddings.
|
| 70 |
+
use_sliding_window (`bool`, *optional*, defaults to `False`):
|
| 71 |
+
Whether to use sliding window attention.
|
| 72 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
| 73 |
+
Sliding window attention (SWA) window size. If not specified, will default to `4096`.
|
| 74 |
+
max_window_layers (`int`, *optional*, defaults to 28):
|
| 75 |
+
The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
|
| 76 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 77 |
+
The dropout ratio for the attention probabilities.
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
>>> from transformers import Qwen2Model, Qwen2Config
|
| 81 |
+
|
| 82 |
+
>>> # Initializing a Qwen2 style configuration
|
| 83 |
+
>>> configuration = Qwen2Config()
|
| 84 |
+
|
| 85 |
+
>>> # Initializing a model from the Qwen2-7B style configuration
|
| 86 |
+
>>> model = Qwen2Model(configuration)
|
| 87 |
+
|
| 88 |
+
>>> # Accessing the model configuration
|
| 89 |
+
>>> configuration = model.config
|
| 90 |
+
```"""
|
| 91 |
+
|
| 92 |
+
model_type = "qwen2"
|
| 93 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 94 |
+
|
| 95 |
+
def __init__(
|
| 96 |
+
self,
|
| 97 |
+
vocab_size=151936,
|
| 98 |
+
hidden_size=4096,
|
| 99 |
+
intermediate_size=22016,
|
| 100 |
+
num_hidden_layers=32,
|
| 101 |
+
num_attention_heads=32,
|
| 102 |
+
num_key_value_heads=32,
|
| 103 |
+
hidden_act="silu",
|
| 104 |
+
max_position_embeddings=32768,
|
| 105 |
+
initializer_range=0.02,
|
| 106 |
+
rms_norm_eps=1e-6,
|
| 107 |
+
use_cache=True,
|
| 108 |
+
tie_word_embeddings=False,
|
| 109 |
+
rope_theta=10000.0,
|
| 110 |
+
use_sliding_window=False,
|
| 111 |
+
sliding_window=4096,
|
| 112 |
+
max_window_layers=28,
|
| 113 |
+
attention_dropout=0.0,
|
| 114 |
+
**kwargs,
|
| 115 |
+
):
|
| 116 |
+
self.vocab_size = vocab_size
|
| 117 |
+
self.max_position_embeddings = max_position_embeddings
|
| 118 |
+
self.hidden_size = hidden_size
|
| 119 |
+
self.intermediate_size = intermediate_size
|
| 120 |
+
self.num_hidden_layers = num_hidden_layers
|
| 121 |
+
self.num_attention_heads = num_attention_heads
|
| 122 |
+
self.use_sliding_window = use_sliding_window
|
| 123 |
+
self.sliding_window = sliding_window
|
| 124 |
+
self.max_window_layers = max_window_layers
|
| 125 |
+
|
| 126 |
+
# for backward compatibility
|
| 127 |
+
if num_key_value_heads is None:
|
| 128 |
+
num_key_value_heads = num_attention_heads
|
| 129 |
+
|
| 130 |
+
self.num_key_value_heads = num_key_value_heads
|
| 131 |
+
self.hidden_act = hidden_act
|
| 132 |
+
self.initializer_range = initializer_range
|
| 133 |
+
self.rms_norm_eps = rms_norm_eps
|
| 134 |
+
self.use_cache = use_cache
|
| 135 |
+
self.rope_theta = rope_theta
|
| 136 |
+
self.attention_dropout = attention_dropout
|
| 137 |
+
|
| 138 |
+
super().__init__(
|
| 139 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 140 |
+
**kwargs,
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
TINYTIMEMIXER_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class TinyTimeMixerConfig(PretrainedConfig):
|
| 147 |
+
r"""
|
| 148 |
+
This is the configuration class to store the configuration of a [`TinyTimeMixerModel`]. It is used to instantiate a
|
| 149 |
+
TinyTimeMixer model according to the specified arguments, defining the model architecture. Instantiating a
|
| 150 |
+
configuration with the defaults will yield a similar configuration to that of the TinyTimeMixer {} architecture.
|
| 151 |
+
|
| 152 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 153 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 154 |
+
|
| 155 |
+
Args:
|
| 156 |
+
context_length (`int`, *optional*, defaults to 64)
|
| 157 |
+
The context/history length for the input sequence.
|
| 158 |
+
patch_length (`int`, *optional*, defaults to 8)
|
| 159 |
+
The patch length for the input sequence.
|
| 160 |
+
num_input_channels (`int`):
|
| 161 |
+
Number of input variates. For Univariate, set it to 1.
|
| 162 |
+
patch_stride (`int`, *optional*, defaults to 8):
|
| 163 |
+
Amount of points to stride. If its value is same as patch_length, we get non-overlapping patches.
|
| 164 |
+
d_model (`int`, *optional*, defaults to 16):
|
| 165 |
+
Hidden feature size of the model.
|
| 166 |
+
prediction_length (`int`, *optional*, defaults to 16)
|
| 167 |
+
Number of time steps to forecast for a forecasting task. Also known as the Forecast Horizon.
|
| 168 |
+
expansion_factor (`int`, *optional*, defaults to 2):
|
| 169 |
+
Expansion factor to use inside MLP. Recommended range is 2-5. Larger value indicates more complex model.
|
| 170 |
+
num_layers (`int`, *optional*, defaults to 3):
|
| 171 |
+
Number of layers to use. Recommended range is 3-15. Larger value indicates more complex model.
|
| 172 |
+
dropout (`float`, *optional*, defaults to 0.2):
|
| 173 |
+
The dropout probability the `TinyTimeMixer` backbone. Recommended range is 0.2-0.7
|
| 174 |
+
mode (`str`, *optional*, defaults to `"common_channel"`):
|
| 175 |
+
Mixer Mode. Determines how to process the channels. Allowed values: "common_channel", "mix_channel". In
|
| 176 |
+
"common_channel" mode, we follow Channel-independent modelling with no explicit channel-mixing. Channel
|
| 177 |
+
mixing happens in an implicit manner via shared weights across channels. (preferred first approach) In
|
| 178 |
+
"mix_channel" mode, we follow explicit channel-mixing in addition to patch and feature mixer. (preferred
|
| 179 |
+
approach when channel correlations are very important to model)
|
| 180 |
+
gated_attn (`bool`, *optional*, defaults to `True`):
|
| 181 |
+
Enable Gated Attention.
|
| 182 |
+
norm_mlp (`str`, *optional*, defaults to `"LayerNorm"`):
|
| 183 |
+
Normalization layer (BatchNorm or LayerNorm).
|
| 184 |
+
self_attn (`bool`, *optional*, defaults to `False`):
|
| 185 |
+
Enable Tiny self attention across patches. This can be enabled when the output of Vanilla TinyTimeMixer with
|
| 186 |
+
gated attention is not satisfactory. Enabling this leads to explicit pair-wise attention and modelling
|
| 187 |
+
across patches.
|
| 188 |
+
self_attn_heads (`int`, *optional*, defaults to 1):
|
| 189 |
+
Number of self-attention heads. Works only when `self_attn` is set to `True`.
|
| 190 |
+
use_positional_encoding (`bool`, *optional*, defaults to `False`):
|
| 191 |
+
Enable the use of positional embedding for the tiny self-attention layers. Works only when `self_attn` is
|
| 192 |
+
set to `True`.
|
| 193 |
+
positional_encoding_type (`str`, *optional*, defaults to `"sincos"`):
|
| 194 |
+
Positional encodings. Options `"random"` and `"sincos"` are supported. Works only when
|
| 195 |
+
`use_positional_encoding` is set to `True`
|
| 196 |
+
scaling (`string` or `bool`, *optional*, defaults to `"std"`):
|
| 197 |
+
Whether to scale the input targets via "mean" scaler, "std" scaler or no scaler if `None`. If `True`, the
|
| 198 |
+
scaler is set to "mean".
|
| 199 |
+
loss (`string`, *optional*, defaults to `"mse"`):
|
| 200 |
+
The loss function for the model. Defaults to mean squared error "mse". Allowed values: ["mse", "mae"]
|
| 201 |
+
init_std (`float`, *optional*, defaults to 0.02):
|
| 202 |
+
The standard deviation of the truncated normal weight initialization distribution.
|
| 203 |
+
post_init (`bool`, *optional*, defaults to `False`):
|
| 204 |
+
Whether to use custom weight initialization from `transformers` library, or the default initialization in
|
| 205 |
+
`PyTorch`. Setting it to `False` performs `PyTorch` weight initialization.
|
| 206 |
+
norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 207 |
+
A value added to the denominator for numerical stability of normalization.
|
| 208 |
+
adaptive_patching_levels (`int`, *optional*, defaults to 0):
|
| 209 |
+
If adaptive_patching_levels is i, then we will have i levels with each level having n_layers.
|
| 210 |
+
Level id starts with 0. num_patches at level i will be multipled by (2^i) and num_features at level i will be divided by (2^i).
|
| 211 |
+
For Ex. if adaptive_patching_levels is 3 - then we will have 3 levels:
|
| 212 |
+
level 2: num_features//(2^2), num_patches*(2^2)
|
| 213 |
+
level 1: num_features//(2^1), num_patches*(2^1)
|
| 214 |
+
level 0: num_features//(2^0), num_patches*(2^0)
|
| 215 |
+
adaptive_patching_levels = 1 is same as one level PatchTSMixer. This module gets disabled when adaptive_patching_levels is 0 or neg value. Defaults to 0 (off mode).
|
| 216 |
+
resolution_prefix_tuning (`bool`, *optional*, defaults to `False`):
|
| 217 |
+
Enable if your dataloader has time resolution information as defined in `get_freq_mapping` function in `modelling_tinytimemixer`.
|
| 218 |
+
frequency_token_vocab_size (`int`, *optional*, defaults to 5):
|
| 219 |
+
Vocab size to use when resolution_prefix_tuning is enabled.
|
| 220 |
+
head_dropout (`float`, *optional*, defaults to 0.2):
|
| 221 |
+
The dropout probability the `TinyTimeMixer` head.
|
| 222 |
+
prediction_channel_indices (`list`, *optional*):
|
| 223 |
+
List of channel indices to forecast. If None, forecast all channels. Target data is expected to have all
|
| 224 |
+
channels and we explicitly filter the channels in prediction and target before loss computation. Please provide the indices
|
| 225 |
+
in sorted ascending order.
|
| 226 |
+
decoder_num_layers (`int`, *optional*, defaults to 8):
|
| 227 |
+
Number of layers to use in decoder
|
| 228 |
+
decoder_d_model(`int`, *optional*, defaults to 16):
|
| 229 |
+
Defines the hidden feature size of the decoder.
|
| 230 |
+
decoder_adaptive_patching_levels (`int`, *optional*, defaults to 0):
|
| 231 |
+
Adaptive Patching levels for decoder. Preferable to set it to 0 for decoder to keep it light weight.
|
| 232 |
+
decoder_raw_residual (`bool`, *optional*, defaults to `False`):
|
| 233 |
+
Flag to enable merging of raw embedding with encoder embedding for decoder input. Defaults to False.
|
| 234 |
+
decoder_mode (`string`, *optional*, defaults to `"common_channel"`):
|
| 235 |
+
Decoder channel mode. Use `"common_channel" for channel-independent modelling and `"mix_channel"` for channel-mixing modelling
|
| 236 |
+
use_decoder (`bool`, *optional*, defaults to `True`):
|
| 237 |
+
Enable to use decoder.
|
| 238 |
+
prediction_filter_length (`int`,*optional*, defaults to None):
|
| 239 |
+
Actual length in the prediction output to use for loss calculations.
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
Example:
|
| 243 |
+
|
| 244 |
+
```python
|
| 245 |
+
>>> from transformers import TinyTimeMixerConfig, TinyTimeMixerModel
|
| 246 |
+
|
| 247 |
+
>>> # Initializing a default TinyTimeMixer configuration
|
| 248 |
+
>>> configuration = TinyTimeMixerConfig()
|
| 249 |
+
|
| 250 |
+
>>> # Randomly initializing a model (with random weights) from the configuration
|
| 251 |
+
>>> model = TinyTimeMixerModel(configuration)
|
| 252 |
+
|
| 253 |
+
>>> # Accessing the model configuration
|
| 254 |
+
>>> configuration = model.config
|
| 255 |
+
```"""
|
| 256 |
+
|
| 257 |
+
model_type = "tinytimemixer"
|
| 258 |
+
attribute_map = {
|
| 259 |
+
"hidden_size": "d_model",
|
| 260 |
+
"num_hidden_layers": "num_layers",
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
def __init__(
|
| 264 |
+
self,
|
| 265 |
+
# Time series specific configuration
|
| 266 |
+
context_length: int = 64,
|
| 267 |
+
patch_length: int = 8,
|
| 268 |
+
num_input_channels: int = 1,
|
| 269 |
+
prediction_length: int = 16,
|
| 270 |
+
patch_stride: int = 8,
|
| 271 |
+
prediction_channel_indices: Optional[list] = None,
|
| 272 |
+
# General model configuration
|
| 273 |
+
d_model: int = 16,
|
| 274 |
+
expansion_factor: int = 2,
|
| 275 |
+
num_layers: int = 3,
|
| 276 |
+
dropout: float = 0.2,
|
| 277 |
+
mode: str = "common_channel",
|
| 278 |
+
gated_attn: bool = True,
|
| 279 |
+
norm_mlp: str = "LayerNorm",
|
| 280 |
+
self_attn: bool = False,
|
| 281 |
+
self_attn_heads: int = 1,
|
| 282 |
+
use_positional_encoding: bool = False,
|
| 283 |
+
positional_encoding_type: str = "sincos",
|
| 284 |
+
scaling: Optional[Union[str, bool]] = "std",
|
| 285 |
+
loss: str = "mse",
|
| 286 |
+
init_std: float = 0.02,
|
| 287 |
+
post_init: bool = False,
|
| 288 |
+
norm_eps: float = 1e-5,
|
| 289 |
+
adaptive_patching_levels: int = 0,
|
| 290 |
+
resolution_prefix_tuning: bool = False,
|
| 291 |
+
frequency_token_vocab_size: int = 5,
|
| 292 |
+
# General head configuration
|
| 293 |
+
head_dropout: float = 0.2,
|
| 294 |
+
# decoder parameters
|
| 295 |
+
decoder_num_layers: int = 8,
|
| 296 |
+
decoder_d_model: int = 8,
|
| 297 |
+
decoder_adaptive_patching_levels: int = 0,
|
| 298 |
+
decoder_raw_residual: bool = False,
|
| 299 |
+
decoder_mode: str = "common_channel",
|
| 300 |
+
use_decoder: bool = True,
|
| 301 |
+
# prediction length filtering
|
| 302 |
+
prediction_filter_length: Optional[int] = None,
|
| 303 |
+
**kwargs,
|
| 304 |
+
):
|
| 305 |
+
self.num_input_channels = num_input_channels
|
| 306 |
+
self.context_length = context_length
|
| 307 |
+
self.patch_length = patch_length
|
| 308 |
+
self.expansion_factor = expansion_factor
|
| 309 |
+
self.num_layers = num_layers
|
| 310 |
+
self.dropout = dropout
|
| 311 |
+
self.mode = mode
|
| 312 |
+
self.gated_attn = gated_attn
|
| 313 |
+
self.norm_mlp = norm_mlp
|
| 314 |
+
self.scaling = scaling
|
| 315 |
+
self.head_dropout = head_dropout
|
| 316 |
+
|
| 317 |
+
self.patch_last = True
|
| 318 |
+
self.use_positional_encoding = use_positional_encoding
|
| 319 |
+
self.positional_encoding_type = positional_encoding_type
|
| 320 |
+
self.prediction_length = prediction_length
|
| 321 |
+
self.prediction_channel_indices = prediction_channel_indices
|
| 322 |
+
self.self_attn = self_attn
|
| 323 |
+
self.self_attn_heads = self_attn_heads
|
| 324 |
+
self.init_std = init_std
|
| 325 |
+
self.post_init = post_init
|
| 326 |
+
self.loss = loss
|
| 327 |
+
self.norm_eps = norm_eps
|
| 328 |
+
|
| 329 |
+
self.use_decoder = use_decoder
|
| 330 |
+
|
| 331 |
+
self.adaptive_patching_levels = adaptive_patching_levels
|
| 332 |
+
self.resolution_prefix_tuning = resolution_prefix_tuning
|
| 333 |
+
self.decoder_num_layers = decoder_num_layers
|
| 334 |
+
self.decoder_adaptive_patching_levels = decoder_adaptive_patching_levels
|
| 335 |
+
self.decoder_raw_residual = decoder_raw_residual
|
| 336 |
+
self.decoder_mode = decoder_mode
|
| 337 |
+
self.frequency_token_vocab_size = frequency_token_vocab_size
|
| 338 |
+
self.d_model = d_model
|
| 339 |
+
self.patch_stride = patch_stride
|
| 340 |
+
self.decoder_d_model = decoder_d_model
|
| 341 |
+
self.init_processing = False
|
| 342 |
+
self.prediction_filter_length = prediction_filter_length
|
| 343 |
+
|
| 344 |
+
super().__init__(**kwargs)
|
| 345 |
+
|
| 346 |
+
def check_and_init_preprocessing(self):
|
| 347 |
+
self.init_processing = True
|
| 348 |
+
|
| 349 |
+
if not hasattr(self, "num_patches"):
|
| 350 |
+
self.num_patches = (
|
| 351 |
+
max(self.context_length, self.patch_length) - self.patch_length
|
| 352 |
+
) // self.patch_stride + 1
|
| 353 |
+
|
| 354 |
+
if self.resolution_prefix_tuning:
|
| 355 |
+
self.num_patches += 1
|
| 356 |
+
|
| 357 |
+
if self.prediction_filter_length is not None:
|
| 358 |
+
if self.prediction_filter_length > self.prediction_length or self.prediction_filter_length <= 0:
|
| 359 |
+
raise ValueError("prediction_filter_length should be positive and less than prediction_length")
|
| 360 |
+
|
| 361 |
+
if self.prediction_channel_indices is not None:
|
| 362 |
+
self.prediction_channel_indices.sort()
|
generation_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"do_sample": true,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
151645,
|
| 6 |
+
151643
|
| 7 |
+
],
|
| 8 |
+
"pad_token_id": 151643,
|
| 9 |
+
"repetition_penalty": 1.05,
|
| 10 |
+
"temperature": 0.7,
|
| 11 |
+
"top_k": 20,
|
| 12 |
+
"top_p": 0.8,
|
| 13 |
+
"transformers_version": "4.52.4"
|
| 14 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_qwen2.py
ADDED
|
@@ -0,0 +1,2063 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# The following code are reused from the QWen project (https://huggingface.co/Qwen/Qwen2.5-14B-Instruct) of Alibaba Cloud.
|
| 3 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 4 |
+
#
|
| 5 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
| 6 |
+
# and OPT implementations in this library. It has been modified from its
|
| 7 |
+
# original forms to accommodate minor architectural differences compared
|
| 8 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
| 9 |
+
#
|
| 10 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 11 |
+
# you may not use this file except in compliance with the License.
|
| 12 |
+
# You may obtain a copy of the License at
|
| 13 |
+
#
|
| 14 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 15 |
+
#
|
| 16 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 17 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 18 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 19 |
+
# See the License for the specific language governing permissions and
|
| 20 |
+
# limitations under the License.
|
| 21 |
+
|
| 22 |
+
# The code is modified by ByteDance and Tsinghua University from the original implementation of Qwen:
|
| 23 |
+
# - Support time series modality for Qwen2 model.
|
| 24 |
+
|
| 25 |
+
""" PyTorch Qwen2 model."""
|
| 26 |
+
import inspect
|
| 27 |
+
import math
|
| 28 |
+
import copy
|
| 29 |
+
from typing import List, Optional, Tuple, Union, Dict, Any
|
| 30 |
+
from dataclasses import dataclass
|
| 31 |
+
|
| 32 |
+
import torch
|
| 33 |
+
import torch.nn.functional as F
|
| 34 |
+
import torch.utils.checkpoint
|
| 35 |
+
from torch import nn
|
| 36 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 37 |
+
|
| 38 |
+
from transformers.activations import ACT2FN
|
| 39 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 40 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask, _prepare_4d_causal_attention_mask_for_sdpa
|
| 41 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
|
| 42 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 43 |
+
from transformers import AutoConfig
|
| 44 |
+
from transformers.utils import (
|
| 45 |
+
add_start_docstrings,
|
| 46 |
+
add_start_docstrings_to_model_forward,
|
| 47 |
+
is_flash_attn_2_available,
|
| 48 |
+
is_flash_attn_greater_or_equal_2_10,
|
| 49 |
+
logging,
|
| 50 |
+
replace_return_docstrings,
|
| 51 |
+
ModelOutput
|
| 52 |
+
)
|
| 53 |
+
from .configuration_qwen2 import Qwen2TSConfig, TinyTimeMixerConfig
|
| 54 |
+
|
| 55 |
+
# from .modeling_tinytimemixer import TinyTimeMixerForPrediction
|
| 56 |
+
# from .configuration_tinytimemixer import TinyTimeMixerConfig
|
| 57 |
+
|
| 58 |
+
if is_flash_attn_2_available():
|
| 59 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 60 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 61 |
+
|
| 62 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
logger = logging.get_logger(__name__)
|
| 66 |
+
|
| 67 |
+
_CHECKPOINT_FOR_DOC = "Qwen/Qwen2-7B-beta"
|
| 68 |
+
_CONFIG_FOR_DOC = "Qwen2TSConfig"
|
| 69 |
+
_GLOBAL_LOG = None
|
| 70 |
+
_GLOBAL_LOG_w = None
|
| 71 |
+
@dataclass
|
| 72 |
+
class Qwen2TSCausalLMOutputWithPast(ModelOutput):
|
| 73 |
+
"""
|
| 74 |
+
Base class for Qwen2TS causal language model (or autoregressive) outputs.
|
| 75 |
+
|
| 76 |
+
Args:
|
| 77 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 78 |
+
Language modeling loss (for next-token prediction).
|
| 79 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
| 80 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
| 81 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 82 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
|
| 83 |
+
`(batch_size, num_heads, sequence_length, embed_size_per_head)`)
|
| 84 |
+
|
| 85 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
|
| 86 |
+
`past_key_values` input) to speed up sequential decoding.
|
| 87 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
| 88 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
| 89 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
| 90 |
+
|
| 91 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
| 92 |
+
attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
|
| 93 |
+
Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
|
| 94 |
+
sequence_length)`.
|
| 95 |
+
|
| 96 |
+
Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
|
| 97 |
+
heads.
|
| 98 |
+
attention_mask (`torch.FloatTensor`, *optional*):
|
| 99 |
+
Attentions mask, used to update attention mask and position_ids.
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
loss: Optional[torch.FloatTensor] = None
|
| 103 |
+
logits: torch.FloatTensor = None
|
| 104 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None
|
| 105 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
| 106 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
| 107 |
+
attention_mask: Optional[torch.FloatTensor] = None
|
| 108 |
+
labels: Optional[torch.LongTensor] = None
|
| 109 |
+
new_token_positions: Optional[torch.LongTensor] = None
|
| 110 |
+
import torch
|
| 111 |
+
import torch.nn as nn
|
| 112 |
+
|
| 113 |
+
class RelativeSmoothL1Loss(nn.Module):
|
| 114 |
+
def __init__(self, beta=1.0, eps=1e-6, reduction='mean'):
|
| 115 |
+
super().__init__()
|
| 116 |
+
self.beta = beta
|
| 117 |
+
self.eps = eps
|
| 118 |
+
self.reduction = reduction
|
| 119 |
+
|
| 120 |
+
def forward(self, pred, target):
|
| 121 |
+
rel_diff = torch.abs(pred - target) / (torch.abs(target) + self.eps)
|
| 122 |
+
loss = torch.where(
|
| 123 |
+
rel_diff < self.beta,
|
| 124 |
+
0.5 * (rel_diff ** 2) / self.beta,
|
| 125 |
+
rel_diff - 0.5 * self.beta
|
| 126 |
+
)
|
| 127 |
+
if self.reduction == 'sum':
|
| 128 |
+
return loss.sum()
|
| 129 |
+
elif self.reduction == 'none':
|
| 130 |
+
return loss
|
| 131 |
+
else:
|
| 132 |
+
return loss.mean()
|
| 133 |
+
class RelativeSquaredErrorLoss(nn.Module):
|
| 134 |
+
def __init__(self, eps=1e-8, reduction='mean'):
|
| 135 |
+
super().__init__()
|
| 136 |
+
self.eps = eps
|
| 137 |
+
self.reduction = reduction
|
| 138 |
+
|
| 139 |
+
def forward(self, pred, target):
|
| 140 |
+
pred = pred.to(target.dtype)
|
| 141 |
+
|
| 142 |
+
numerator = torch.sum((pred - target) ** 2, dim=-1)
|
| 143 |
+
denominator = torch.sum((target - target.mean(dim=-1, keepdim=True)) ** 2, dim=-1) + self.eps
|
| 144 |
+
|
| 145 |
+
rse = torch.sqrt(numerator / denominator)
|
| 146 |
+
|
| 147 |
+
if self.reduction == 'sum':
|
| 148 |
+
return rse.sum()
|
| 149 |
+
elif self.reduction == 'none':
|
| 150 |
+
return rse
|
| 151 |
+
else:
|
| 152 |
+
return rse.mean()
|
| 153 |
+
########################Naive TS Decoder2#####################
|
| 154 |
+
class TimeSeriesDecoder(nn.Module):
|
| 155 |
+
def __init__(self, config):
|
| 156 |
+
super(TimeSeriesDecoder, self).__init__()
|
| 157 |
+
self.patch_size = config['patch_size']
|
| 158 |
+
self.hidden_size = config['hidden_size']
|
| 159 |
+
self.num_features = 1
|
| 160 |
+
self.dropout_rate = config.get('dropout_rate', 0.1)
|
| 161 |
+
|
| 162 |
+
layers = []
|
| 163 |
+
input_size = self.hidden_size
|
| 164 |
+
|
| 165 |
+
for _ in range(config['num_layers'] - 1):
|
| 166 |
+
layers.append(nn.Linear(input_size, input_size))
|
| 167 |
+
layers.append(nn.GELU())
|
| 168 |
+
layers.append(nn.Dropout(self.dropout_rate))
|
| 169 |
+
layers.append(nn.Linear(input_size, self.patch_size * 1))
|
| 170 |
+
|
| 171 |
+
self.mlp = nn.Sequential(*layers)
|
| 172 |
+
|
| 173 |
+
def forward(self, x: torch.Tensor, patch_cnt: list, original_lengths: torch.Tensor):
|
| 174 |
+
patches = self.mlp(x) # (total_patch_cnt, patch_size * num_features)
|
| 175 |
+
|
| 176 |
+
reconstructed = []
|
| 177 |
+
start_idx = 0
|
| 178 |
+
for pc in patch_cnt:
|
| 179 |
+
if pc == 0:
|
| 180 |
+
reconstructed.append(torch.zeros(0, 1, device=x.device))
|
| 181 |
+
continue
|
| 182 |
+
|
| 183 |
+
sample_patches = patches[start_idx: start_idx+pc]
|
| 184 |
+
start_idx += pc
|
| 185 |
+
sample_ts = sample_patches.reshape(-1, 1).squeeze(-1)
|
| 186 |
+
|
| 187 |
+
reconstructed.append(sample_ts)
|
| 188 |
+
if start_idx != patches.shape[0]:
|
| 189 |
+
raise ValueError(f'now_idx: {start_idx}\npatches: {patches.shape}\n ')
|
| 190 |
+
|
| 191 |
+
return reconstructed
|
| 192 |
+
|
| 193 |
+
########################Naive TS Embedding#####################
|
| 194 |
+
class TimeSeriesEmbedding(nn.Module):
|
| 195 |
+
def __init__(self, config):
|
| 196 |
+
super(TimeSeriesEmbedding, self).__init__()
|
| 197 |
+
self.patch_size = config['patch_size']
|
| 198 |
+
self.num_layers = config['num_layers']
|
| 199 |
+
self.hidden_size = config['hidden_size']
|
| 200 |
+
self.num_features = config['num_features']
|
| 201 |
+
self.max_sequence_length = config['max_sequence_length'] # Maximum time series length
|
| 202 |
+
self.use_position_embedding = config.get('use_position_embedding', False)
|
| 203 |
+
self.use_position_idx = config.get('use_position_idx', False)
|
| 204 |
+
self.embedding_dim = config.get('embedding_dim', 16) # Embedding dimension
|
| 205 |
+
|
| 206 |
+
if self.use_position_embedding:
|
| 207 |
+
# Extended vocabulary: [0, max_sequence_length) for real positions, max_sequence_length for padding
|
| 208 |
+
self.position_embedding = nn.Embedding(self.max_sequence_length + 1, self.embedding_dim)
|
| 209 |
+
self.padding_idx = self.max_sequence_length # Special index for padding
|
| 210 |
+
input_size = 1 * self.patch_size + self.embedding_dim * self.patch_size
|
| 211 |
+
elif self.use_position_idx:
|
| 212 |
+
input_size = 2 * self.patch_size
|
| 213 |
+
else:
|
| 214 |
+
input_size = 1 * self.patch_size
|
| 215 |
+
|
| 216 |
+
# Build MLP layers
|
| 217 |
+
layers = []
|
| 218 |
+
for _ in range(self.num_layers - 1):
|
| 219 |
+
layers.append(nn.Linear(input_size, self.hidden_size))
|
| 220 |
+
layers.append(nn.GELU())
|
| 221 |
+
input_size = self.hidden_size
|
| 222 |
+
layers.append(nn.Linear(input_size, self.hidden_size))
|
| 223 |
+
|
| 224 |
+
self.mlp = nn.Sequential(*layers)
|
| 225 |
+
|
| 226 |
+
def forward(self, x: torch.Tensor):
|
| 227 |
+
batch_size = x.size(0)
|
| 228 |
+
x = x.reshape(batch_size, -1, self.num_features)
|
| 229 |
+
|
| 230 |
+
# Extract mask and calculate valid lengths
|
| 231 |
+
mask = x[:, :, -1].long()
|
| 232 |
+
valid_lengths = mask.sum(dim=1).long()
|
| 233 |
+
patch_cnt = (valid_lengths + self.patch_size - 1) // self.patch_size
|
| 234 |
+
|
| 235 |
+
patches_list = []
|
| 236 |
+
# Collect position indices for batch embedding lookup
|
| 237 |
+
all_position_indices = []
|
| 238 |
+
patch_info_list = [] # Store metadata for each patch group
|
| 239 |
+
|
| 240 |
+
for i in range(batch_size):
|
| 241 |
+
vl = valid_lengths[i].item()
|
| 242 |
+
pc = patch_cnt[i].item()
|
| 243 |
+
if pc == 0:
|
| 244 |
+
continue
|
| 245 |
+
|
| 246 |
+
# Extract time series data (excluding mask)
|
| 247 |
+
xi = x[i, :vl, :1] # Time-series data
|
| 248 |
+
total_padded_length = pc * self.patch_size
|
| 249 |
+
padding_length = total_padded_length - vl
|
| 250 |
+
|
| 251 |
+
# Create position indices: real positions for actual data, special index for padding
|
| 252 |
+
position_indices = torch.arange(vl, device=x.device)
|
| 253 |
+
|
| 254 |
+
if padding_length > 0:
|
| 255 |
+
# Pad with last value
|
| 256 |
+
last_value = xi[-1:, :]
|
| 257 |
+
padding = last_value.repeat(padding_length, 1)
|
| 258 |
+
xi = torch.cat([xi, padding], dim=0)
|
| 259 |
+
|
| 260 |
+
# Use special padding index for padding positions
|
| 261 |
+
padding_positions = torch.full((padding_length,), self.padding_idx, device=x.device)
|
| 262 |
+
position_indices = torch.cat([position_indices, padding_positions], dim=0)
|
| 263 |
+
|
| 264 |
+
# Reshape to patches
|
| 265 |
+
xi = xi.reshape(pc, self.patch_size) # (num_patches, patch_size)
|
| 266 |
+
position_indices = position_indices.reshape(pc, self.patch_size) # (num_patches, patch_size)
|
| 267 |
+
|
| 268 |
+
if self.use_position_embedding:
|
| 269 |
+
# Collect position indices instead of calling embedding immediately
|
| 270 |
+
all_position_indices.append(position_indices)
|
| 271 |
+
patch_info_list.append({
|
| 272 |
+
'xi': xi,
|
| 273 |
+
'pc': pc,
|
| 274 |
+
'sample_idx': i
|
| 275 |
+
})
|
| 276 |
+
elif self.use_position_idx:
|
| 277 |
+
# Normalize position indices
|
| 278 |
+
pos_indices = torch.arange(vl, device=x.device).unsqueeze(1)
|
| 279 |
+
pos_indices = pos_indices / max(1, valid_lengths.max().item() - 1)
|
| 280 |
+
if padding_length > 0:
|
| 281 |
+
# Use -1 for padding positions
|
| 282 |
+
padding_indices = torch.full((padding_length, 1), -1, device=x.device)
|
| 283 |
+
pos_indices = torch.cat([pos_indices, padding_indices], dim=0)
|
| 284 |
+
# Combine time series data with position indices
|
| 285 |
+
xi_combined = torch.cat([xi.reshape(-1, 1), pos_indices], dim=1)
|
| 286 |
+
patch_input = xi_combined.reshape(pc, self.patch_size * 2)
|
| 287 |
+
patches_list.append(patch_input)
|
| 288 |
+
else:
|
| 289 |
+
# No position embedding, use raw patches
|
| 290 |
+
patch_input = xi
|
| 291 |
+
patches_list.append(patch_input)
|
| 292 |
+
|
| 293 |
+
# Batch process position embeddings if needed
|
| 294 |
+
if self.use_position_embedding and all_position_indices:
|
| 295 |
+
# Concatenate all position indices for batch embedding lookup
|
| 296 |
+
batch_position_indices = torch.cat(all_position_indices, dim=0)
|
| 297 |
+
# print(f"{x.shape=}, {x.device=}, {len(all_position_indices)=}, {batch_position_indices=}")
|
| 298 |
+
batch_pos_emb = self.position_embedding(batch_position_indices) # Single embedding call
|
| 299 |
+
|
| 300 |
+
# Split embeddings back and create patch inputs
|
| 301 |
+
emb_start_idx = 0
|
| 302 |
+
for patch_info in patch_info_list:
|
| 303 |
+
xi = patch_info['xi']
|
| 304 |
+
pc = patch_info['pc']
|
| 305 |
+
|
| 306 |
+
# Extract corresponding embeddings
|
| 307 |
+
pos_emb = batch_pos_emb[emb_start_idx:emb_start_idx + pc]
|
| 308 |
+
emb_start_idx += pc
|
| 309 |
+
|
| 310 |
+
# Flatten and concatenate
|
| 311 |
+
xi = xi.unsqueeze(-1) # (num_patches, patch_size, 1)
|
| 312 |
+
patch_input = torch.cat([
|
| 313 |
+
xi.flatten(1), # (num_patches, patch_size)
|
| 314 |
+
pos_emb.flatten(1) # (num_patches, patch_size * embedding_dim)
|
| 315 |
+
], dim=1)
|
| 316 |
+
patches_list.append(patch_input)
|
| 317 |
+
|
| 318 |
+
# Process all patches through MLP
|
| 319 |
+
if patches_list:
|
| 320 |
+
x_patches = torch.cat(patches_list, dim=0).to(dtype=next(self.mlp.parameters()).dtype)
|
| 321 |
+
x = self.mlp(x_patches)
|
| 322 |
+
else:
|
| 323 |
+
# Handle empty case
|
| 324 |
+
x = torch.empty(0, self.hidden_size, device=x.device)
|
| 325 |
+
|
| 326 |
+
return x, patch_cnt
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
########################QWEN2###################################
|
| 330 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
| 331 |
+
def _get_unpad_data(attention_mask):
|
| 332 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
| 333 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
| 334 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
| 335 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
| 336 |
+
return (
|
| 337 |
+
indices,
|
| 338 |
+
cu_seqlens,
|
| 339 |
+
max_seqlen_in_batch,
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Qwen2
|
| 344 |
+
class Qwen2RMSNorm(nn.Module):
|
| 345 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 346 |
+
"""
|
| 347 |
+
Qwen2RMSNorm is equivalent to T5LayerNorm
|
| 348 |
+
"""
|
| 349 |
+
super().__init__()
|
| 350 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 351 |
+
self.variance_epsilon = eps
|
| 352 |
+
|
| 353 |
+
def forward(self, hidden_states):
|
| 354 |
+
input_dtype = hidden_states.dtype
|
| 355 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 356 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 357 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 358 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralRotaryEmbedding with Mistral->Qwen2
|
| 362 |
+
class Qwen2RotaryEmbedding(nn.Module):
|
| 363 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
| 364 |
+
super().__init__()
|
| 365 |
+
|
| 366 |
+
self.dim = dim
|
| 367 |
+
self.max_position_embeddings = max_position_embeddings
|
| 368 |
+
self.base = base
|
| 369 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(device) / self.dim))
|
| 370 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 371 |
+
|
| 372 |
+
# Build here to make `torch.jit.trace` work.
|
| 373 |
+
self._set_cos_sin_cache(
|
| 374 |
+
seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
| 378 |
+
self.max_seq_len_cached = seq_len
|
| 379 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.int64).type_as(self.inv_freq)
|
| 380 |
+
|
| 381 |
+
freqs = torch.outer(t, self.inv_freq)
|
| 382 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
| 383 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 384 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
| 385 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
| 386 |
+
|
| 387 |
+
def forward(self, x, seq_len=None):
|
| 388 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
| 389 |
+
if seq_len > self.max_seq_len_cached:
|
| 390 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
|
| 391 |
+
|
| 392 |
+
return (
|
| 393 |
+
self.cos_cached[:seq_len].to(dtype=x.dtype),
|
| 394 |
+
self.sin_cached[:seq_len].to(dtype=x.dtype),
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
| 399 |
+
def rotate_half(x):
|
| 400 |
+
"""Rotates half the hidden dims of the input."""
|
| 401 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 402 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 403 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
# Copied from transformers.models.mistral.modeling_mistral.apply_rotary_pos_emb
|
| 407 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
|
| 408 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 409 |
+
|
| 410 |
+
Args:
|
| 411 |
+
q (`torch.Tensor`): The query tensor.
|
| 412 |
+
k (`torch.Tensor`): The key tensor.
|
| 413 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 414 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 415 |
+
position_ids (`torch.Tensor`):
|
| 416 |
+
The position indices of the tokens corresponding to the query and key tensors. For example, this can be
|
| 417 |
+
used to pass offsetted position ids when working with a KV-cache.
|
| 418 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 419 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 420 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 421 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 422 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 423 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 424 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 425 |
+
Returns:
|
| 426 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 427 |
+
"""
|
| 428 |
+
cos = cos[position_ids].unsqueeze(unsqueeze_dim)
|
| 429 |
+
sin = sin[position_ids].unsqueeze(unsqueeze_dim)
|
| 430 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 431 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 432 |
+
return q_embed, k_embed
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralMLP with Mistral->Qwen2
|
| 436 |
+
class Qwen2MLP(nn.Module):
|
| 437 |
+
def __init__(self, config):
|
| 438 |
+
super().__init__()
|
| 439 |
+
self.config = config
|
| 440 |
+
self.hidden_size = config.hidden_size
|
| 441 |
+
self.intermediate_size = config.intermediate_size
|
| 442 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 443 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 444 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
| 445 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 446 |
+
|
| 447 |
+
def forward(self, x):
|
| 448 |
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv
|
| 452 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 453 |
+
"""
|
| 454 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 455 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 456 |
+
"""
|
| 457 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 458 |
+
if n_rep == 1:
|
| 459 |
+
return hidden_states
|
| 460 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 461 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
class Qwen2Attention(nn.Module):
|
| 465 |
+
"""
|
| 466 |
+
Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer
|
| 467 |
+
and "Generating Long Sequences with Sparse Transformers".
|
| 468 |
+
"""
|
| 469 |
+
|
| 470 |
+
def __init__(self, config: Qwen2TSConfig, layer_idx: Optional[int] = None):
|
| 471 |
+
super().__init__()
|
| 472 |
+
self.config = config
|
| 473 |
+
self.layer_idx = layer_idx
|
| 474 |
+
if layer_idx is None:
|
| 475 |
+
logger.warning_once(
|
| 476 |
+
f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
|
| 477 |
+
"to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
|
| 478 |
+
"when creating this class."
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
self.hidden_size = config.hidden_size
|
| 482 |
+
self.num_heads = config.num_attention_heads
|
| 483 |
+
self.head_dim = self.hidden_size // self.num_heads
|
| 484 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 485 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
| 486 |
+
self.max_position_embeddings = config.max_position_embeddings
|
| 487 |
+
self.rope_theta = config.rope_theta
|
| 488 |
+
self.is_causal = True
|
| 489 |
+
self.attention_dropout = config.attention_dropout
|
| 490 |
+
|
| 491 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
| 492 |
+
raise ValueError(
|
| 493 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
| 494 |
+
f" and `num_heads`: {self.num_heads})."
|
| 495 |
+
)
|
| 496 |
+
self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=True)
|
| 497 |
+
self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
|
| 498 |
+
self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
|
| 499 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
| 500 |
+
|
| 501 |
+
self.rotary_emb = Qwen2RotaryEmbedding(
|
| 502 |
+
self.head_dim,
|
| 503 |
+
max_position_embeddings=self.max_position_embeddings,
|
| 504 |
+
base=self.rope_theta,
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
def forward(
|
| 508 |
+
self,
|
| 509 |
+
hidden_states: torch.Tensor,
|
| 510 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 511 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 512 |
+
past_key_value: Optional[Cache] = None,
|
| 513 |
+
output_attentions: bool = False,
|
| 514 |
+
use_cache: bool = False,
|
| 515 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 516 |
+
bsz, q_len, _ = hidden_states.size()
|
| 517 |
+
|
| 518 |
+
query_states = self.q_proj(hidden_states)
|
| 519 |
+
key_states = self.k_proj(hidden_states)
|
| 520 |
+
value_states = self.v_proj(hidden_states)
|
| 521 |
+
|
| 522 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 523 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 524 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 525 |
+
|
| 526 |
+
kv_seq_len = key_states.shape[-2]
|
| 527 |
+
if past_key_value is not None:
|
| 528 |
+
if self.layer_idx is None:
|
| 529 |
+
raise ValueError(
|
| 530 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 531 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 532 |
+
"with a layer index."
|
| 533 |
+
)
|
| 534 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 535 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
| 536 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 537 |
+
|
| 538 |
+
if past_key_value is not None:
|
| 539 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 540 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 541 |
+
|
| 542 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 543 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 544 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 545 |
+
|
| 546 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
| 547 |
+
|
| 548 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
| 549 |
+
raise ValueError(
|
| 550 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
| 551 |
+
f" {attn_weights.size()}"
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
if attention_mask is not None:
|
| 555 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 556 |
+
raise ValueError(
|
| 557 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 558 |
+
)
|
| 559 |
+
|
| 560 |
+
attn_weights = attn_weights + attention_mask
|
| 561 |
+
|
| 562 |
+
# upcast attention to fp32
|
| 563 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
|
| 564 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
| 565 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 566 |
+
|
| 567 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
| 568 |
+
raise ValueError(
|
| 569 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
| 570 |
+
f" {attn_output.size()}"
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 574 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
| 575 |
+
|
| 576 |
+
attn_output = self.o_proj(attn_output)
|
| 577 |
+
|
| 578 |
+
if not output_attentions:
|
| 579 |
+
attn_weights = None
|
| 580 |
+
|
| 581 |
+
return attn_output, attn_weights, past_key_value
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
class Qwen2FlashAttention2(Qwen2Attention):
|
| 585 |
+
"""
|
| 586 |
+
Qwen2 flash attention module, following Qwen2 attention module. This module inherits from `Qwen2Attention`
|
| 587 |
+
as the weights of the module stays untouched. The only required change would be on the forward pass
|
| 588 |
+
where it needs to correctly call the public API of flash attention and deal with padding tokens
|
| 589 |
+
in case the input contains any of them. Additionally, for sliding window attention, we apply SWA only to the bottom
|
| 590 |
+
config.max_window_layers layers.
|
| 591 |
+
"""
|
| 592 |
+
|
| 593 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
|
| 594 |
+
def __init__(self, *args, **kwargs):
|
| 595 |
+
super().__init__(*args, **kwargs)
|
| 596 |
+
|
| 597 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
| 598 |
+
# flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
|
| 599 |
+
# Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
|
| 600 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
| 601 |
+
|
| 602 |
+
def forward(
|
| 603 |
+
self,
|
| 604 |
+
hidden_states: torch.Tensor,
|
| 605 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 606 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 607 |
+
past_key_value: Optional[Cache] = None,
|
| 608 |
+
output_attentions: bool = False,
|
| 609 |
+
use_cache: bool = False,
|
| 610 |
+
):
|
| 611 |
+
bsz, q_len, _ = hidden_states.size()
|
| 612 |
+
|
| 613 |
+
query_states = self.q_proj(hidden_states)
|
| 614 |
+
key_states = self.k_proj(hidden_states)
|
| 615 |
+
value_states = self.v_proj(hidden_states)
|
| 616 |
+
|
| 617 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 618 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 619 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 620 |
+
|
| 621 |
+
kv_seq_len = key_states.shape[-2]
|
| 622 |
+
if past_key_value is not None:
|
| 623 |
+
if self.layer_idx is None:
|
| 624 |
+
raise ValueError(
|
| 625 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 626 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 627 |
+
"with a layer index."
|
| 628 |
+
)
|
| 629 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 630 |
+
|
| 631 |
+
# Because the input can be padded, the absolute sequence length depends on the max position id.
|
| 632 |
+
rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
|
| 633 |
+
cos, sin = self.rotary_emb(value_states, seq_len=rotary_seq_len)
|
| 634 |
+
|
| 635 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 636 |
+
|
| 637 |
+
use_sliding_windows = (
|
| 638 |
+
_flash_supports_window_size
|
| 639 |
+
and getattr(self.config, "sliding_window", None) is not None
|
| 640 |
+
and kv_seq_len > self.config.sliding_window
|
| 641 |
+
and self.config.use_sliding_window
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
if not _flash_supports_window_size:
|
| 645 |
+
logger.warning_once(
|
| 646 |
+
"The current flash attention version does not support sliding window attention, for a more memory efficient implementation"
|
| 647 |
+
" make sure to upgrade flash-attn library."
|
| 648 |
+
)
|
| 649 |
+
|
| 650 |
+
if past_key_value is not None:
|
| 651 |
+
# Activate slicing cache only if the config has a value `sliding_windows` attribute
|
| 652 |
+
cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
|
| 653 |
+
if (
|
| 654 |
+
getattr(self.config, "sliding_window", None) is not None
|
| 655 |
+
and kv_seq_len > self.config.sliding_window
|
| 656 |
+
and cache_has_contents
|
| 657 |
+
):
|
| 658 |
+
slicing_tokens = 1 - self.config.sliding_window
|
| 659 |
+
|
| 660 |
+
past_key = past_key_value[self.layer_idx][0]
|
| 661 |
+
past_value = past_key_value[self.layer_idx][1]
|
| 662 |
+
|
| 663 |
+
past_key = past_key[:, :, slicing_tokens:, :].contiguous()
|
| 664 |
+
past_value = past_value[:, :, slicing_tokens:, :].contiguous()
|
| 665 |
+
|
| 666 |
+
if past_key.shape[-2] != self.config.sliding_window - 1:
|
| 667 |
+
raise ValueError(
|
| 668 |
+
f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
|
| 669 |
+
f" {past_key.shape}"
|
| 670 |
+
)
|
| 671 |
+
|
| 672 |
+
if attention_mask is not None:
|
| 673 |
+
attention_mask = attention_mask[:, slicing_tokens:]
|
| 674 |
+
attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
|
| 675 |
+
|
| 676 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 677 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 678 |
+
|
| 679 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 680 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 681 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 682 |
+
dropout_rate = 0.0 if not self.training else self.attention_dropout
|
| 683 |
+
|
| 684 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
| 685 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
| 686 |
+
# cast them back in float16 just to be sure everything works as expected.
|
| 687 |
+
input_dtype = query_states.dtype
|
| 688 |
+
if input_dtype == torch.float32:
|
| 689 |
+
if torch.is_autocast_enabled():
|
| 690 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
| 691 |
+
# Handle the case where the model is quantized
|
| 692 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
| 693 |
+
target_dtype = self.config._pre_quantization_dtype
|
| 694 |
+
else:
|
| 695 |
+
target_dtype = self.q_proj.weight.dtype
|
| 696 |
+
|
| 697 |
+
logger.warning_once(
|
| 698 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
| 699 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
| 700 |
+
f" {target_dtype}."
|
| 701 |
+
)
|
| 702 |
+
|
| 703 |
+
query_states = query_states.to(target_dtype)
|
| 704 |
+
key_states = key_states.to(target_dtype)
|
| 705 |
+
value_states = value_states.to(target_dtype)
|
| 706 |
+
|
| 707 |
+
# Reashape to the expected shape for Flash Attention
|
| 708 |
+
query_states = query_states.transpose(1, 2)
|
| 709 |
+
key_states = key_states.transpose(1, 2)
|
| 710 |
+
value_states = value_states.transpose(1, 2)
|
| 711 |
+
|
| 712 |
+
attn_output = self._flash_attention_forward(
|
| 713 |
+
query_states,
|
| 714 |
+
key_states,
|
| 715 |
+
value_states,
|
| 716 |
+
attention_mask,
|
| 717 |
+
q_len,
|
| 718 |
+
dropout=dropout_rate,
|
| 719 |
+
use_sliding_windows=use_sliding_windows,
|
| 720 |
+
)
|
| 721 |
+
|
| 722 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
| 723 |
+
attn_output = self.o_proj(attn_output)
|
| 724 |
+
|
| 725 |
+
if not output_attentions:
|
| 726 |
+
attn_weights = None
|
| 727 |
+
|
| 728 |
+
return attn_output, attn_weights, past_key_value
|
| 729 |
+
|
| 730 |
+
def _flash_attention_forward(
|
| 731 |
+
self,
|
| 732 |
+
query_states,
|
| 733 |
+
key_states,
|
| 734 |
+
value_states,
|
| 735 |
+
attention_mask,
|
| 736 |
+
query_length,
|
| 737 |
+
dropout=0.0,
|
| 738 |
+
softmax_scale=None,
|
| 739 |
+
use_sliding_windows=False,
|
| 740 |
+
):
|
| 741 |
+
"""
|
| 742 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
| 743 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
| 744 |
+
|
| 745 |
+
Args:
|
| 746 |
+
query_states (`torch.Tensor`):
|
| 747 |
+
Input query states to be passed to Flash Attention API
|
| 748 |
+
key_states (`torch.Tensor`):
|
| 749 |
+
Input key states to be passed to Flash Attention API
|
| 750 |
+
value_states (`torch.Tensor`):
|
| 751 |
+
Input value states to be passed to Flash Attention API
|
| 752 |
+
attention_mask (`torch.Tensor`):
|
| 753 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
| 754 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
| 755 |
+
dropout (`float`):
|
| 756 |
+
Attention dropout
|
| 757 |
+
softmax_scale (`float`, *optional*):
|
| 758 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
| 759 |
+
use_sliding_windows (`bool`, *optional*):
|
| 760 |
+
Whether to activate sliding window attention.
|
| 761 |
+
"""
|
| 762 |
+
if not self._flash_attn_uses_top_left_mask:
|
| 763 |
+
causal = self.is_causal
|
| 764 |
+
else:
|
| 765 |
+
# TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
|
| 766 |
+
causal = self.is_causal and query_length != 1
|
| 767 |
+
|
| 768 |
+
# Decide whether to use SWA or not by layer index.
|
| 769 |
+
if use_sliding_windows and self.layer_idx >= self.config.max_window_layers:
|
| 770 |
+
use_sliding_windows = False
|
| 771 |
+
|
| 772 |
+
# Contains at least one padding token in the sequence
|
| 773 |
+
if attention_mask is not None:
|
| 774 |
+
batch_size = query_states.shape[0]
|
| 775 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
| 776 |
+
query_states, key_states, value_states, attention_mask, query_length
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
| 780 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
| 781 |
+
|
| 782 |
+
if not use_sliding_windows:
|
| 783 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 784 |
+
query_states,
|
| 785 |
+
key_states,
|
| 786 |
+
value_states,
|
| 787 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 788 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 789 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 790 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 791 |
+
dropout_p=dropout,
|
| 792 |
+
softmax_scale=softmax_scale,
|
| 793 |
+
causal=causal,
|
| 794 |
+
)
|
| 795 |
+
else:
|
| 796 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 797 |
+
query_states,
|
| 798 |
+
key_states,
|
| 799 |
+
value_states,
|
| 800 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 801 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 802 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 803 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 804 |
+
dropout_p=dropout,
|
| 805 |
+
softmax_scale=softmax_scale,
|
| 806 |
+
causal=causal,
|
| 807 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
| 811 |
+
else:
|
| 812 |
+
if not use_sliding_windows:
|
| 813 |
+
attn_output = flash_attn_func(
|
| 814 |
+
query_states,
|
| 815 |
+
key_states,
|
| 816 |
+
value_states,
|
| 817 |
+
dropout,
|
| 818 |
+
softmax_scale=softmax_scale,
|
| 819 |
+
causal=causal,
|
| 820 |
+
)
|
| 821 |
+
else:
|
| 822 |
+
attn_output = flash_attn_func(
|
| 823 |
+
query_states,
|
| 824 |
+
key_states,
|
| 825 |
+
value_states,
|
| 826 |
+
dropout,
|
| 827 |
+
softmax_scale=softmax_scale,
|
| 828 |
+
causal=causal,
|
| 829 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 830 |
+
)
|
| 831 |
+
|
| 832 |
+
return attn_output
|
| 833 |
+
|
| 834 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
|
| 835 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
| 836 |
+
batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
|
| 837 |
+
|
| 838 |
+
# On the first iteration we need to properly re-create the padding mask
|
| 839 |
+
# by slicing it on the proper place
|
| 840 |
+
if kv_seq_len != attention_mask.shape[-1]:
|
| 841 |
+
attention_mask_num_tokens = attention_mask.shape[-1]
|
| 842 |
+
attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
|
| 843 |
+
|
| 844 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
| 845 |
+
|
| 846 |
+
key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 847 |
+
value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 848 |
+
|
| 849 |
+
if query_length == kv_seq_len:
|
| 850 |
+
query_layer = index_first_axis(
|
| 851 |
+
query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
|
| 852 |
+
)
|
| 853 |
+
cu_seqlens_q = cu_seqlens_k
|
| 854 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
| 855 |
+
indices_q = indices_k
|
| 856 |
+
elif query_length == 1:
|
| 857 |
+
max_seqlen_in_batch_q = 1
|
| 858 |
+
cu_seqlens_q = torch.arange(
|
| 859 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
| 860 |
+
) # There is a memcpy here, that is very bad.
|
| 861 |
+
indices_q = cu_seqlens_q[:-1]
|
| 862 |
+
query_layer = query_layer.squeeze(1)
|
| 863 |
+
else:
|
| 864 |
+
# The -q_len: slice assumes left padding.
|
| 865 |
+
attention_mask = attention_mask[:, -query_length:]
|
| 866 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
| 867 |
+
|
| 868 |
+
return (
|
| 869 |
+
query_layer,
|
| 870 |
+
key_layer,
|
| 871 |
+
value_layer,
|
| 872 |
+
indices_q,
|
| 873 |
+
(cu_seqlens_q, cu_seqlens_k),
|
| 874 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
| 875 |
+
)
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralSdpaAttention with Mistral->Qwen2
|
| 879 |
+
class Qwen2SdpaAttention(Qwen2Attention):
|
| 880 |
+
"""
|
| 881 |
+
Qwen2 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
| 882 |
+
`Qwen2Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
| 883 |
+
SDPA API.
|
| 884 |
+
"""
|
| 885 |
+
|
| 886 |
+
# Adapted from Qwen2Attention.forward
|
| 887 |
+
def forward(
|
| 888 |
+
self,
|
| 889 |
+
hidden_states: torch.Tensor,
|
| 890 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 891 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 892 |
+
past_key_value: Optional[Cache] = None,
|
| 893 |
+
output_attentions: bool = False,
|
| 894 |
+
use_cache: bool = False,
|
| 895 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 896 |
+
if output_attentions:
|
| 897 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
| 898 |
+
logger.warning_once(
|
| 899 |
+
"Qwen2Model is using Qwen2SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
| 900 |
+
'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
| 901 |
+
)
|
| 902 |
+
return super().forward(
|
| 903 |
+
hidden_states=hidden_states,
|
| 904 |
+
attention_mask=attention_mask,
|
| 905 |
+
position_ids=position_ids,
|
| 906 |
+
past_key_value=past_key_value,
|
| 907 |
+
output_attentions=output_attentions,
|
| 908 |
+
use_cache=use_cache,
|
| 909 |
+
)
|
| 910 |
+
|
| 911 |
+
bsz, q_len, _ = hidden_states.size()
|
| 912 |
+
|
| 913 |
+
query_states = self.q_proj(hidden_states)
|
| 914 |
+
key_states = self.k_proj(hidden_states)
|
| 915 |
+
value_states = self.v_proj(hidden_states)
|
| 916 |
+
|
| 917 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 918 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 919 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 920 |
+
|
| 921 |
+
kv_seq_len = key_states.shape[-2]
|
| 922 |
+
if past_key_value is not None:
|
| 923 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 924 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
| 925 |
+
|
| 926 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 927 |
+
|
| 928 |
+
if past_key_value is not None:
|
| 929 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 930 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 931 |
+
|
| 932 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 933 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 934 |
+
|
| 935 |
+
if attention_mask is not None:
|
| 936 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 937 |
+
raise ValueError(
|
| 938 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 939 |
+
)
|
| 940 |
+
|
| 941 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
| 942 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
| 943 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
| 944 |
+
query_states = query_states.contiguous()
|
| 945 |
+
key_states = key_states.contiguous()
|
| 946 |
+
value_states = value_states.contiguous()
|
| 947 |
+
|
| 948 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
| 949 |
+
query_states,
|
| 950 |
+
key_states,
|
| 951 |
+
value_states,
|
| 952 |
+
attn_mask=attention_mask,
|
| 953 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
| 954 |
+
# The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
|
| 955 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
| 956 |
+
)
|
| 957 |
+
|
| 958 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 959 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
| 960 |
+
|
| 961 |
+
attn_output = self.o_proj(attn_output)
|
| 962 |
+
|
| 963 |
+
return attn_output, None, past_key_value
|
| 964 |
+
|
| 965 |
+
|
| 966 |
+
QWEN2_ATTENTION_CLASSES = {
|
| 967 |
+
"eager": Qwen2Attention,
|
| 968 |
+
"flash_attention_2": Qwen2FlashAttention2,
|
| 969 |
+
"sdpa": Qwen2SdpaAttention,
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
|
| 973 |
+
class Qwen2DecoderLayer(nn.Module):
|
| 974 |
+
def __init__(self, config: Qwen2TSConfig, layer_idx: int):
|
| 975 |
+
super().__init__()
|
| 976 |
+
self.hidden_size = config.hidden_size
|
| 977 |
+
|
| 978 |
+
if config.use_sliding_window and config._attn_implementation != "flash_attention_2":
|
| 979 |
+
logger.warning_once(
|
| 980 |
+
f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
|
| 981 |
+
"unexpected results may be encountered."
|
| 982 |
+
)
|
| 983 |
+
self.self_attn = QWEN2_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)
|
| 984 |
+
|
| 985 |
+
self.mlp = Qwen2MLP(config)
|
| 986 |
+
self.input_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 987 |
+
self.post_attention_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 988 |
+
|
| 989 |
+
def forward(
|
| 990 |
+
self,
|
| 991 |
+
hidden_states: torch.Tensor,
|
| 992 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 993 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 994 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
| 995 |
+
output_attentions: Optional[bool] = False,
|
| 996 |
+
use_cache: Optional[bool] = False,
|
| 997 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 998 |
+
"""
|
| 999 |
+
Args:
|
| 1000 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 1001 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 1002 |
+
`(batch, sequence_length)` where padding elements are indicated by 0.
|
| 1003 |
+
output_attentions (`bool`, *optional*):
|
| 1004 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 1005 |
+
returned tensors for more detail.
|
| 1006 |
+
use_cache (`bool`, *optional*):
|
| 1007 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 1008 |
+
(see `past_key_values`).
|
| 1009 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
| 1010 |
+
"""
|
| 1011 |
+
|
| 1012 |
+
residual = hidden_states
|
| 1013 |
+
|
| 1014 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 1015 |
+
|
| 1016 |
+
# Self Attention
|
| 1017 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
| 1018 |
+
hidden_states=hidden_states,
|
| 1019 |
+
attention_mask=attention_mask,
|
| 1020 |
+
position_ids=position_ids,
|
| 1021 |
+
past_key_value=past_key_value,
|
| 1022 |
+
output_attentions=output_attentions,
|
| 1023 |
+
use_cache=use_cache,
|
| 1024 |
+
)
|
| 1025 |
+
hidden_states = residual + hidden_states
|
| 1026 |
+
|
| 1027 |
+
# Fully Connected
|
| 1028 |
+
residual = hidden_states
|
| 1029 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 1030 |
+
hidden_states = self.mlp(hidden_states)
|
| 1031 |
+
hidden_states = residual + hidden_states
|
| 1032 |
+
|
| 1033 |
+
outputs = (hidden_states,)
|
| 1034 |
+
|
| 1035 |
+
if output_attentions:
|
| 1036 |
+
outputs += (self_attn_weights,)
|
| 1037 |
+
|
| 1038 |
+
if use_cache:
|
| 1039 |
+
outputs += (present_key_value,)
|
| 1040 |
+
|
| 1041 |
+
return outputs
|
| 1042 |
+
|
| 1043 |
+
|
| 1044 |
+
QWEN2_START_DOCSTRING = r"""
|
| 1045 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 1046 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 1047 |
+
etc.)
|
| 1048 |
+
|
| 1049 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 1050 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 1051 |
+
and behavior.
|
| 1052 |
+
|
| 1053 |
+
Parameters:
|
| 1054 |
+
config ([`Qwen2TSConfig`]):
|
| 1055 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 1056 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 1057 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 1058 |
+
"""
|
| 1059 |
+
|
| 1060 |
+
|
| 1061 |
+
@add_start_docstrings(
|
| 1062 |
+
"The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
|
| 1063 |
+
QWEN2_START_DOCSTRING,
|
| 1064 |
+
)
|
| 1065 |
+
class Qwen2PreTrainedModel(PreTrainedModel):
|
| 1066 |
+
config_class = Qwen2TSConfig
|
| 1067 |
+
base_model_prefix = "model"
|
| 1068 |
+
supports_gradient_checkpointing = True
|
| 1069 |
+
_no_split_modules = ["Qwen2DecoderLayer"]
|
| 1070 |
+
_skip_keys_device_placement = "past_key_values"
|
| 1071 |
+
_supports_flash_attn_2 = True
|
| 1072 |
+
_supports_sdpa = True
|
| 1073 |
+
_supports_cache_class = True
|
| 1074 |
+
|
| 1075 |
+
def _init_weights(self, module):
|
| 1076 |
+
std = self.config.initializer_range
|
| 1077 |
+
if isinstance(module, nn.Linear):
|
| 1078 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 1079 |
+
if module.bias is not None:
|
| 1080 |
+
module.bias.data.zero_()
|
| 1081 |
+
elif isinstance(module, nn.Embedding):
|
| 1082 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 1083 |
+
if module.padding_idx is not None:
|
| 1084 |
+
module.weight.data[module.padding_idx].zero_()
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
class TSProjector(nn.Module):
|
| 1088 |
+
def __init__(self, config: Qwen2TSConfig):
|
| 1089 |
+
super().__init__()
|
| 1090 |
+
self.config = config
|
| 1091 |
+
self.linear_1 = nn.Linear(config.ts['d_model'], config.hidden_size, bias=True)
|
| 1092 |
+
self.linear_2 = nn.LayerNorm(config.hidden_size, bias=True)
|
| 1093 |
+
self.linear_3 = nn.Linear(config.hidden_size, config.hidden_size * 4, bias=True)
|
| 1094 |
+
self.linear_4 = nn.LayerNorm(config.hidden_size * 4, bias=True)
|
| 1095 |
+
self.act = nn.GELU()
|
| 1096 |
+
|
| 1097 |
+
def forward(self, ts_features):
|
| 1098 |
+
hidden_states = self.linear_1(ts_features)
|
| 1099 |
+
hidden_states = self.linear_2(hidden_states)
|
| 1100 |
+
hidden_states = self.act(hidden_states)
|
| 1101 |
+
hidden_states = self.linear_3(hidden_states)
|
| 1102 |
+
hidden_states = self.linear_4(hidden_states)
|
| 1103 |
+
hidden_states = hidden_states.reshape(hidden_states.size(0), -1, self.config.hidden_size)
|
| 1104 |
+
return hidden_states
|
| 1105 |
+
|
| 1106 |
+
|
| 1107 |
+
QWEN2_INPUTS_DOCSTRING = r"""
|
| 1108 |
+
Args:
|
| 1109 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 1110 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 1111 |
+
it.
|
| 1112 |
+
|
| 1113 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 1114 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 1115 |
+
|
| 1116 |
+
[What are input IDs?](../glossary#input-ids)
|
| 1117 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1118 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 1119 |
+
|
| 1120 |
+
- 1 for tokens that are **not masked**,
|
| 1121 |
+
- 0 for tokens that are **masked**.
|
| 1122 |
+
|
| 1123 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 1124 |
+
|
| 1125 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 1126 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 1127 |
+
|
| 1128 |
+
If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
| 1129 |
+
`past_key_values`).
|
| 1130 |
+
|
| 1131 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 1132 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 1133 |
+
information on the default strategy.
|
| 1134 |
+
|
| 1135 |
+
- 1 indicates the head is **not masked**,
|
| 1136 |
+
- 0 indicates the head is **masked**.
|
| 1137 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1138 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 1139 |
+
config.n_positions - 1]`.
|
| 1140 |
+
|
| 1141 |
+
[What are position IDs?](../glossary#position-ids)
|
| 1142 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 1143 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 1144 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 1145 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 1146 |
+
|
| 1147 |
+
Two formats are allowed:
|
| 1148 |
+
- a [`~cache_utils.Cache`] instance;
|
| 1149 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 1150 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 1151 |
+
cache format.
|
| 1152 |
+
|
| 1153 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 1154 |
+
legacy cache format will be returned.
|
| 1155 |
+
|
| 1156 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 1157 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 1158 |
+
of shape `(batch_size, sequence_length)`.
|
| 1159 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 1160 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 1161 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 1162 |
+
model's internal embedding lookup matrix.
|
| 1163 |
+
use_cache (`bool`, *optional*):
|
| 1164 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 1165 |
+
`past_key_values`).
|
| 1166 |
+
output_attentions (`bool`, *optional*):
|
| 1167 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 1168 |
+
tensors for more detail.
|
| 1169 |
+
output_hidden_states (`bool`, *optional*):
|
| 1170 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 1171 |
+
more detail.
|
| 1172 |
+
return_dict (`bool`, *optional*):
|
| 1173 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 1174 |
+
"""
|
| 1175 |
+
|
| 1176 |
+
|
| 1177 |
+
@add_start_docstrings(
|
| 1178 |
+
"The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
|
| 1179 |
+
QWEN2_START_DOCSTRING,
|
| 1180 |
+
)
|
| 1181 |
+
class Qwen2Model(Qwen2PreTrainedModel):
|
| 1182 |
+
"""
|
| 1183 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Qwen2DecoderLayer`]
|
| 1184 |
+
|
| 1185 |
+
Args:
|
| 1186 |
+
config: Qwen2TSConfig
|
| 1187 |
+
"""
|
| 1188 |
+
|
| 1189 |
+
def __init__(self, config: Qwen2TSConfig):
|
| 1190 |
+
super().__init__(config)
|
| 1191 |
+
self.padding_idx = config.pad_token_id
|
| 1192 |
+
self.vocab_size = config.vocab_size
|
| 1193 |
+
|
| 1194 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 1195 |
+
self.layers = nn.ModuleList(
|
| 1196 |
+
[Qwen2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 1197 |
+
)
|
| 1198 |
+
self._attn_implementation = config._attn_implementation
|
| 1199 |
+
self.norm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 1200 |
+
|
| 1201 |
+
self.gradient_checkpointing = False
|
| 1202 |
+
|
| 1203 |
+
# Initialize weights and apply final processing
|
| 1204 |
+
self.post_init()
|
| 1205 |
+
|
| 1206 |
+
def get_input_embeddings(self):
|
| 1207 |
+
return self.embed_tokens
|
| 1208 |
+
|
| 1209 |
+
def set_input_embeddings(self, value):
|
| 1210 |
+
self.embed_tokens = value
|
| 1211 |
+
|
| 1212 |
+
@add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
|
| 1213 |
+
def forward(
|
| 1214 |
+
self,
|
| 1215 |
+
input_ids: torch.LongTensor = None,
|
| 1216 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1217 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1218 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1219 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1220 |
+
use_cache: Optional[bool] = None,
|
| 1221 |
+
output_attentions: Optional[bool] = None,
|
| 1222 |
+
output_hidden_states: Optional[bool] = None,
|
| 1223 |
+
return_dict: Optional[bool] = None,
|
| 1224 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 1225 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1226 |
+
output_hidden_states = (
|
| 1227 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1228 |
+
)
|
| 1229 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1230 |
+
|
| 1231 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1232 |
+
|
| 1233 |
+
# retrieve input_ids and inputs_embeds
|
| 1234 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 1235 |
+
raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
|
| 1236 |
+
elif input_ids is not None:
|
| 1237 |
+
batch_size, seq_length = input_ids.shape
|
| 1238 |
+
elif inputs_embeds is not None:
|
| 1239 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
| 1240 |
+
else:
|
| 1241 |
+
raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
|
| 1242 |
+
|
| 1243 |
+
if self.gradient_checkpointing and self.training:
|
| 1244 |
+
if use_cache:
|
| 1245 |
+
logger.warning_once(
|
| 1246 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
| 1247 |
+
)
|
| 1248 |
+
use_cache = False
|
| 1249 |
+
|
| 1250 |
+
past_key_values_length = 0
|
| 1251 |
+
|
| 1252 |
+
if use_cache:
|
| 1253 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
| 1254 |
+
if use_legacy_cache:
|
| 1255 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
| 1256 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
| 1257 |
+
|
| 1258 |
+
if position_ids is None:
|
| 1259 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
| 1260 |
+
position_ids = torch.arange(
|
| 1261 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
| 1262 |
+
)
|
| 1263 |
+
position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
|
| 1264 |
+
else:
|
| 1265 |
+
position_ids = position_ids.view(-1, seq_length).long()
|
| 1266 |
+
|
| 1267 |
+
if inputs_embeds is None:
|
| 1268 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 1269 |
+
|
| 1270 |
+
if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
|
| 1271 |
+
is_padding_right = attention_mask[:, -1].sum().item() != batch_size
|
| 1272 |
+
if is_padding_right:
|
| 1273 |
+
raise ValueError(
|
| 1274 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 1275 |
+
" this may lead to unexpected behaviour for Flash Attention version of Qwen2. Make sure to "
|
| 1276 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 1277 |
+
)
|
| 1278 |
+
|
| 1279 |
+
if self._attn_implementation == "flash_attention_2":
|
| 1280 |
+
# 2d mask is passed through the layers
|
| 1281 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
| 1282 |
+
elif self._attn_implementation == "sdpa" and not output_attentions:
|
| 1283 |
+
# output_attentions=True can not be supported when using SDPA, and we fall back on
|
| 1284 |
+
# the manual implementation that requires a 4D causal mask in all cases.
|
| 1285 |
+
attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
|
| 1286 |
+
attention_mask,
|
| 1287 |
+
(batch_size, seq_length),
|
| 1288 |
+
inputs_embeds,
|
| 1289 |
+
past_key_values_length,
|
| 1290 |
+
sliding_window=self.config.sliding_window,
|
| 1291 |
+
)
|
| 1292 |
+
else:
|
| 1293 |
+
# 4d mask is passed through the layers
|
| 1294 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
| 1295 |
+
attention_mask,
|
| 1296 |
+
(batch_size, seq_length),
|
| 1297 |
+
inputs_embeds,
|
| 1298 |
+
past_key_values_length,
|
| 1299 |
+
sliding_window=self.config.sliding_window,
|
| 1300 |
+
)
|
| 1301 |
+
|
| 1302 |
+
hidden_states = inputs_embeds
|
| 1303 |
+
|
| 1304 |
+
# decoder layers
|
| 1305 |
+
all_hidden_states = () if output_hidden_states else None
|
| 1306 |
+
all_self_attns = () if output_attentions else None
|
| 1307 |
+
next_decoder_cache = None
|
| 1308 |
+
|
| 1309 |
+
for decoder_layer in self.layers:
|
| 1310 |
+
if output_hidden_states:
|
| 1311 |
+
all_hidden_states += (hidden_states,)
|
| 1312 |
+
|
| 1313 |
+
if self.gradient_checkpointing and self.training:
|
| 1314 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 1315 |
+
decoder_layer.__call__,
|
| 1316 |
+
hidden_states,
|
| 1317 |
+
attention_mask,
|
| 1318 |
+
position_ids,
|
| 1319 |
+
past_key_values,
|
| 1320 |
+
output_attentions,
|
| 1321 |
+
use_cache,
|
| 1322 |
+
)
|
| 1323 |
+
else:
|
| 1324 |
+
layer_outputs = decoder_layer(
|
| 1325 |
+
hidden_states,
|
| 1326 |
+
attention_mask=attention_mask,
|
| 1327 |
+
position_ids=position_ids,
|
| 1328 |
+
past_key_value=past_key_values,
|
| 1329 |
+
output_attentions=output_attentions,
|
| 1330 |
+
use_cache=use_cache,
|
| 1331 |
+
)
|
| 1332 |
+
|
| 1333 |
+
hidden_states = layer_outputs[0]
|
| 1334 |
+
|
| 1335 |
+
if use_cache:
|
| 1336 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
| 1337 |
+
|
| 1338 |
+
if output_attentions:
|
| 1339 |
+
all_self_attns += (layer_outputs[1],)
|
| 1340 |
+
|
| 1341 |
+
hidden_states = self.norm(hidden_states)
|
| 1342 |
+
|
| 1343 |
+
# add hidden states from the last decoder layer
|
| 1344 |
+
if output_hidden_states:
|
| 1345 |
+
all_hidden_states += (hidden_states,)
|
| 1346 |
+
|
| 1347 |
+
next_cache = None
|
| 1348 |
+
if use_cache:
|
| 1349 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
| 1350 |
+
|
| 1351 |
+
if not return_dict:
|
| 1352 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
| 1353 |
+
return BaseModelOutputWithPast(
|
| 1354 |
+
last_hidden_state=hidden_states,
|
| 1355 |
+
past_key_values=next_cache,
|
| 1356 |
+
hidden_states=all_hidden_states,
|
| 1357 |
+
attentions=all_self_attns,
|
| 1358 |
+
)
|
| 1359 |
+
|
| 1360 |
+
|
| 1361 |
+
class Qwen2TSForCausalLM(Qwen2PreTrainedModel):
|
| 1362 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 1363 |
+
|
| 1364 |
+
def __init__(self, config):
|
| 1365 |
+
super().__init__(config)
|
| 1366 |
+
self.config = config
|
| 1367 |
+
|
| 1368 |
+
self.model = Qwen2Model(config)
|
| 1369 |
+
self.vocab_size = config.vocab_size
|
| 1370 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1371 |
+
self.ts_loss_func = RelativeSquaredErrorLoss()
|
| 1372 |
+
# TS embedding
|
| 1373 |
+
self.ts_encoder = TimeSeriesEmbedding(config.ts)
|
| 1374 |
+
self.ts_decoder = TimeSeriesDecoder(config.ts)
|
| 1375 |
+
|
| 1376 |
+
# Initialize weights and apply final processing
|
| 1377 |
+
self.post_init()
|
| 1378 |
+
|
| 1379 |
+
def get_input_embeddings(self):
|
| 1380 |
+
return self.model.embed_tokens
|
| 1381 |
+
|
| 1382 |
+
def set_input_embeddings(self, value):
|
| 1383 |
+
self.model.embed_tokens = value
|
| 1384 |
+
|
| 1385 |
+
def get_output_embeddings(self):
|
| 1386 |
+
return self.lm_head
|
| 1387 |
+
|
| 1388 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1389 |
+
self.lm_head = new_embeddings
|
| 1390 |
+
|
| 1391 |
+
def set_decoder(self, decoder):
|
| 1392 |
+
self.model = decoder
|
| 1393 |
+
|
| 1394 |
+
def get_decoder(self):
|
| 1395 |
+
return self.model
|
| 1396 |
+
def _merge_input_ids_with_time_series_features(
|
| 1397 |
+
self, time_series_features, inputs_embeds, input_ids, attention_mask, labels, patch_cnt
|
| 1398 |
+
):
|
| 1399 |
+
batch_size, sequence_length = input_ids.shape
|
| 1400 |
+
_left_padding = torch.any(attention_mask[:, 0] == 0)
|
| 1401 |
+
_right_padding = torch.any(attention_mask[:, -1] == 0)
|
| 1402 |
+
left_padding = False
|
| 1403 |
+
if batch_size > 1:
|
| 1404 |
+
if _left_padding and not _right_padding:
|
| 1405 |
+
left_padding = True
|
| 1406 |
+
elif not _left_padding and _right_padding:
|
| 1407 |
+
left_padding = False
|
| 1408 |
+
elif not _left_padding and not _right_padding:
|
| 1409 |
+
left_padding = False
|
| 1410 |
+
else:
|
| 1411 |
+
raise ValueError(f"both side of attention_mask has zero, invalid. {attention_mask}")
|
| 1412 |
+
else:
|
| 1413 |
+
if _left_padding and not _right_padding:
|
| 1414 |
+
left_padding = True
|
| 1415 |
+
else:
|
| 1416 |
+
left_padding = False
|
| 1417 |
+
|
| 1418 |
+
# 1. Create a mask to know where special time series tokens are
|
| 1419 |
+
special_ts_token_mask_start = input_ids == self.config.ts_token_start_index
|
| 1420 |
+
special_ts_token_mask_end = input_ids == self.config.ts_token_end_index
|
| 1421 |
+
special_ts_token_mask = special_ts_token_mask_start | special_ts_token_mask_end
|
| 1422 |
+
|
| 1423 |
+
# 2. Calculate patch count
|
| 1424 |
+
num_special_ts_tokens = torch.sum(special_ts_token_mask_start, dim=-1)
|
| 1425 |
+
total_time_steps, embed_dim = time_series_features.shape
|
| 1426 |
+
|
| 1427 |
+
# Correctly calculate the total number of patches per batch
|
| 1428 |
+
patch_index = 0
|
| 1429 |
+
num_total_patches = torch.zeros(batch_size, dtype=patch_cnt.dtype, device=patch_cnt.device)
|
| 1430 |
+
special_ts_token_mask_start_nonzero = special_ts_token_mask_start.nonzero()
|
| 1431 |
+
special_ts_token_mask_start_with_size = special_ts_token_mask_start.clone().long()
|
| 1432 |
+
|
| 1433 |
+
attn_mask_cnt = attention_mask.sum(dim=-1)
|
| 1434 |
+
for i in range(batch_size):
|
| 1435 |
+
num_ts_in_batch = num_special_ts_tokens[i]
|
| 1436 |
+
num_total_patches[i] = patch_cnt[patch_index : patch_index + num_ts_in_batch].sum() - 2 * num_ts_in_batch
|
| 1437 |
+
for idx in range(patch_index, patch_index + num_ts_in_batch):
|
| 1438 |
+
b_idx, pos = special_ts_token_mask_start_nonzero[idx]
|
| 1439 |
+
special_ts_token_mask_start_with_size[b_idx, pos] *= (patch_cnt[idx].item() - 2)
|
| 1440 |
+
patch_index += num_ts_in_batch
|
| 1441 |
+
attn_mask_cnt[i] += num_total_patches[i].item()
|
| 1442 |
+
|
| 1443 |
+
# 3. Embeding length
|
| 1444 |
+
max_embed_dim = sequence_length + num_total_patches.max()
|
| 1445 |
+
|
| 1446 |
+
# 4. Non ts tokens
|
| 1447 |
+
batch_indices, non_ts_indices = torch.where(~special_ts_token_mask)
|
| 1448 |
+
attn_batch_indices, attn_indices = torch.where(attention_mask == 1)
|
| 1449 |
+
|
| 1450 |
+
# 5. Text token in final text positions
|
| 1451 |
+
new_token_positions = torch.cumsum((special_ts_token_mask_start_with_size + 1), dim=-1) - 1
|
| 1452 |
+
|
| 1453 |
+
# nb_ts_pad
|
| 1454 |
+
nb_ts_pad = max_embed_dim - 1 - new_token_positions[:, -1]
|
| 1455 |
+
if left_padding:
|
| 1456 |
+
new_token_positions += nb_ts_pad[:, None]
|
| 1457 |
+
|
| 1458 |
+
text_to_overwrite = new_token_positions[batch_indices, non_ts_indices]
|
| 1459 |
+
|
| 1460 |
+
# 6. Final embedding and attention masks
|
| 1461 |
+
final_embedding = torch.zeros(
|
| 1462 |
+
batch_size, max_embed_dim, embed_dim, dtype=inputs_embeds.dtype, device=inputs_embeds.device
|
| 1463 |
+
)
|
| 1464 |
+
|
| 1465 |
+
final_attention_mask = torch.zeros(batch_size, max_embed_dim, dtype=attention_mask.dtype, device=inputs_embeds.device)
|
| 1466 |
+
for i in range(attention_mask.size(0)):
|
| 1467 |
+
if left_padding:
|
| 1468 |
+
final_attention_mask[i, max_embed_dim - attn_mask_cnt[i] :] = 1
|
| 1469 |
+
else:
|
| 1470 |
+
final_attention_mask[i, : attn_mask_cnt[i]] = 1
|
| 1471 |
+
|
| 1472 |
+
final_labels = None
|
| 1473 |
+
if labels is not None:
|
| 1474 |
+
final_labels = torch.full(
|
| 1475 |
+
(batch_size, max_embed_dim), self.config.ignore_index, dtype=input_ids.dtype, device=input_ids.device
|
| 1476 |
+
)
|
| 1477 |
+
|
| 1478 |
+
target_device = inputs_embeds.device
|
| 1479 |
+
batch_indices, non_ts_indices, text_to_overwrite = (
|
| 1480 |
+
batch_indices.to(target_device),
|
| 1481 |
+
non_ts_indices.to(target_device),
|
| 1482 |
+
text_to_overwrite.to(target_device),
|
| 1483 |
+
)
|
| 1484 |
+
|
| 1485 |
+
# 7. Move embedding and labels to final positions
|
| 1486 |
+
final_embedding[batch_indices, text_to_overwrite] = inputs_embeds[batch_indices, non_ts_indices]
|
| 1487 |
+
if labels is not None:
|
| 1488 |
+
final_labels[batch_indices, text_to_overwrite] = labels[batch_indices, non_ts_indices]
|
| 1489 |
+
|
| 1490 |
+
# 8. Move time series to final positions
|
| 1491 |
+
ts_to_overwrite = torch.full(
|
| 1492 |
+
(batch_size, max_embed_dim), True, dtype=torch.bool, device=inputs_embeds.device
|
| 1493 |
+
)
|
| 1494 |
+
ts_to_overwrite[batch_indices, text_to_overwrite] = False
|
| 1495 |
+
|
| 1496 |
+
reversed_cumsum = ts_to_overwrite.flip(dims=[-1]).cumsum(-1).flip(dims=[-1]) - 1
|
| 1497 |
+
ts_to_overwrite &= reversed_cumsum >= nb_ts_pad[:, None].to(target_device)
|
| 1498 |
+
|
| 1499 |
+
# Check that the number of time series tokens is correct
|
| 1500 |
+
if ts_to_overwrite.sum() != time_series_features.shape[:-1].numel():
|
| 1501 |
+
raise ValueError(
|
| 1502 |
+
f"The input provided to the model are wrong. The number of time series tokens is {torch.sum(special_ts_token_mask_start)} while"
|
| 1503 |
+
f" the number of time series given to the model is {len(patch_cnt)}. This prevents correct indexing and breaks batch generation."
|
| 1504 |
+
)
|
| 1505 |
+
final_embedding[ts_to_overwrite] = time_series_features.contiguous().reshape(-1, embed_dim).to(target_device)
|
| 1506 |
+
position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_((final_attention_mask == 0), 1)
|
| 1507 |
+
if position_ids.size(-1) < input_ids.size(-1):
|
| 1508 |
+
position_ids = position_ids[:, -input_ids.size(-1) :]
|
| 1509 |
+
|
| 1510 |
+
# 10. Move attention mask to final positions
|
| 1511 |
+
pad_batch_indices, pad_indices = torch.where(input_ids == self.config.pad_token_id)
|
| 1512 |
+
if len(pad_batch_indices) > 0:
|
| 1513 |
+
indices_to_mask = new_token_positions[pad_batch_indices, pad_indices]
|
| 1514 |
+
final_embedding[pad_batch_indices, indices_to_mask] = 0
|
| 1515 |
+
max_extra_pad = None
|
| 1516 |
+
input_end_pos = None
|
| 1517 |
+
train_start_pos = None
|
| 1518 |
+
if final_labels is not None:
|
| 1519 |
+
# 1. 识别关键位置
|
| 1520 |
+
# 输入内容结束位置(每个样本有效输入的长度)
|
| 1521 |
+
#logger_zr(f'{"-"*10}\n attention_mask {final_attention_mask} \n final_labels {final_labels}\n{"-"*10}')
|
| 1522 |
+
# 训练标注开始位置(每个样本第一个非ignore_index的位置)
|
| 1523 |
+
train_start_pos = torch.argmax((final_labels != self.config.ignore_index).int(), dim=1)
|
| 1524 |
+
use_bos = hasattr(self.config, 'bos_token_id') and self.config.bos_token_id is not None
|
| 1525 |
+
offset = 1 # 在BOS之后进行添加
|
| 1526 |
+
|
| 1527 |
+
# 计算输入结束位置(训练开始位置 - 偏移量)
|
| 1528 |
+
input_end_pos = train_start_pos - offset
|
| 1529 |
+
# 处理无训练标注的样本
|
| 1530 |
+
has_trainable = (final_labels != self.config.ignore_index).any(dim=1)
|
| 1531 |
+
train_start_pos = torch.where(has_trainable, train_start_pos, input_end_pos)
|
| 1532 |
+
extra_pad_counts = []
|
| 1533 |
+
patch_idx = 0
|
| 1534 |
+
for i in range(batch_size):
|
| 1535 |
+
num_ts = num_special_ts_tokens[i]
|
| 1536 |
+
total_patch = patch_cnt[patch_idx:patch_idx+num_ts].sum().item()
|
| 1537 |
+
extra_pad_counts.append(total_patch)
|
| 1538 |
+
patch_idx += num_ts
|
| 1539 |
+
extra_pad_counts = torch.tensor(extra_pad_counts, device=labels.device)
|
| 1540 |
+
max_extra_pad = extra_pad_counts.max()
|
| 1541 |
+
new_max_embed_dim = max_embed_dim + max_extra_pad
|
| 1542 |
+
new_final_embedding = torch.zeros(
|
| 1543 |
+
batch_size, new_max_embed_dim, embed_dim,
|
| 1544 |
+
dtype=inputs_embeds.dtype, device=inputs_embeds.device
|
| 1545 |
+
)
|
| 1546 |
+
new_final_attention_mask = torch.ones(
|
| 1547 |
+
batch_size, new_max_embed_dim,
|
| 1548 |
+
dtype=attention_mask.dtype, device=inputs_embeds.device
|
| 1549 |
+
)
|
| 1550 |
+
new_final_labels = torch.full(
|
| 1551 |
+
(batch_size, new_max_embed_dim), self.config.ignore_index,
|
| 1552 |
+
dtype=labels.dtype, device=labels.device
|
| 1553 |
+
)
|
| 1554 |
+
|
| 1555 |
+
# 4. 填充新张量(核心逻辑:在输入后、标注前插入padding)
|
| 1556 |
+
for i in range(batch_size):
|
| 1557 |
+
pad_count = extra_pad_counts[i]
|
| 1558 |
+
input_end = input_end_pos[i].item() # 输入内容结束位置
|
| 1559 |
+
train_start = train_start_pos[i].item() # 训练标注开始位置
|
| 1560 |
+
|
| 1561 |
+
# 校验位置合理性(输入结束 <= 标注开始)
|
| 1562 |
+
if input_end > train_start:
|
| 1563 |
+
raise ValueError(f"样本 {i} 输入结束位置({input_end})大于标注开始位置({train_start}),无法插入padding")
|
| 1564 |
+
|
| 1565 |
+
# 复制输入内容([0, input_end))
|
| 1566 |
+
new_final_embedding[i, :input_end] = final_embedding[i, :input_end]
|
| 1567 |
+
new_final_attention_mask[i, :input_end] = final_attention_mask[i, :input_end]
|
| 1568 |
+
|
| 1569 |
+
# 插入额外padding([input_end, input_end+pad_count))
|
| 1570 |
+
# embedding保持0,attention_mask设为0(不参与注意力),labels设为ignore_index(不参与loss)
|
| 1571 |
+
|
| 1572 |
+
# 复制输入与标注之间的非训练区域([input_end, train_start))
|
| 1573 |
+
non_train_length = train_start - input_end
|
| 1574 |
+
if non_train_length > 0:
|
| 1575 |
+
new_final_embedding[i, input_end+pad_count : input_end+pad_count+non_train_length] = \
|
| 1576 |
+
final_embedding[i, input_end : train_start]
|
| 1577 |
+
new_final_attention_mask[i, input_end+pad_count : input_end+pad_count+non_train_length] = \
|
| 1578 |
+
final_attention_mask[i, input_end : train_start]
|
| 1579 |
+
new_final_labels[i, input_end+pad_count : input_end+pad_count+non_train_length] = \
|
| 1580 |
+
final_labels[i, input_end : train_start]
|
| 1581 |
+
|
| 1582 |
+
# 复制训练标注内容([train_start, ...))
|
| 1583 |
+
train_content_length = max_embed_dim - train_start
|
| 1584 |
+
new_final_embedding[i, input_end+pad_count+non_train_length : input_end+pad_count+non_train_length+train_content_length] = \
|
| 1585 |
+
final_embedding[i, train_start : ]
|
| 1586 |
+
new_final_attention_mask[i, input_end+pad_count+non_train_length : input_end+pad_count+non_train_length+train_content_length] = \
|
| 1587 |
+
final_attention_mask[i, train_start : ]
|
| 1588 |
+
new_final_labels[i, input_end+pad_count+non_train_length : input_end+pad_count+non_train_length+train_content_length] = \
|
| 1589 |
+
final_labels[i, train_start : ]
|
| 1590 |
+
|
| 1591 |
+
# 5. 更新变量
|
| 1592 |
+
final_embedding = new_final_embedding
|
| 1593 |
+
final_attention_mask = new_final_attention_mask
|
| 1594 |
+
final_labels = new_final_labels
|
| 1595 |
+
max_embed_dim = new_max_embed_dim
|
| 1596 |
+
|
| 1597 |
+
position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_((final_attention_mask == 0), 1)
|
| 1598 |
+
if position_ids.size(-1) < input_ids.size(-1):
|
| 1599 |
+
position_ids = position_ids[:, -input_ids.size(-1) :]
|
| 1600 |
+
|
| 1601 |
+
expanded_new_token_positions = torch.full(
|
| 1602 |
+
(batch_size, max_embed_dim),
|
| 1603 |
+
-1,
|
| 1604 |
+
dtype=new_token_positions.dtype,
|
| 1605 |
+
device=new_token_positions.device
|
| 1606 |
+
)
|
| 1607 |
+
|
| 1608 |
+
expanded_new_token_positions[batch_indices, text_to_overwrite] = \
|
| 1609 |
+
new_token_positions[batch_indices, non_ts_indices]
|
| 1610 |
+
|
| 1611 |
+
new_token_positions = expanded_new_token_positions.masked_fill(final_attention_mask == 0, -1)
|
| 1612 |
+
return final_embedding, final_attention_mask, position_ids, final_labels, new_token_positions, max_extra_pad, train_start_pos, input_end_pos
|
| 1613 |
+
|
| 1614 |
+
@add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
|
| 1615 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
| 1616 |
+
def forward(
|
| 1617 |
+
self,
|
| 1618 |
+
input_ids: torch.LongTensor = None,
|
| 1619 |
+
timeseries: torch.FloatTensor = None,
|
| 1620 |
+
target_timeseries: torch.FloatTensor = None,
|
| 1621 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1622 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1623 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1624 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1625 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1626 |
+
use_cache: Optional[bool] = None,
|
| 1627 |
+
output_attentions: Optional[bool] = None,
|
| 1628 |
+
output_hidden_states: Optional[bool] = None,
|
| 1629 |
+
return_dict: Optional[bool] = None,
|
| 1630 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1631 |
+
r"""
|
| 1632 |
+
Args:
|
| 1633 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1634 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1635 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1636 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1637 |
+
|
| 1638 |
+
Returns:
|
| 1639 |
+
|
| 1640 |
+
Example:
|
| 1641 |
+
|
| 1642 |
+
```python
|
| 1643 |
+
>>> from transformers import AutoTokenizer, Qwen2ForCausalLM
|
| 1644 |
+
|
| 1645 |
+
>>> model = Qwen2ForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
|
| 1646 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
|
| 1647 |
+
|
| 1648 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 1649 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1650 |
+
|
| 1651 |
+
>>> # Generate
|
| 1652 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1653 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1654 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 1655 |
+
```"""
|
| 1656 |
+
|
| 1657 |
+
# if input_ids is not None and timeseries is not None:
|
| 1658 |
+
# # Batch decode the input
|
| 1659 |
+
# input_text = self.tokenizer.batch_decode(input_ids, skip_special_tokens=False)
|
| 1660 |
+
# # Print the input text
|
| 1661 |
+
# print("=================================================================")
|
| 1662 |
+
# print("Input text:", input_text)
|
| 1663 |
+
# print("Timeseries shape:", timeseries.shape)
|
| 1664 |
+
# print("=================================================================\n\n")
|
| 1665 |
+
# else:
|
| 1666 |
+
# print("Time series is None!!!!")
|
| 1667 |
+
|
| 1668 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1669 |
+
output_hidden_states = (
|
| 1670 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1671 |
+
)
|
| 1672 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1673 |
+
|
| 1674 |
+
original_lengths = None
|
| 1675 |
+
if timeseries is not None:
|
| 1676 |
+
original_lengths = timeseries[:, :, -1].long().sum(dim=1) # (batch_size,)
|
| 1677 |
+
if inputs_embeds is None:
|
| 1678 |
+
inputs_embeds = self.get_input_embeddings()(input_ids)
|
| 1679 |
+
|
| 1680 |
+
if timeseries is not None and timeseries.shape[0] > 0:
|
| 1681 |
+
# use_cache = False
|
| 1682 |
+
# print(f"timeseries shape: {timeseries.shape=}, {input_ids.shape=}")
|
| 1683 |
+
ts_features, patch_cnt = self.ts_encoder(timeseries)
|
| 1684 |
+
inputs_embeds = inputs_embeds.to(ts_features.dtype)
|
| 1685 |
+
|
| 1686 |
+
inputs_embeds, attention_mask, position_ids, labels, new_token_positions, max_extra_pad, _train_start_pos, _input_end_pos = self._merge_input_ids_with_time_series_features(
|
| 1687 |
+
ts_features, inputs_embeds, input_ids, attention_mask, labels, patch_cnt
|
| 1688 |
+
)
|
| 1689 |
+
# print(f"{inputs_embeds.shape=}, {attention_mask.shape=}, {position_ids.shape=}, {labels.shape=}")
|
| 1690 |
+
|
| 1691 |
+
outputs = self.model(
|
| 1692 |
+
attention_mask=attention_mask,
|
| 1693 |
+
position_ids=position_ids,
|
| 1694 |
+
past_key_values=past_key_values,
|
| 1695 |
+
inputs_embeds=inputs_embeds,
|
| 1696 |
+
use_cache=use_cache,
|
| 1697 |
+
output_attentions=output_attentions,
|
| 1698 |
+
output_hidden_states=output_hidden_states,
|
| 1699 |
+
return_dict=return_dict,
|
| 1700 |
+
)
|
| 1701 |
+
|
| 1702 |
+
hidden_states = outputs[0]
|
| 1703 |
+
logits = self.lm_head(hidden_states)
|
| 1704 |
+
logits = logits.float()
|
| 1705 |
+
ts_loss = None
|
| 1706 |
+
loss = None
|
| 1707 |
+
if labels is not None:
|
| 1708 |
+
special_ts_token_mask_start = input_ids == self.config.ts_token_start_index
|
| 1709 |
+
num_special_ts_tokens = torch.sum(special_ts_token_mask_start, dim=-1)
|
| 1710 |
+
batch_size = labels.size(0)
|
| 1711 |
+
total_ts_tokens = sum(patch_cnt) if timeseries is not None else 0
|
| 1712 |
+
#logger_zr(f'total_ts_tokens {total_ts_tokens}')
|
| 1713 |
+
if total_ts_tokens > 0:
|
| 1714 |
+
ts_hidden = []
|
| 1715 |
+
current_idx = 0
|
| 1716 |
+
end_pos = torch.argmax((labels != self.config.ignore_index).int(), dim=1)
|
| 1717 |
+
offset = 1
|
| 1718 |
+
for i in range(batch_size):
|
| 1719 |
+
num_ts_in_batch = num_special_ts_tokens[i]
|
| 1720 |
+
start_idx = _train_start_pos[i]
|
| 1721 |
+
# logger_zr(f'check input_end_pos start_idx {start_idx} - {_input_end_pos[i]}')
|
| 1722 |
+
for k in range(num_ts_in_batch):
|
| 1723 |
+
pc = patch_cnt[current_idx]
|
| 1724 |
+
current_idx += 1
|
| 1725 |
+
if pc > 0:
|
| 1726 |
+
ts_hidden.append(hidden_states[i, start_idx:start_idx+pc])
|
| 1727 |
+
start_idx += pc
|
| 1728 |
+
|
| 1729 |
+
# logger_zr(f'check input_end_pos end_idx {start_idx} - {end_pos[i]} - {max_extra_pad}')
|
| 1730 |
+
|
| 1731 |
+
ts_hidden = torch.cat(ts_hidden, dim=0) if ts_hidden else None
|
| 1732 |
+
|
| 1733 |
+
if ts_hidden is not None and original_lengths is not None:
|
| 1734 |
+
reconstructed = self.ts_decoder(ts_hidden, patch_cnt, original_lengths)
|
| 1735 |
+
|
| 1736 |
+
targets = []
|
| 1737 |
+
if target_timeseries is None:
|
| 1738 |
+
# raise ValueError('target_timeseries is None')
|
| 1739 |
+
ts = timeseries.reshape(timeseries.shape[0], -1, self.config.ts['num_features'])
|
| 1740 |
+
else:
|
| 1741 |
+
# change target_timeseries from 'list' to 'tensor'
|
| 1742 |
+
ts = [torch.tensor(t, device=ts_hidden.device, dtype=reconstructed[0].dtype) for t in target_timeseries]
|
| 1743 |
+
if type(ts) == list:
|
| 1744 |
+
tslen=len(ts)
|
| 1745 |
+
else :
|
| 1746 |
+
tslen=ts.size(0)
|
| 1747 |
+
for i in range(tslen):
|
| 1748 |
+
#pre_shape = ts[i].shape[0]
|
| 1749 |
+
if target_timeseries is None:
|
| 1750 |
+
targets.append(ts[i, :reconstructed[i].shape[0], 0])
|
| 1751 |
+
else :
|
| 1752 |
+
targets.append(ts[i][:reconstructed[i].shape[0]])
|
| 1753 |
+
|
| 1754 |
+
reconstructed[i] = reconstructed[i][: ts[i].shape[0]]
|
| 1755 |
+
|
| 1756 |
+
if targets[i].shape != reconstructed[i].shape:
|
| 1757 |
+
raise ValueError(f'{targets[i].shape}\n---\n{len(reconstructed)} * {reconstructed[i].shape} \n ts {ts.shape} \n---\n patch_cnt {patch_cnt} \n ---\n ts_hidden {ts_hidden.shape}')
|
| 1758 |
+
if len(reconstructed) == len(targets) and len(targets) > 0:
|
| 1759 |
+
mse_loss = 0
|
| 1760 |
+
fft_loss = 0
|
| 1761 |
+
count = 0
|
| 1762 |
+
for pred, target in zip(reconstructed, targets):
|
| 1763 |
+
if pred.size(0) == target.size(0):
|
| 1764 |
+
mse_loss += self.ts_loss_func(pred, target)
|
| 1765 |
+
with torch.cuda.amp.autocast(enabled=False):
|
| 1766 |
+
pred_fft = torch.fft.rfft(pred.float(), dim=-1)
|
| 1767 |
+
target_fft = torch.fft.rfft(target.float(), dim=-1)
|
| 1768 |
+
pred_mag = torch.abs(pred_fft)
|
| 1769 |
+
target_mag = torch.abs(target_fft)
|
| 1770 |
+
fft_loss += self.ts_loss_func(pred_mag, target_mag).to(pred.dtype)
|
| 1771 |
+
|
| 1772 |
+
count += 1
|
| 1773 |
+
#_w(f'mse_loss={mse_loss} | fft_loss={fft_loss} | {pred.size(0)} | \n pred={pred} \n target={target}')
|
| 1774 |
+
else :
|
| 1775 |
+
raise ValueError(f'pred.size {pred.size(0)} target.size {target.size(0)}')
|
| 1776 |
+
if count > 0:
|
| 1777 |
+
ts_loss = mse_loss / count # + fft_loss / count
|
| 1778 |
+
else :
|
| 1779 |
+
raise ValueError(f'rec {len(reconstructed)} \n targets {len(targets)} \n{tslen=}')
|
| 1780 |
+
# Shift so that tokens < n predict n
|
| 1781 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 1782 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 1783 |
+
loss_fct = CrossEntropyLoss()
|
| 1784 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
| 1785 |
+
shift_labels = shift_labels.view(-1)
|
| 1786 |
+
# Enable model parallelism
|
| 1787 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 1788 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 1789 |
+
|
| 1790 |
+
total_loss = None
|
| 1791 |
+
if loss is not None or ts_loss is not None:
|
| 1792 |
+
total_loss = 0
|
| 1793 |
+
if loss is not None:
|
| 1794 |
+
total_loss += loss
|
| 1795 |
+
if ts_loss is not None:
|
| 1796 |
+
total_loss += ts_loss
|
| 1797 |
+
|
| 1798 |
+
if not return_dict:
|
| 1799 |
+
output = (logits,) + outputs[1:]
|
| 1800 |
+
return (total_loss,) + output if total_loss is not None else output
|
| 1801 |
+
|
| 1802 |
+
return Qwen2TSCausalLMOutputWithPast(
|
| 1803 |
+
loss=total_loss,
|
| 1804 |
+
labels=labels,
|
| 1805 |
+
logits=logits,
|
| 1806 |
+
past_key_values=outputs.past_key_values,
|
| 1807 |
+
hidden_states=outputs.hidden_states,
|
| 1808 |
+
attentions=outputs.attentions,
|
| 1809 |
+
attention_mask=attention_mask,
|
| 1810 |
+
new_token_positions=new_token_positions
|
| 1811 |
+
)
|
| 1812 |
+
|
| 1813 |
+
def _extract_past_from_model_output(self, outputs: ModelOutput):
|
| 1814 |
+
return "past_key_values", outputs.past_key_values
|
| 1815 |
+
|
| 1816 |
+
def _update_model_kwargs_for_generation(
|
| 1817 |
+
self,
|
| 1818 |
+
outputs: ModelOutput,
|
| 1819 |
+
model_kwargs: Dict[str, Any],
|
| 1820 |
+
is_encoder_decoder: bool = False,
|
| 1821 |
+
num_new_tokens: int = 1,
|
| 1822 |
+
) -> Dict[str, Any]:
|
| 1823 |
+
# update past_key_values keeping its naming used in model code
|
| 1824 |
+
cache_name, cache = self._extract_past_from_model_output(outputs)
|
| 1825 |
+
model_kwargs[cache_name] = cache
|
| 1826 |
+
if getattr(outputs, "state", None) is not None:
|
| 1827 |
+
model_kwargs["state"] = outputs.state
|
| 1828 |
+
|
| 1829 |
+
# update attention_mask
|
| 1830 |
+
if getattr(outputs, "attention_mask", None) is not None:
|
| 1831 |
+
model_kwargs["attention_mask"] = outputs.attention_mask
|
| 1832 |
+
|
| 1833 |
+
# update token_type_ids with last value
|
| 1834 |
+
if "token_type_ids" in model_kwargs:
|
| 1835 |
+
token_type_ids = model_kwargs["token_type_ids"]
|
| 1836 |
+
model_kwargs["token_type_ids"] = torch.cat([token_type_ids, token_type_ids[:, -1].unsqueeze(-1)], dim=-1)
|
| 1837 |
+
|
| 1838 |
+
if not is_encoder_decoder:
|
| 1839 |
+
# update attention mask
|
| 1840 |
+
if "attention_mask" in model_kwargs:
|
| 1841 |
+
attention_mask = model_kwargs["attention_mask"]
|
| 1842 |
+
model_kwargs["attention_mask"] = torch.cat(
|
| 1843 |
+
[attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1
|
| 1844 |
+
)
|
| 1845 |
+
else:
|
| 1846 |
+
# update decoder attention mask
|
| 1847 |
+
if "decoder_attention_mask" in model_kwargs:
|
| 1848 |
+
decoder_attention_mask = model_kwargs["decoder_attention_mask"]
|
| 1849 |
+
model_kwargs["decoder_attention_mask"] = torch.cat(
|
| 1850 |
+
[decoder_attention_mask, decoder_attention_mask.new_ones((decoder_attention_mask.shape[0], 1))],
|
| 1851 |
+
dim=-1,
|
| 1852 |
+
)
|
| 1853 |
+
|
| 1854 |
+
if model_kwargs.get("use_cache", True):
|
| 1855 |
+
model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens
|
| 1856 |
+
else:
|
| 1857 |
+
past_positions = model_kwargs.pop("cache_position")
|
| 1858 |
+
new_positions = torch.arange(
|
| 1859 |
+
past_positions[-1] + 1, past_positions[-1] + num_new_tokens + 1, dtype=past_positions.dtype
|
| 1860 |
+
).to(past_positions.device)
|
| 1861 |
+
model_kwargs["cache_position"] = torch.cat((past_positions, new_positions))
|
| 1862 |
+
return model_kwargs
|
| 1863 |
+
|
| 1864 |
+
def prepare_inputs_for_generation(
|
| 1865 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, timeseries=None, **kwargs
|
| 1866 |
+
):
|
| 1867 |
+
# Omit tokens covered by past_key_values
|
| 1868 |
+
if past_key_values is not None:
|
| 1869 |
+
if isinstance(past_key_values, Cache):
|
| 1870 |
+
cache_length = past_key_values.get_seq_length()
|
| 1871 |
+
past_length = past_key_values.seen_tokens
|
| 1872 |
+
max_cache_length = (
|
| 1873 |
+
past_key_values.get_max_length()
|
| 1874 |
+
if hasattr(past_key_values, "get_max_length")
|
| 1875 |
+
else past_key_values.get_max_cache_shape()
|
| 1876 |
+
)
|
| 1877 |
+
else:
|
| 1878 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
| 1879 |
+
max_cache_length = None
|
| 1880 |
+
|
| 1881 |
+
has_ts = timeseries is not None and len(timeseries) > 0
|
| 1882 |
+
|
| 1883 |
+
if has_ts and kwargs.get("attention_mask") is not None:
|
| 1884 |
+
attention_mask = kwargs["attention_mask"]
|
| 1885 |
+
attention_mask = torch.cat(
|
| 1886 |
+
[attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1
|
| 1887 |
+
)
|
| 1888 |
+
|
| 1889 |
+
# Set attention mask and input_ids
|
| 1890 |
+
if has_ts and past_length > 0:
|
| 1891 |
+
# We have only one token added and timeseries are already inferenced
|
| 1892 |
+
input_ids = input_ids[:, -1:]
|
| 1893 |
+
timeseries = None
|
| 1894 |
+
elif attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
| 1895 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
| 1896 |
+
elif past_length < input_ids.shape[1]:
|
| 1897 |
+
input_ids = input_ids[:, past_length:]
|
| 1898 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
| 1899 |
+
|
| 1900 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
| 1901 |
+
if (
|
| 1902 |
+
max_cache_length is not None
|
| 1903 |
+
and attention_mask is not None
|
| 1904 |
+
and cache_length + input_ids.size(1) > max_cache_length
|
| 1905 |
+
):
|
| 1906 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
| 1907 |
+
|
| 1908 |
+
position_ids = kwargs.get("position_ids", None)
|
| 1909 |
+
if attention_mask is not None and position_ids is None:
|
| 1910 |
+
# create position_ids on the fly for batch generation
|
| 1911 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 1912 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 1913 |
+
if past_key_values:
|
| 1914 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
| 1915 |
+
|
| 1916 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
| 1917 |
+
if inputs_embeds is not None and past_key_values is None:
|
| 1918 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
| 1919 |
+
else:
|
| 1920 |
+
model_inputs = {"input_ids": input_ids}
|
| 1921 |
+
|
| 1922 |
+
model_inputs.update(
|
| 1923 |
+
{
|
| 1924 |
+
"position_ids": position_ids,
|
| 1925 |
+
"past_key_values": past_key_values,
|
| 1926 |
+
"use_cache": kwargs.get("use_cache"),
|
| 1927 |
+
"attention_mask": attention_mask,
|
| 1928 |
+
"timeseries": timeseries
|
| 1929 |
+
}
|
| 1930 |
+
)
|
| 1931 |
+
return model_inputs
|
| 1932 |
+
|
| 1933 |
+
@staticmethod
|
| 1934 |
+
def _reorder_cache(past_key_values, beam_idx):
|
| 1935 |
+
reordered_past = ()
|
| 1936 |
+
for layer_past in past_key_values:
|
| 1937 |
+
reordered_past += (
|
| 1938 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
| 1939 |
+
)
|
| 1940 |
+
return reordered_past
|
| 1941 |
+
|
| 1942 |
+
|
| 1943 |
+
@add_start_docstrings(
|
| 1944 |
+
"""
|
| 1945 |
+
The Qwen2 Model transformer with a sequence classification head on top (linear layer).
|
| 1946 |
+
|
| 1947 |
+
[`Qwen2ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
| 1948 |
+
(e.g. GPT-2) do.
|
| 1949 |
+
|
| 1950 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
| 1951 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
| 1952 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
| 1953 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
| 1954 |
+
each row of the batch).
|
| 1955 |
+
""",
|
| 1956 |
+
QWEN2_START_DOCSTRING,
|
| 1957 |
+
)
|
| 1958 |
+
class Qwen2ForSequenceClassification(Qwen2PreTrainedModel):
|
| 1959 |
+
def __init__(self, config):
|
| 1960 |
+
super().__init__(config)
|
| 1961 |
+
self.num_labels = config.num_labels
|
| 1962 |
+
self.model = Qwen2Model(config)
|
| 1963 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
| 1964 |
+
|
| 1965 |
+
# Initialize weights and apply final processing
|
| 1966 |
+
self.post_init()
|
| 1967 |
+
|
| 1968 |
+
def get_input_embeddings(self):
|
| 1969 |
+
return self.model.embed_tokens
|
| 1970 |
+
|
| 1971 |
+
def set_input_embeddings(self, value):
|
| 1972 |
+
self.model.embed_tokens = value
|
| 1973 |
+
|
| 1974 |
+
@add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
|
| 1975 |
+
def forward(
|
| 1976 |
+
self,
|
| 1977 |
+
input_ids: torch.LongTensor = None,
|
| 1978 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1979 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1980 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1981 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1982 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1983 |
+
use_cache: Optional[bool] = None,
|
| 1984 |
+
output_attentions: Optional[bool] = None,
|
| 1985 |
+
output_hidden_states: Optional[bool] = None,
|
| 1986 |
+
return_dict: Optional[bool] = None,
|
| 1987 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
| 1988 |
+
r"""
|
| 1989 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1990 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1991 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1992 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1993 |
+
"""
|
| 1994 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1995 |
+
|
| 1996 |
+
transformer_outputs = self.model(
|
| 1997 |
+
input_ids,
|
| 1998 |
+
attention_mask=attention_mask,
|
| 1999 |
+
position_ids=position_ids,
|
| 2000 |
+
past_key_values=past_key_values,
|
| 2001 |
+
inputs_embeds=inputs_embeds,
|
| 2002 |
+
use_cache=use_cache,
|
| 2003 |
+
output_attentions=output_attentions,
|
| 2004 |
+
output_hidden_states=output_hidden_states,
|
| 2005 |
+
return_dict=return_dict,
|
| 2006 |
+
)
|
| 2007 |
+
hidden_states = transformer_outputs[0]
|
| 2008 |
+
logits = self.score(hidden_states)
|
| 2009 |
+
|
| 2010 |
+
if input_ids is not None:
|
| 2011 |
+
batch_size = input_ids.shape[0]
|
| 2012 |
+
else:
|
| 2013 |
+
batch_size = inputs_embeds.shape[0]
|
| 2014 |
+
|
| 2015 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
| 2016 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
| 2017 |
+
if self.config.pad_token_id is None:
|
| 2018 |
+
sequence_lengths = -1
|
| 2019 |
+
else:
|
| 2020 |
+
if input_ids is not None:
|
| 2021 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
| 2022 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
| 2023 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
| 2024 |
+
sequence_lengths = sequence_lengths.to(logits.device)
|
| 2025 |
+
else:
|
| 2026 |
+
sequence_lengths = -1
|
| 2027 |
+
|
| 2028 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
| 2029 |
+
|
| 2030 |
+
loss = None
|
| 2031 |
+
if labels is not None:
|
| 2032 |
+
labels = labels.to(logits.device)
|
| 2033 |
+
if self.config.problem_type is None:
|
| 2034 |
+
if self.num_labels == 1:
|
| 2035 |
+
self.config.problem_type = "regression"
|
| 2036 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 2037 |
+
self.config.problem_type = "single_label_classification"
|
| 2038 |
+
else:
|
| 2039 |
+
self.config.problem_type = "multi_label_classification"
|
| 2040 |
+
|
| 2041 |
+
if self.config.problem_type == "regression":
|
| 2042 |
+
loss_fct = MSELoss()
|
| 2043 |
+
if self.num_labels == 1:
|
| 2044 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
| 2045 |
+
else:
|
| 2046 |
+
loss = loss_fct(pooled_logits, labels)
|
| 2047 |
+
elif self.config.problem_type == "single_label_classification":
|
| 2048 |
+
loss_fct = CrossEntropyLoss()
|
| 2049 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
| 2050 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 2051 |
+
loss_fct = BCEWithLogitsLoss()
|
| 2052 |
+
loss = loss_fct(pooled_logits, labels)
|
| 2053 |
+
if not return_dict:
|
| 2054 |
+
output = (pooled_logits,) + transformer_outputs[1:]
|
| 2055 |
+
return ((loss,) + output) if loss is not None else output
|
| 2056 |
+
|
| 2057 |
+
return SequenceClassifierOutputWithPast(
|
| 2058 |
+
loss=loss,
|
| 2059 |
+
logits=pooled_logits,
|
| 2060 |
+
past_key_values=transformer_outputs.past_key_values,
|
| 2061 |
+
hidden_states=transformer_outputs.hidden_states,
|
| 2062 |
+
attentions=transformer_outputs.attentions,
|
| 2063 |
+
)
|
processing_qwen2_ts.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Tsinghua University and ByteDance.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the MIT License (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# https://opensource.org/license/mit
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
from typing import List, Union, Tuple, Optional
|
| 18 |
+
import torch
|
| 19 |
+
|
| 20 |
+
from transformers.feature_extraction_utils import BatchFeature
|
| 21 |
+
from transformers.processing_utils import ProcessorMixin
|
| 22 |
+
from transformers.tokenization_utils_base import PaddingStrategy
|
| 23 |
+
|
| 24 |
+
def sp_encoding(timeseries: np.ndarray, eots_token: bool = True) -> Tuple[np.ndarray, str, dict]:
|
| 25 |
+
"""
|
| 26 |
+
Encodes a time series with scalar normalization.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
timeseries (np.ndarray): The raw time series data (1D or 2D).
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
result_timeseries (np.ndarray): The encoded time series, shape [seq_len, 1].
|
| 33 |
+
prompt (str): The placeholder string with offset and scaling info.
|
| 34 |
+
metadata (dict): Metadata containing the offset and scaling factor.
|
| 35 |
+
"""
|
| 36 |
+
timeseries = np.array(timeseries)
|
| 37 |
+
mean = np.mean(timeseries)
|
| 38 |
+
scaled_timeseries = timeseries - mean
|
| 39 |
+
scale_factor = 1.0
|
| 40 |
+
if np.any(np.abs(scaled_timeseries) >= 3.0):
|
| 41 |
+
scale_factor = np.max(np.abs(scaled_timeseries)) / 3.0
|
| 42 |
+
scaled_timeseries /= scale_factor
|
| 43 |
+
|
| 44 |
+
prompt = f"[offset={-mean:.4f}|scaling={scale_factor:.4f}|length={len(timeseries)}|max={max(timeseries):.4f}|min={min(timeseries):.4f}|left={timeseries[0]:.4f}|right={timeseries[-1]:.4f}]<ts>"
|
| 45 |
+
if eots_token:
|
| 46 |
+
prompt += '<ts/>'
|
| 47 |
+
|
| 48 |
+
result_timeseries = np.stack([scaled_timeseries, np.ones_like(scaled_timeseries)], axis=-1).reshape(-1, 1)
|
| 49 |
+
|
| 50 |
+
return result_timeseries, prompt, {"offset": float(-mean), "scale_factor": float(scale_factor)}
|
| 51 |
+
|
| 52 |
+
class Qwen2TSProcessor(ProcessorMixin):
|
| 53 |
+
"""
|
| 54 |
+
A processor for ChatTS that integrates text prompt processing and time series encoding.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
attributes = ["tokenizer"]
|
| 58 |
+
feature_extractor_class = None # You can add a feature extractor if needed
|
| 59 |
+
tokenizer_class = "AutoTokenizer"
|
| 60 |
+
|
| 61 |
+
def __init__(self, tokenizer=None, chat_template=None, **kwargs):
|
| 62 |
+
"""
|
| 63 |
+
Args:
|
| 64 |
+
tokenizer: An optional tokenizer to process text prompts.
|
| 65 |
+
"""
|
| 66 |
+
if chat_template is None and tokenizer is not None and tokenizer.chat_template is not None:
|
| 67 |
+
chat_template = tokenizer.chat_template
|
| 68 |
+
self.chat_template = chat_template
|
| 69 |
+
|
| 70 |
+
super().__init__(tokenizer=tokenizer, chat_template=chat_template, **kwargs)
|
| 71 |
+
|
| 72 |
+
def __call__(
|
| 73 |
+
self,
|
| 74 |
+
text: Union[str, List[str]],
|
| 75 |
+
timeseries: Optional[List[List[np.ndarray]]] = None,
|
| 76 |
+
padding: Union[bool, str, PaddingStrategy] = False,
|
| 77 |
+
padding_side: str = 'left',
|
| 78 |
+
vllm_flag: bool = False,
|
| 79 |
+
tokenize: bool = True,
|
| 80 |
+
**kwargs,
|
| 81 |
+
) -> BatchFeature:
|
| 82 |
+
"""
|
| 83 |
+
Encodes a prompt and its associated time series.
|
| 84 |
+
|
| 85 |
+
Args:
|
| 86 |
+
prompt (List[str]): The input prompt containing <ts><ts/> placeholders.
|
| 87 |
+
timeseries (List[np.ndarray]): A list of time series matched to placeholders in the prompt.
|
| 88 |
+
padding (bool or str or PaddingStrategy, optional): Passed to the tokenizer for text padding.
|
| 89 |
+
return_tensors (str, optional): "pt" to return PyTorch tensors; None to return NumPy arrays.
|
| 90 |
+
**kwargs: Additional tokenizer parameters.
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
BatchFeature: Contains processed prompt, encoded time series, and tokenizer outputs.
|
| 94 |
+
"""
|
| 95 |
+
if type(text) == str:
|
| 96 |
+
text = [text]
|
| 97 |
+
if timeseries is None:
|
| 98 |
+
timeseries = []
|
| 99 |
+
|
| 100 |
+
reconstructed_prompts = []
|
| 101 |
+
concatenated_ts = None
|
| 102 |
+
ts_tokens = []
|
| 103 |
+
|
| 104 |
+
if vllm_flag:
|
| 105 |
+
# All prompt modifications have to be done inside of the vLLM
|
| 106 |
+
# to work correctly with its caching mechanism.
|
| 107 |
+
reconstructed_prompts = text
|
| 108 |
+
|
| 109 |
+
# Process timeseries data
|
| 110 |
+
encoded_ts_arrays = []
|
| 111 |
+
for ts in timeseries:
|
| 112 |
+
# Get the normalized data and prompt text
|
| 113 |
+
encoded_ts, ts_prompt, _ = sp_encoding(ts, eots_token=False)
|
| 114 |
+
# Tokenize the ts_prompt and add to the tokens list
|
| 115 |
+
if self.tokenizer is not None:
|
| 116 |
+
tokens = self.tokenizer.encode(ts_prompt, add_special_tokens=False)
|
| 117 |
+
ts_tokens.append(tokens)
|
| 118 |
+
encoded_ts_arrays.append(encoded_ts[None, ...])
|
| 119 |
+
else:
|
| 120 |
+
encoded_ts_arrays = []
|
| 121 |
+
total_ts_cnt = 0
|
| 122 |
+
for idx, prompt in enumerate(text):
|
| 123 |
+
# Split prompt by <ts><ts/> placeholders
|
| 124 |
+
last_ts_cnt = total_ts_cnt
|
| 125 |
+
prompt_segments = prompt.split("<ts><ts/>")
|
| 126 |
+
total_ts_cnt = total_ts_cnt + len(prompt_segments) - 1
|
| 127 |
+
|
| 128 |
+
# Encode each time series and rebuild the prompt
|
| 129 |
+
reconstructed_prompt = prompt_segments[0]
|
| 130 |
+
|
| 131 |
+
for i, ts in enumerate(timeseries[last_ts_cnt:total_ts_cnt]):
|
| 132 |
+
encoded_ts, ts_prompt, _ = sp_encoding(ts, eots_token=not vllm_flag)
|
| 133 |
+
reconstructed_prompt += ts_prompt + prompt_segments[i + 1]
|
| 134 |
+
# Ensure time series shape [1, seq_len, feature_dim] for batch concatenation
|
| 135 |
+
encoded_ts_arrays.append(encoded_ts[None, ...])
|
| 136 |
+
|
| 137 |
+
reconstructed_prompts.append(reconstructed_prompt)
|
| 138 |
+
|
| 139 |
+
if len(timeseries) != len(encoded_ts_arrays):
|
| 140 |
+
raise ValueError(
|
| 141 |
+
f"Mismatch between <ts><ts/> placeholders ({total_ts_cnt}) "
|
| 142 |
+
f"and time series ({len(encoded_ts_arrays)})."
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
if len(encoded_ts_arrays) > 0:
|
| 146 |
+
# Pad time series to the same length
|
| 147 |
+
max_length = max(ts.shape[1] for ts in encoded_ts_arrays)
|
| 148 |
+
padded_ts_arrays = [
|
| 149 |
+
np.pad(ts, ((0, 0), (0, max_length - ts.shape[1]), (0, 0)), mode="constant", constant_values=0.0)
|
| 150 |
+
for ts in encoded_ts_arrays
|
| 151 |
+
]
|
| 152 |
+
concatenated_ts = np.concatenate(padded_ts_arrays, axis=0) # Shape: [batch_size, max_length, feature_dim]
|
| 153 |
+
|
| 154 |
+
# Convert to torch
|
| 155 |
+
concatenated_ts = torch.from_numpy(concatenated_ts).half()
|
| 156 |
+
|
| 157 |
+
# Tokenize the processed prompt
|
| 158 |
+
tokenizer_outputs = {}
|
| 159 |
+
if tokenize and self.tokenizer is not None:
|
| 160 |
+
tokenizer_outputs = self.tokenizer(reconstructed_prompts, padding=padding, padding_side=padding_side, **kwargs)
|
| 161 |
+
else:
|
| 162 |
+
tokenizer_outputs = {"text": reconstructed_prompts}
|
| 163 |
+
|
| 164 |
+
# Create the final output
|
| 165 |
+
outputs = tokenizer_outputs
|
| 166 |
+
if vllm_flag:
|
| 167 |
+
outputs["timeseries"] = zip(ts_tokens, encoded_ts_arrays)
|
| 168 |
+
elif concatenated_ts is not None:
|
| 169 |
+
outputs["timeseries"] = concatenated_ts
|
| 170 |
+
|
| 171 |
+
return BatchFeature(data=outputs)
|
| 172 |
+
|
| 173 |
+
def encode_timeseries(
|
| 174 |
+
self,
|
| 175 |
+
timeseries: Optional[List[List[np.ndarray]]] = None,
|
| 176 |
+
) -> np.ndarray:
|
| 177 |
+
if timeseries is None:
|
| 178 |
+
timeseries = []
|
| 179 |
+
|
| 180 |
+
concatenated_ts = None
|
| 181 |
+
encoded_ts_arrays = []
|
| 182 |
+
|
| 183 |
+
for i, ts in enumerate(timeseries):
|
| 184 |
+
encoded_ts, _, _ = sp_encoding(ts)
|
| 185 |
+
# Ensure time series shape [1, seq_len, feature_dim] for batch concatenation
|
| 186 |
+
encoded_ts_arrays.append(encoded_ts[None, ...])
|
| 187 |
+
|
| 188 |
+
if len(encoded_ts_arrays) > 0:
|
| 189 |
+
# Pad time series to the same length
|
| 190 |
+
max_length = max(ts.shape[1] for ts in encoded_ts_arrays)
|
| 191 |
+
padded_ts_arrays = [
|
| 192 |
+
np.pad(ts, ((0, 0), (0, max_length - ts.shape[1]), (0, 0)), mode="constant", constant_values=0.0)
|
| 193 |
+
for ts in encoded_ts_arrays
|
| 194 |
+
]
|
| 195 |
+
concatenated_ts = np.concatenate(padded_ts_arrays, axis=0) # Shape: [batch_size, max_length, feature_dim]
|
| 196 |
+
|
| 197 |
+
# Convert to torch
|
| 198 |
+
concatenated_ts = torch.from_numpy(concatenated_ts).half()
|
| 199 |
+
|
| 200 |
+
return concatenated_ts
|
| 201 |
+
|
| 202 |
+
@property
|
| 203 |
+
def model_input_names(self):
|
| 204 |
+
"""
|
| 205 |
+
Define the input names expected by the model.
|
| 206 |
+
"""
|
| 207 |
+
tokenizer_input_names = []
|
| 208 |
+
if self.tokenizer and hasattr(self.tokenizer, "model_input_names"):
|
| 209 |
+
tokenizer_input_names = self.tokenizer.model_input_names
|
| 210 |
+
return list(dict.fromkeys(["processed_prompt", "time_series"] + tokenizer_input_names))
|
| 211 |
+
|
| 212 |
+
def batch_decode(self, *args, **kwargs):
|
| 213 |
+
"""
|
| 214 |
+
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
|
| 215 |
+
refer to the docstring of this method for more information.
|
| 216 |
+
"""
|
| 217 |
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
| 218 |
+
|
| 219 |
+
def decode(self, *args, **kwargs):
|
| 220 |
+
"""
|
| 221 |
+
This method forwards all its arguments to Qwen2TokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
|
| 222 |
+
the docstring of this method for more information.
|
| 223 |
+
"""
|
| 224 |
+
return self.tokenizer.decode(*args, **kwargs)
|
processor_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoProcessor": "processing_qwen2_ts.Qwen2TSProcessor"
|
| 4 |
+
},
|
| 5 |
+
"processor_class": "Qwen2TSProcessor"
|
| 6 |
+
}
|
pytorch_model-00001-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9cad179e20f571f2a04ef8e992886f19d0482cd2652bc9765ef60305bddd9a2a
|
| 3 |
+
size 4986229446
|
pytorch_model-00002-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f16d006b0f93dd5d68dff71e8b2fa9951e4838424683c92c183258ddc7c11690
|
| 3 |
+
size 4954871762
|
pytorch_model-00003-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c6e7fb119e72bb278b667c5995a38805a6b0e9ddb2ba65ddb054d95f6b2b72ee
|
| 3 |
+
size 4954871762
|
pytorch_model-00004-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e9a506dfd831a55640b48b411e0a41085cc15639516c9e7a4712884c33f42e8d
|
| 3 |
+
size 4954871762
|
pytorch_model-00005-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0884f2746c627f2edc359dcf8dd1f229987cbed51323442a4adeca76e2bc95d2
|
| 3 |
+
size 4954871762
|
pytorch_model-00006-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84ef59b57440318a3697016af6abb17243989fcd10d5e0a64e4bbc90d748815a
|
| 3 |
+
size 4999199338
|
pytorch_model-00007-of-00007.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cfba4a75228aed0337038b99d10e21e82e22c3e823ae77f636e2f5d60321c27e
|
| 3 |
+
size 157402492
|
pytorch_model.bin.index.json
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 29962113072
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "pytorch_model-00006-of-00007.bin",
|
| 7 |
+
"model.embed_tokens.weight": "pytorch_model-00001-of-00007.bin",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 10 |
+
"model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 11 |
+
"model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 12 |
+
"model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 13 |
+
"model.layers.0.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 14 |
+
"model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 15 |
+
"model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 16 |
+
"model.layers.0.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 17 |
+
"model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 18 |
+
"model.layers.0.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 19 |
+
"model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 20 |
+
"model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 21 |
+
"model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 22 |
+
"model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 23 |
+
"model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 24 |
+
"model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 25 |
+
"model.layers.1.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 26 |
+
"model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 27 |
+
"model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 28 |
+
"model.layers.1.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 29 |
+
"model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 30 |
+
"model.layers.1.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 31 |
+
"model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 32 |
+
"model.layers.10.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 33 |
+
"model.layers.10.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 34 |
+
"model.layers.10.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 35 |
+
"model.layers.10.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 36 |
+
"model.layers.10.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 37 |
+
"model.layers.10.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 38 |
+
"model.layers.10.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 39 |
+
"model.layers.10.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 40 |
+
"model.layers.10.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 41 |
+
"model.layers.10.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 42 |
+
"model.layers.10.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 43 |
+
"model.layers.10.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 44 |
+
"model.layers.11.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 45 |
+
"model.layers.11.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 46 |
+
"model.layers.11.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 47 |
+
"model.layers.11.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 48 |
+
"model.layers.11.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 49 |
+
"model.layers.11.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 50 |
+
"model.layers.11.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 51 |
+
"model.layers.11.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 52 |
+
"model.layers.11.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 53 |
+
"model.layers.11.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 54 |
+
"model.layers.11.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 55 |
+
"model.layers.11.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 56 |
+
"model.layers.12.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 57 |
+
"model.layers.12.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 58 |
+
"model.layers.12.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 59 |
+
"model.layers.12.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 60 |
+
"model.layers.12.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 61 |
+
"model.layers.12.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 62 |
+
"model.layers.12.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 63 |
+
"model.layers.12.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 64 |
+
"model.layers.12.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 65 |
+
"model.layers.12.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 66 |
+
"model.layers.12.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 67 |
+
"model.layers.12.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 68 |
+
"model.layers.13.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 69 |
+
"model.layers.13.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 70 |
+
"model.layers.13.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 71 |
+
"model.layers.13.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 72 |
+
"model.layers.13.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 73 |
+
"model.layers.13.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 74 |
+
"model.layers.13.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 75 |
+
"model.layers.13.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 76 |
+
"model.layers.13.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 77 |
+
"model.layers.13.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 78 |
+
"model.layers.13.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 79 |
+
"model.layers.13.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 80 |
+
"model.layers.14.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 81 |
+
"model.layers.14.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 82 |
+
"model.layers.14.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 83 |
+
"model.layers.14.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 84 |
+
"model.layers.14.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 85 |
+
"model.layers.14.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 86 |
+
"model.layers.14.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 87 |
+
"model.layers.14.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 88 |
+
"model.layers.14.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 89 |
+
"model.layers.14.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 90 |
+
"model.layers.14.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 91 |
+
"model.layers.14.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 92 |
+
"model.layers.15.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 93 |
+
"model.layers.15.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 94 |
+
"model.layers.15.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 95 |
+
"model.layers.15.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 96 |
+
"model.layers.15.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 97 |
+
"model.layers.15.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 98 |
+
"model.layers.15.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 99 |
+
"model.layers.15.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 100 |
+
"model.layers.15.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 101 |
+
"model.layers.15.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 102 |
+
"model.layers.15.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 103 |
+
"model.layers.15.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 104 |
+
"model.layers.16.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 105 |
+
"model.layers.16.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 106 |
+
"model.layers.16.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 107 |
+
"model.layers.16.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 108 |
+
"model.layers.16.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 109 |
+
"model.layers.16.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 110 |
+
"model.layers.16.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 111 |
+
"model.layers.16.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 112 |
+
"model.layers.16.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 113 |
+
"model.layers.16.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 114 |
+
"model.layers.16.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 115 |
+
"model.layers.16.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 116 |
+
"model.layers.17.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 117 |
+
"model.layers.17.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 118 |
+
"model.layers.17.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 119 |
+
"model.layers.17.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 120 |
+
"model.layers.17.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 121 |
+
"model.layers.17.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 122 |
+
"model.layers.17.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 123 |
+
"model.layers.17.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 124 |
+
"model.layers.17.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 125 |
+
"model.layers.17.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 126 |
+
"model.layers.17.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 127 |
+
"model.layers.17.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 128 |
+
"model.layers.18.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 129 |
+
"model.layers.18.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 130 |
+
"model.layers.18.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 131 |
+
"model.layers.18.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 132 |
+
"model.layers.18.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 133 |
+
"model.layers.18.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 134 |
+
"model.layers.18.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 135 |
+
"model.layers.18.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 136 |
+
"model.layers.18.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 137 |
+
"model.layers.18.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 138 |
+
"model.layers.18.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 139 |
+
"model.layers.18.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 140 |
+
"model.layers.19.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 141 |
+
"model.layers.19.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 142 |
+
"model.layers.19.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 143 |
+
"model.layers.19.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 144 |
+
"model.layers.19.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 145 |
+
"model.layers.19.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 146 |
+
"model.layers.19.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 147 |
+
"model.layers.19.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 148 |
+
"model.layers.19.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 149 |
+
"model.layers.19.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 150 |
+
"model.layers.19.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 151 |
+
"model.layers.19.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 152 |
+
"model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 153 |
+
"model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 154 |
+
"model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 155 |
+
"model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 156 |
+
"model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 157 |
+
"model.layers.2.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 158 |
+
"model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 159 |
+
"model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 160 |
+
"model.layers.2.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 161 |
+
"model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 162 |
+
"model.layers.2.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 163 |
+
"model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 164 |
+
"model.layers.20.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 165 |
+
"model.layers.20.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 166 |
+
"model.layers.20.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 167 |
+
"model.layers.20.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 168 |
+
"model.layers.20.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 169 |
+
"model.layers.20.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 170 |
+
"model.layers.20.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 171 |
+
"model.layers.20.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 172 |
+
"model.layers.20.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 173 |
+
"model.layers.20.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 174 |
+
"model.layers.20.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 175 |
+
"model.layers.20.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 176 |
+
"model.layers.21.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 177 |
+
"model.layers.21.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 178 |
+
"model.layers.21.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 179 |
+
"model.layers.21.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 180 |
+
"model.layers.21.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 181 |
+
"model.layers.21.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 182 |
+
"model.layers.21.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 183 |
+
"model.layers.21.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 184 |
+
"model.layers.21.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 185 |
+
"model.layers.21.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 186 |
+
"model.layers.21.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 187 |
+
"model.layers.21.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 188 |
+
"model.layers.22.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 189 |
+
"model.layers.22.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 190 |
+
"model.layers.22.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 191 |
+
"model.layers.22.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 192 |
+
"model.layers.22.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 193 |
+
"model.layers.22.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 194 |
+
"model.layers.22.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 195 |
+
"model.layers.22.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 196 |
+
"model.layers.22.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 197 |
+
"model.layers.22.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 198 |
+
"model.layers.22.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 199 |
+
"model.layers.22.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 200 |
+
"model.layers.23.input_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 201 |
+
"model.layers.23.mlp.down_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 202 |
+
"model.layers.23.mlp.gate_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 203 |
+
"model.layers.23.mlp.up_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 204 |
+
"model.layers.23.post_attention_layernorm.weight": "pytorch_model-00003-of-00007.bin",
|
| 205 |
+
"model.layers.23.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 206 |
+
"model.layers.23.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 207 |
+
"model.layers.23.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 208 |
+
"model.layers.23.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 209 |
+
"model.layers.23.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 210 |
+
"model.layers.23.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 211 |
+
"model.layers.23.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 212 |
+
"model.layers.24.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 213 |
+
"model.layers.24.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 214 |
+
"model.layers.24.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 215 |
+
"model.layers.24.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 216 |
+
"model.layers.24.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 217 |
+
"model.layers.24.self_attn.k_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 218 |
+
"model.layers.24.self_attn.k_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 219 |
+
"model.layers.24.self_attn.o_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 220 |
+
"model.layers.24.self_attn.q_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 221 |
+
"model.layers.24.self_attn.q_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 222 |
+
"model.layers.24.self_attn.v_proj.bias": "pytorch_model-00003-of-00007.bin",
|
| 223 |
+
"model.layers.24.self_attn.v_proj.weight": "pytorch_model-00003-of-00007.bin",
|
| 224 |
+
"model.layers.25.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 225 |
+
"model.layers.25.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 226 |
+
"model.layers.25.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 227 |
+
"model.layers.25.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 228 |
+
"model.layers.25.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 229 |
+
"model.layers.25.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 230 |
+
"model.layers.25.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 231 |
+
"model.layers.25.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 232 |
+
"model.layers.25.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 233 |
+
"model.layers.25.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 234 |
+
"model.layers.25.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 235 |
+
"model.layers.25.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 236 |
+
"model.layers.26.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 237 |
+
"model.layers.26.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 238 |
+
"model.layers.26.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 239 |
+
"model.layers.26.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 240 |
+
"model.layers.26.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 241 |
+
"model.layers.26.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 242 |
+
"model.layers.26.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 243 |
+
"model.layers.26.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 244 |
+
"model.layers.26.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 245 |
+
"model.layers.26.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 246 |
+
"model.layers.26.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 247 |
+
"model.layers.26.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 248 |
+
"model.layers.27.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 249 |
+
"model.layers.27.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 250 |
+
"model.layers.27.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 251 |
+
"model.layers.27.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 252 |
+
"model.layers.27.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 253 |
+
"model.layers.27.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 254 |
+
"model.layers.27.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 255 |
+
"model.layers.27.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 256 |
+
"model.layers.27.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 257 |
+
"model.layers.27.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 258 |
+
"model.layers.27.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 259 |
+
"model.layers.27.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 260 |
+
"model.layers.28.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 261 |
+
"model.layers.28.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 262 |
+
"model.layers.28.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 263 |
+
"model.layers.28.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 264 |
+
"model.layers.28.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 265 |
+
"model.layers.28.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 266 |
+
"model.layers.28.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 267 |
+
"model.layers.28.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 268 |
+
"model.layers.28.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 269 |
+
"model.layers.28.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 270 |
+
"model.layers.28.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 271 |
+
"model.layers.28.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 272 |
+
"model.layers.29.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 273 |
+
"model.layers.29.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 274 |
+
"model.layers.29.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 275 |
+
"model.layers.29.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 276 |
+
"model.layers.29.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 277 |
+
"model.layers.29.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 278 |
+
"model.layers.29.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 279 |
+
"model.layers.29.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 280 |
+
"model.layers.29.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 281 |
+
"model.layers.29.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 282 |
+
"model.layers.29.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 283 |
+
"model.layers.29.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 284 |
+
"model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 285 |
+
"model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 286 |
+
"model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 287 |
+
"model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 288 |
+
"model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 289 |
+
"model.layers.3.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 290 |
+
"model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 291 |
+
"model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 292 |
+
"model.layers.3.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 293 |
+
"model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 294 |
+
"model.layers.3.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 295 |
+
"model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 296 |
+
"model.layers.30.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 297 |
+
"model.layers.30.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 298 |
+
"model.layers.30.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 299 |
+
"model.layers.30.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 300 |
+
"model.layers.30.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 301 |
+
"model.layers.30.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 302 |
+
"model.layers.30.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 303 |
+
"model.layers.30.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 304 |
+
"model.layers.30.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 305 |
+
"model.layers.30.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 306 |
+
"model.layers.30.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 307 |
+
"model.layers.30.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 308 |
+
"model.layers.31.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 309 |
+
"model.layers.31.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 310 |
+
"model.layers.31.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 311 |
+
"model.layers.31.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 312 |
+
"model.layers.31.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 313 |
+
"model.layers.31.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 314 |
+
"model.layers.31.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 315 |
+
"model.layers.31.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 316 |
+
"model.layers.31.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 317 |
+
"model.layers.31.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 318 |
+
"model.layers.31.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 319 |
+
"model.layers.31.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 320 |
+
"model.layers.32.input_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 321 |
+
"model.layers.32.mlp.down_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 322 |
+
"model.layers.32.mlp.gate_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 323 |
+
"model.layers.32.mlp.up_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 324 |
+
"model.layers.32.post_attention_layernorm.weight": "pytorch_model-00004-of-00007.bin",
|
| 325 |
+
"model.layers.32.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 326 |
+
"model.layers.32.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 327 |
+
"model.layers.32.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 328 |
+
"model.layers.32.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 329 |
+
"model.layers.32.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 330 |
+
"model.layers.32.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 331 |
+
"model.layers.32.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 332 |
+
"model.layers.33.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 333 |
+
"model.layers.33.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 334 |
+
"model.layers.33.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 335 |
+
"model.layers.33.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 336 |
+
"model.layers.33.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 337 |
+
"model.layers.33.self_attn.k_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 338 |
+
"model.layers.33.self_attn.k_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 339 |
+
"model.layers.33.self_attn.o_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 340 |
+
"model.layers.33.self_attn.q_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 341 |
+
"model.layers.33.self_attn.q_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 342 |
+
"model.layers.33.self_attn.v_proj.bias": "pytorch_model-00004-of-00007.bin",
|
| 343 |
+
"model.layers.33.self_attn.v_proj.weight": "pytorch_model-00004-of-00007.bin",
|
| 344 |
+
"model.layers.34.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 345 |
+
"model.layers.34.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 346 |
+
"model.layers.34.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 347 |
+
"model.layers.34.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 348 |
+
"model.layers.34.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 349 |
+
"model.layers.34.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 350 |
+
"model.layers.34.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 351 |
+
"model.layers.34.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 352 |
+
"model.layers.34.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 353 |
+
"model.layers.34.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 354 |
+
"model.layers.34.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 355 |
+
"model.layers.34.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 356 |
+
"model.layers.35.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 357 |
+
"model.layers.35.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 358 |
+
"model.layers.35.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 359 |
+
"model.layers.35.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 360 |
+
"model.layers.35.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 361 |
+
"model.layers.35.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 362 |
+
"model.layers.35.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 363 |
+
"model.layers.35.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 364 |
+
"model.layers.35.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 365 |
+
"model.layers.35.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 366 |
+
"model.layers.35.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 367 |
+
"model.layers.35.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 368 |
+
"model.layers.36.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 369 |
+
"model.layers.36.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 370 |
+
"model.layers.36.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 371 |
+
"model.layers.36.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 372 |
+
"model.layers.36.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 373 |
+
"model.layers.36.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 374 |
+
"model.layers.36.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 375 |
+
"model.layers.36.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 376 |
+
"model.layers.36.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 377 |
+
"model.layers.36.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 378 |
+
"model.layers.36.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 379 |
+
"model.layers.36.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 380 |
+
"model.layers.37.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 381 |
+
"model.layers.37.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 382 |
+
"model.layers.37.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 383 |
+
"model.layers.37.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 384 |
+
"model.layers.37.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 385 |
+
"model.layers.37.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 386 |
+
"model.layers.37.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 387 |
+
"model.layers.37.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 388 |
+
"model.layers.37.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 389 |
+
"model.layers.37.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 390 |
+
"model.layers.37.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 391 |
+
"model.layers.37.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 392 |
+
"model.layers.38.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 393 |
+
"model.layers.38.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 394 |
+
"model.layers.38.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 395 |
+
"model.layers.38.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 396 |
+
"model.layers.38.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 397 |
+
"model.layers.38.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 398 |
+
"model.layers.38.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 399 |
+
"model.layers.38.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 400 |
+
"model.layers.38.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 401 |
+
"model.layers.38.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 402 |
+
"model.layers.38.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 403 |
+
"model.layers.38.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 404 |
+
"model.layers.39.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 405 |
+
"model.layers.39.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 406 |
+
"model.layers.39.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 407 |
+
"model.layers.39.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 408 |
+
"model.layers.39.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 409 |
+
"model.layers.39.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 410 |
+
"model.layers.39.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 411 |
+
"model.layers.39.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 412 |
+
"model.layers.39.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 413 |
+
"model.layers.39.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 414 |
+
"model.layers.39.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 415 |
+
"model.layers.39.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 416 |
+
"model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 417 |
+
"model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 418 |
+
"model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 419 |
+
"model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 420 |
+
"model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 421 |
+
"model.layers.4.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 422 |
+
"model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 423 |
+
"model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 424 |
+
"model.layers.4.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 425 |
+
"model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 426 |
+
"model.layers.4.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 427 |
+
"model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 428 |
+
"model.layers.40.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 429 |
+
"model.layers.40.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 430 |
+
"model.layers.40.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 431 |
+
"model.layers.40.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 432 |
+
"model.layers.40.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 433 |
+
"model.layers.40.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 434 |
+
"model.layers.40.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 435 |
+
"model.layers.40.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 436 |
+
"model.layers.40.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 437 |
+
"model.layers.40.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 438 |
+
"model.layers.40.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 439 |
+
"model.layers.40.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 440 |
+
"model.layers.41.input_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 441 |
+
"model.layers.41.mlp.down_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 442 |
+
"model.layers.41.mlp.gate_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 443 |
+
"model.layers.41.mlp.up_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 444 |
+
"model.layers.41.post_attention_layernorm.weight": "pytorch_model-00005-of-00007.bin",
|
| 445 |
+
"model.layers.41.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 446 |
+
"model.layers.41.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 447 |
+
"model.layers.41.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 448 |
+
"model.layers.41.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 449 |
+
"model.layers.41.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 450 |
+
"model.layers.41.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 451 |
+
"model.layers.41.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 452 |
+
"model.layers.42.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 453 |
+
"model.layers.42.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 454 |
+
"model.layers.42.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 455 |
+
"model.layers.42.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 456 |
+
"model.layers.42.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 457 |
+
"model.layers.42.self_attn.k_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 458 |
+
"model.layers.42.self_attn.k_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 459 |
+
"model.layers.42.self_attn.o_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 460 |
+
"model.layers.42.self_attn.q_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 461 |
+
"model.layers.42.self_attn.q_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 462 |
+
"model.layers.42.self_attn.v_proj.bias": "pytorch_model-00005-of-00007.bin",
|
| 463 |
+
"model.layers.42.self_attn.v_proj.weight": "pytorch_model-00005-of-00007.bin",
|
| 464 |
+
"model.layers.43.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 465 |
+
"model.layers.43.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 466 |
+
"model.layers.43.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 467 |
+
"model.layers.43.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 468 |
+
"model.layers.43.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 469 |
+
"model.layers.43.self_attn.k_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 470 |
+
"model.layers.43.self_attn.k_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 471 |
+
"model.layers.43.self_attn.o_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 472 |
+
"model.layers.43.self_attn.q_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 473 |
+
"model.layers.43.self_attn.q_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 474 |
+
"model.layers.43.self_attn.v_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 475 |
+
"model.layers.43.self_attn.v_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 476 |
+
"model.layers.44.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 477 |
+
"model.layers.44.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 478 |
+
"model.layers.44.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 479 |
+
"model.layers.44.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 480 |
+
"model.layers.44.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 481 |
+
"model.layers.44.self_attn.k_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 482 |
+
"model.layers.44.self_attn.k_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 483 |
+
"model.layers.44.self_attn.o_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 484 |
+
"model.layers.44.self_attn.q_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 485 |
+
"model.layers.44.self_attn.q_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 486 |
+
"model.layers.44.self_attn.v_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 487 |
+
"model.layers.44.self_attn.v_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 488 |
+
"model.layers.45.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 489 |
+
"model.layers.45.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 490 |
+
"model.layers.45.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 491 |
+
"model.layers.45.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 492 |
+
"model.layers.45.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 493 |
+
"model.layers.45.self_attn.k_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 494 |
+
"model.layers.45.self_attn.k_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 495 |
+
"model.layers.45.self_attn.o_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 496 |
+
"model.layers.45.self_attn.q_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 497 |
+
"model.layers.45.self_attn.q_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 498 |
+
"model.layers.45.self_attn.v_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 499 |
+
"model.layers.45.self_attn.v_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 500 |
+
"model.layers.46.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 501 |
+
"model.layers.46.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 502 |
+
"model.layers.46.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 503 |
+
"model.layers.46.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 504 |
+
"model.layers.46.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 505 |
+
"model.layers.46.self_attn.k_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 506 |
+
"model.layers.46.self_attn.k_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 507 |
+
"model.layers.46.self_attn.o_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 508 |
+
"model.layers.46.self_attn.q_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 509 |
+
"model.layers.46.self_attn.q_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 510 |
+
"model.layers.46.self_attn.v_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 511 |
+
"model.layers.46.self_attn.v_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 512 |
+
"model.layers.47.input_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 513 |
+
"model.layers.47.mlp.down_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 514 |
+
"model.layers.47.mlp.gate_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 515 |
+
"model.layers.47.mlp.up_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 516 |
+
"model.layers.47.post_attention_layernorm.weight": "pytorch_model-00006-of-00007.bin",
|
| 517 |
+
"model.layers.47.self_attn.k_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 518 |
+
"model.layers.47.self_attn.k_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 519 |
+
"model.layers.47.self_attn.o_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 520 |
+
"model.layers.47.self_attn.q_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 521 |
+
"model.layers.47.self_attn.q_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 522 |
+
"model.layers.47.self_attn.v_proj.bias": "pytorch_model-00006-of-00007.bin",
|
| 523 |
+
"model.layers.47.self_attn.v_proj.weight": "pytorch_model-00006-of-00007.bin",
|
| 524 |
+
"model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 525 |
+
"model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 526 |
+
"model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 527 |
+
"model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 528 |
+
"model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00007.bin",
|
| 529 |
+
"model.layers.5.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 530 |
+
"model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 531 |
+
"model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 532 |
+
"model.layers.5.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 533 |
+
"model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 534 |
+
"model.layers.5.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 535 |
+
"model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 536 |
+
"model.layers.6.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 537 |
+
"model.layers.6.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 538 |
+
"model.layers.6.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 539 |
+
"model.layers.6.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 540 |
+
"model.layers.6.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 541 |
+
"model.layers.6.self_attn.k_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 542 |
+
"model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 543 |
+
"model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 544 |
+
"model.layers.6.self_attn.q_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 545 |
+
"model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 546 |
+
"model.layers.6.self_attn.v_proj.bias": "pytorch_model-00001-of-00007.bin",
|
| 547 |
+
"model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00007.bin",
|
| 548 |
+
"model.layers.7.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 549 |
+
"model.layers.7.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 550 |
+
"model.layers.7.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 551 |
+
"model.layers.7.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 552 |
+
"model.layers.7.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 553 |
+
"model.layers.7.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 554 |
+
"model.layers.7.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 555 |
+
"model.layers.7.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 556 |
+
"model.layers.7.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 557 |
+
"model.layers.7.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 558 |
+
"model.layers.7.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 559 |
+
"model.layers.7.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 560 |
+
"model.layers.8.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 561 |
+
"model.layers.8.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 562 |
+
"model.layers.8.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 563 |
+
"model.layers.8.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 564 |
+
"model.layers.8.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 565 |
+
"model.layers.8.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 566 |
+
"model.layers.8.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 567 |
+
"model.layers.8.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 568 |
+
"model.layers.8.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 569 |
+
"model.layers.8.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 570 |
+
"model.layers.8.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 571 |
+
"model.layers.8.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 572 |
+
"model.layers.9.input_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 573 |
+
"model.layers.9.mlp.down_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 574 |
+
"model.layers.9.mlp.gate_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 575 |
+
"model.layers.9.mlp.up_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 576 |
+
"model.layers.9.post_attention_layernorm.weight": "pytorch_model-00002-of-00007.bin",
|
| 577 |
+
"model.layers.9.self_attn.k_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 578 |
+
"model.layers.9.self_attn.k_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 579 |
+
"model.layers.9.self_attn.o_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 580 |
+
"model.layers.9.self_attn.q_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 581 |
+
"model.layers.9.self_attn.q_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 582 |
+
"model.layers.9.self_attn.v_proj.bias": "pytorch_model-00002-of-00007.bin",
|
| 583 |
+
"model.layers.9.self_attn.v_proj.weight": "pytorch_model-00002-of-00007.bin",
|
| 584 |
+
"model.norm.weight": "pytorch_model-00006-of-00007.bin",
|
| 585 |
+
"ts_decoder.mlp.0.bias": "pytorch_model-00006-of-00007.bin",
|
| 586 |
+
"ts_decoder.mlp.0.weight": "pytorch_model-00006-of-00007.bin",
|
| 587 |
+
"ts_decoder.mlp.12.bias": "pytorch_model-00007-of-00007.bin",
|
| 588 |
+
"ts_decoder.mlp.12.weight": "pytorch_model-00007-of-00007.bin",
|
| 589 |
+
"ts_decoder.mlp.3.bias": "pytorch_model-00007-of-00007.bin",
|
| 590 |
+
"ts_decoder.mlp.3.weight": "pytorch_model-00007-of-00007.bin",
|
| 591 |
+
"ts_decoder.mlp.6.bias": "pytorch_model-00007-of-00007.bin",
|
| 592 |
+
"ts_decoder.mlp.6.weight": "pytorch_model-00007-of-00007.bin",
|
| 593 |
+
"ts_decoder.mlp.9.bias": "pytorch_model-00007-of-00007.bin",
|
| 594 |
+
"ts_decoder.mlp.9.weight": "pytorch_model-00007-of-00007.bin",
|
| 595 |
+
"ts_encoder.mlp.0.bias": "pytorch_model-00006-of-00007.bin",
|
| 596 |
+
"ts_encoder.mlp.0.weight": "pytorch_model-00006-of-00007.bin",
|
| 597 |
+
"ts_encoder.mlp.2.bias": "pytorch_model-00006-of-00007.bin",
|
| 598 |
+
"ts_encoder.mlp.2.weight": "pytorch_model-00006-of-00007.bin",
|
| 599 |
+
"ts_encoder.mlp.4.bias": "pytorch_model-00006-of-00007.bin",
|
| 600 |
+
"ts_encoder.mlp.4.weight": "pytorch_model-00006-of-00007.bin",
|
| 601 |
+
"ts_encoder.mlp.6.bias": "pytorch_model-00006-of-00007.bin",
|
| 602 |
+
"ts_encoder.mlp.6.weight": "pytorch_model-00006-of-00007.bin",
|
| 603 |
+
"ts_encoder.mlp.8.bias": "pytorch_model-00006-of-00007.bin",
|
| 604 |
+
"ts_encoder.mlp.8.weight": "pytorch_model-00006-of-00007.bin",
|
| 605 |
+
"ts_encoder.position_embedding.weight": "pytorch_model-00006-of-00007.bin"
|
| 606 |
+
}
|
| 607 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<ts>",
|
| 4 |
+
"<ts/>"
|
| 5 |
+
],
|
| 6 |
+
"eos_token": {
|
| 7 |
+
"content": "<|im_end|>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false
|
| 12 |
+
},
|
| 13 |
+
"pad_token": {
|
| 14 |
+
"content": "<|endoftext|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false
|
| 19 |
+
}
|
| 20 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:309a7f94e51f1104e6687b31284915a0349755302b483d851f466650dc2ebc67
|
| 3 |
+
size 11422259
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"added_tokens_decoder": {
|
| 5 |
+
"151643": {
|
| 6 |
+
"content": "<|endoftext|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"151644": {
|
| 14 |
+
"content": "<|im_start|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
},
|
| 21 |
+
"151645": {
|
| 22 |
+
"content": "<|im_end|>",
|
| 23 |
+
"lstrip": false,
|
| 24 |
+
"normalized": false,
|
| 25 |
+
"rstrip": false,
|
| 26 |
+
"single_word": false,
|
| 27 |
+
"special": true
|
| 28 |
+
},
|
| 29 |
+
"151646": {
|
| 30 |
+
"content": "<|object_ref_start|>",
|
| 31 |
+
"lstrip": false,
|
| 32 |
+
"normalized": false,
|
| 33 |
+
"rstrip": false,
|
| 34 |
+
"single_word": false,
|
| 35 |
+
"special": true
|
| 36 |
+
},
|
| 37 |
+
"151647": {
|
| 38 |
+
"content": "<|object_ref_end|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false,
|
| 43 |
+
"special": true
|
| 44 |
+
},
|
| 45 |
+
"151648": {
|
| 46 |
+
"content": "<|box_start|>",
|
| 47 |
+
"lstrip": false,
|
| 48 |
+
"normalized": false,
|
| 49 |
+
"rstrip": false,
|
| 50 |
+
"single_word": false,
|
| 51 |
+
"special": true
|
| 52 |
+
},
|
| 53 |
+
"151649": {
|
| 54 |
+
"content": "<|box_end|>",
|
| 55 |
+
"lstrip": false,
|
| 56 |
+
"normalized": false,
|
| 57 |
+
"rstrip": false,
|
| 58 |
+
"single_word": false,
|
| 59 |
+
"special": true
|
| 60 |
+
},
|
| 61 |
+
"151650": {
|
| 62 |
+
"content": "<|quad_start|>",
|
| 63 |
+
"lstrip": false,
|
| 64 |
+
"normalized": false,
|
| 65 |
+
"rstrip": false,
|
| 66 |
+
"single_word": false,
|
| 67 |
+
"special": true
|
| 68 |
+
},
|
| 69 |
+
"151651": {
|
| 70 |
+
"content": "<|quad_end|>",
|
| 71 |
+
"lstrip": false,
|
| 72 |
+
"normalized": false,
|
| 73 |
+
"rstrip": false,
|
| 74 |
+
"single_word": false,
|
| 75 |
+
"special": true
|
| 76 |
+
},
|
| 77 |
+
"151652": {
|
| 78 |
+
"content": "<|vision_start|>",
|
| 79 |
+
"lstrip": false,
|
| 80 |
+
"normalized": false,
|
| 81 |
+
"rstrip": false,
|
| 82 |
+
"single_word": false,
|
| 83 |
+
"special": true
|
| 84 |
+
},
|
| 85 |
+
"151653": {
|
| 86 |
+
"content": "<|vision_end|>",
|
| 87 |
+
"lstrip": false,
|
| 88 |
+
"normalized": false,
|
| 89 |
+
"rstrip": false,
|
| 90 |
+
"single_word": false,
|
| 91 |
+
"special": true
|
| 92 |
+
},
|
| 93 |
+
"151654": {
|
| 94 |
+
"content": "<|vision_pad|>",
|
| 95 |
+
"lstrip": false,
|
| 96 |
+
"normalized": false,
|
| 97 |
+
"rstrip": false,
|
| 98 |
+
"single_word": false,
|
| 99 |
+
"special": true
|
| 100 |
+
},
|
| 101 |
+
"151655": {
|
| 102 |
+
"content": "<|image_pad|>",
|
| 103 |
+
"lstrip": false,
|
| 104 |
+
"normalized": false,
|
| 105 |
+
"rstrip": false,
|
| 106 |
+
"single_word": false,
|
| 107 |
+
"special": true
|
| 108 |
+
},
|
| 109 |
+
"151656": {
|
| 110 |
+
"content": "<|video_pad|>",
|
| 111 |
+
"lstrip": false,
|
| 112 |
+
"normalized": false,
|
| 113 |
+
"rstrip": false,
|
| 114 |
+
"single_word": false,
|
| 115 |
+
"special": true
|
| 116 |
+
},
|
| 117 |
+
"151657": {
|
| 118 |
+
"content": "<tool_call>",
|
| 119 |
+
"lstrip": false,
|
| 120 |
+
"normalized": false,
|
| 121 |
+
"rstrip": false,
|
| 122 |
+
"single_word": false,
|
| 123 |
+
"special": false
|
| 124 |
+
},
|
| 125 |
+
"151658": {
|
| 126 |
+
"content": "</tool_call>",
|
| 127 |
+
"lstrip": false,
|
| 128 |
+
"normalized": false,
|
| 129 |
+
"rstrip": false,
|
| 130 |
+
"single_word": false,
|
| 131 |
+
"special": false
|
| 132 |
+
},
|
| 133 |
+
"151659": {
|
| 134 |
+
"content": "<|fim_prefix|>",
|
| 135 |
+
"lstrip": false,
|
| 136 |
+
"normalized": false,
|
| 137 |
+
"rstrip": false,
|
| 138 |
+
"single_word": false,
|
| 139 |
+
"special": false
|
| 140 |
+
},
|
| 141 |
+
"151660": {
|
| 142 |
+
"content": "<|fim_middle|>",
|
| 143 |
+
"lstrip": false,
|
| 144 |
+
"normalized": false,
|
| 145 |
+
"rstrip": false,
|
| 146 |
+
"single_word": false,
|
| 147 |
+
"special": false
|
| 148 |
+
},
|
| 149 |
+
"151661": {
|
| 150 |
+
"content": "<|fim_suffix|>",
|
| 151 |
+
"lstrip": false,
|
| 152 |
+
"normalized": false,
|
| 153 |
+
"rstrip": false,
|
| 154 |
+
"single_word": false,
|
| 155 |
+
"special": false
|
| 156 |
+
},
|
| 157 |
+
"151662": {
|
| 158 |
+
"content": "<|fim_pad|>",
|
| 159 |
+
"lstrip": false,
|
| 160 |
+
"normalized": false,
|
| 161 |
+
"rstrip": false,
|
| 162 |
+
"single_word": false,
|
| 163 |
+
"special": false
|
| 164 |
+
},
|
| 165 |
+
"151663": {
|
| 166 |
+
"content": "<|repo_name|>",
|
| 167 |
+
"lstrip": false,
|
| 168 |
+
"normalized": false,
|
| 169 |
+
"rstrip": false,
|
| 170 |
+
"single_word": false,
|
| 171 |
+
"special": false
|
| 172 |
+
},
|
| 173 |
+
"151664": {
|
| 174 |
+
"content": "<|file_sep|>",
|
| 175 |
+
"lstrip": false,
|
| 176 |
+
"normalized": false,
|
| 177 |
+
"rstrip": false,
|
| 178 |
+
"single_word": false,
|
| 179 |
+
"special": false
|
| 180 |
+
},
|
| 181 |
+
"151665": {
|
| 182 |
+
"content": "<ts>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": true
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "<ts/>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": true
|
| 196 |
+
}
|
| 197 |
+
},
|
| 198 |
+
"additional_special_tokens": [
|
| 199 |
+
"<ts>",
|
| 200 |
+
"<ts/>"
|
| 201 |
+
],
|
| 202 |
+
"bos_token": null,
|
| 203 |
+
"clean_up_tokenization_spaces": false,
|
| 204 |
+
"eos_token": "<|im_end|>",
|
| 205 |
+
"errors": "replace",
|
| 206 |
+
"extra_special_tokens": {},
|
| 207 |
+
"model_max_length": 131072,
|
| 208 |
+
"pad_token": "<|endoftext|>",
|
| 209 |
+
"padding_side": "right",
|
| 210 |
+
"processor_class": "Qwen2TSProcessor",
|
| 211 |
+
"split_special_tokens": false,
|
| 212 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 213 |
+
"unk_token": null
|
| 214 |
+
}
|
train_results.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.3520179920307038,
|
| 3 |
+
"total_flos": 9.027346976391299e+18,
|
| 4 |
+
"train_loss": 213.8077490248945,
|
| 5 |
+
"train_runtime": 76099.1347,
|
| 6 |
+
"train_samples_per_second": 3.028,
|
| 7 |
+
"train_steps_per_second": 0.012
|
| 8 |
+
}
|
train_timesense.sh
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
#source /mnt/home/venv/bin/activate
|
| 3 |
+
trap 'echo "Ctrl+C detected. Exiting..."; exit 1' SIGINT
|
| 4 |
+
set -e
|
| 5 |
+
countdown() {
|
| 6 |
+
local SECONDS_LEFT=$((0 * 30 * 60))
|
| 7 |
+
while [ $SECONDS_LEFT -gt 0 ]; do
|
| 8 |
+
HOURS=$(($SECONDS_LEFT / 3600))
|
| 9 |
+
MINUTES=$((($SECONDS_LEFT % 3600) / 60))
|
| 10 |
+
SECONDS=$(($SECONDS_LEFT % 60))
|
| 11 |
+
printf "\r%02d:%02d:%02d" $HOURS $MINUTES $SECONDS
|
| 12 |
+
sleep 1
|
| 13 |
+
SECONDS_LEFT=$(($SECONDS_LEFT - 1))
|
| 14 |
+
done
|
| 15 |
+
echo ""
|
| 16 |
+
}
|
| 17 |
+
countdown
|
| 18 |
+
|
| 19 |
+
OUTPUT_DIR="/xll/models/ChatTS-14B-timesense"
|
| 20 |
+
MODEL_NAME_OR_PATH="/xll/models/ChatTS-14B"
|
| 21 |
+
#MODEL_NAME_OR_PATH="/mnt/home/xz/zr/LLaMA-Factory-zzr/script/ChatTS/sft_checkpoint/Qwen2.5-14B-Instruct"
|
| 22 |
+
# /mnt/home/zr/models/ChatTS-14B
|
| 23 |
+
APPEND_FILES_DIR="/xll/models/ChatTS-14B/append"
|
| 24 |
+
echo "Copying files from $APPEND_FILES_DIR to $MODEL_NAME_OR_PATH"
|
| 25 |
+
for file in "$APPEND_FILES_DIR"/*; do
|
| 26 |
+
cp -f "$file" "$MODEL_NAME_OR_PATH/"
|
| 27 |
+
done
|
| 28 |
+
|
| 29 |
+
CURRENT_SCRIPT_PATH="${BASH_SOURCE[0]}"
|
| 30 |
+
SCRIPT_FILENAME=$(basename "$CURRENT_SCRIPT_PATH")
|
| 31 |
+
mkdir -p "$OUTPUT_DIR"
|
| 32 |
+
cp "$CURRENT_SCRIPT_PATH" "$OUTPUT_DIR/$SCRIPT_FILENAME"
|
| 33 |
+
|
| 34 |
+
echo "脚本 '$SCRIPT_FILENAME' 已成功复制到 '$OUTPUT_DIR'"
|
| 35 |
+
echo "Files copied successfully."
|
| 36 |
+
#cd /mnt/home/zr/xz/opsfm-xz
|
| 37 |
+
cd /root/code/chat-ts-training
|
| 38 |
+
|
| 39 |
+
DEEPSPEED_TIMEOUT=120 deepspeed --num_gpus 8 --master_port=19901 src/train.py \
|
| 40 |
+
--deepspeed /root/code/chat-ts-training/ds_config/ds_config_2_bf16_offload.json \
|
| 41 |
+
--stage sft \
|
| 42 |
+
--model_name_or_path "$MODEL_NAME_OR_PATH"\
|
| 43 |
+
--dataset "generated_timeseries_bench_qa_new2,generated_timeseries_bench_plus2,tulu_ift,model_detect_0823,model_qa,new_chatts_sft,new_chatts_ift" \
|
| 44 |
+
--interleave_probs "0.4,0.1,0.1,0.1,0.1,0.1,0.1" \
|
| 45 |
+
--do_train \
|
| 46 |
+
--mix_strategy "interleave_over" \
|
| 47 |
+
--template "chatts" \
|
| 48 |
+
--finetuning_type full \
|
| 49 |
+
--output_dir "$OUTPUT_DIR" \
|
| 50 |
+
--overwrite_output_dir \
|
| 51 |
+
--trust_remote_code True \
|
| 52 |
+
--report_to "none" \
|
| 53 |
+
--per_device_train_batch_size 1 \
|
| 54 |
+
--gradient_accumulation_steps 32 \
|
| 55 |
+
--lr_scheduler_type cosine \
|
| 56 |
+
--logging_steps 1 \
|
| 57 |
+
--save_steps 600 \
|
| 58 |
+
--learning_rate 1e-5 \
|
| 59 |
+
--warmup_ratio 0.02 \
|
| 60 |
+
--num_train_epochs 0 \
|
| 61 |
+
--max_steps 1200 \
|
| 62 |
+
--plot_loss \
|
| 63 |
+
--bf16 \
|
| 64 |
+
--save_only_model \
|
| 65 |
+
--save_safetensors False \
|
| 66 |
+
--preprocessing_num_workers 96 \
|
| 67 |
+
--cutoff_len 9000
|
| 68 |
+
|
| 69 |
+
CURRENT_SCRIPT_PATH="${BASH_SOURCE[0]}"
|
| 70 |
+
# 提取脚本文件名
|
| 71 |
+
SCRIPT_FILENAME=$(basename "$CURRENT_SCRIPT_PATH")
|
| 72 |
+
cp "$CURRENT_SCRIPT_PATH" "$OUTPUT_DIR/$SCRIPT_FILENAME"
|
| 73 |
+
echo "Files copied successfully."
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
python /root/code/null.py
|
trainer_log.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
trainer_state.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8f52af9b04573af2c978686a08d2f07e828f92237d7299b4e680f0c45c33e9da
|
| 3 |
+
size 7416
|
training_loss.png
ADDED
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|