Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/README.md +59 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/added_tokens.json +13 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/all_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/config.json +36 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/configuration_phi3.py +227 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/generation_config.json +11 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model-00001-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model-00002-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model.safetensors.index.json +202 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/modeling_phi3.py +1563 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/special_tokens_map.json +30 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/tokenizer.json +0 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/tokenizer_config.json +131 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/train_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/trainer_state.json +1317 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/training_args.bin +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/README.md +59 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/added_tokens.json +13 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/all_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/config.json +36 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/configuration_phi3.py +227 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/generation_config.json +11 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model-00001-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model-00002-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model.safetensors.index.json +202 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/modeling_phi3.py +1563 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/special_tokens_map.json +30 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/tokenizer.json +0 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/tokenizer_config.json +131 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/train_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/trainer_state.json +0 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/training_args.bin +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/README.md +59 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/added_tokens.json +13 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/all_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/config.json +36 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/configuration_phi3.py +227 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/generation_config.json +11 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/model-00001-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/model-00002-of-00002.safetensors +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/model.safetensors.index.json +202 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/modeling_phi3.py +1563 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/raw_datasets.json +3 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/special_tokens_map.json +30 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/tokenizer.json +0 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/tokenizer_config.json +131 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/train_results.json +9 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/trainer_state.json +1392 -0
- Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/training_args.bin +3 -0
.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 |
+
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/raw_datasets.json filter=lfs diff=lfs merge=lfs -text
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
base_model: /home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct
|
| 4 |
+
tags:
|
| 5 |
+
- alignment-handbook
|
| 6 |
+
- generated_from_trainer
|
| 7 |
+
datasets:
|
| 8 |
+
- /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math
|
| 9 |
+
model-index:
|
| 10 |
+
- name: Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1
|
| 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 |
+
# Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1
|
| 18 |
+
|
| 19 |
+
This model is a fine-tuned version of [/home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct](https://huggingface.co//home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct) on the /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math dataset.
|
| 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: 5e-07
|
| 39 |
+
- train_batch_size: 2
|
| 40 |
+
- eval_batch_size: 4
|
| 41 |
+
- seed: 42
|
| 42 |
+
- distributed_type: multi-GPU
|
| 43 |
+
- gradient_accumulation_steps: 64
|
| 44 |
+
- total_train_batch_size: 128
|
| 45 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
| 46 |
+
- lr_scheduler_type: cosine
|
| 47 |
+
- lr_scheduler_warmup_ratio: 0.1
|
| 48 |
+
- num_epochs: 1
|
| 49 |
+
|
| 50 |
+
### Training results
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
### Framework versions
|
| 55 |
+
|
| 56 |
+
- Transformers 4.45.2
|
| 57 |
+
- Pytorch 2.5.1+cu121
|
| 58 |
+
- Datasets 3.5.0
|
| 59 |
+
- Tokenizers 0.20.3
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/added_tokens.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<|assistant|>": 32001,
|
| 3 |
+
"<|endoftext|>": 32000,
|
| 4 |
+
"<|end|>": 32007,
|
| 5 |
+
"<|placeholder1|>": 32002,
|
| 6 |
+
"<|placeholder2|>": 32003,
|
| 7 |
+
"<|placeholder3|>": 32004,
|
| 8 |
+
"<|placeholder4|>": 32005,
|
| 9 |
+
"<|placeholder5|>": 32008,
|
| 10 |
+
"<|placeholder6|>": 32009,
|
| 11 |
+
"<|system|>": 32006,
|
| 12 |
+
"<|user|>": 32010
|
| 13 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/all_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9880609304240429,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 2099.8924772135415,
|
| 5 |
+
"train_runtime": 5573.0674,
|
| 6 |
+
"train_samples": 9715,
|
| 7 |
+
"train_samples_per_second": 1.743,
|
| 8 |
+
"train_steps_per_second": 0.013
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Phi3ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "configuration_phi3.Phi3Config",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 1,
|
| 13 |
+
"embd_pdrop": 0.0,
|
| 14 |
+
"eos_token_id": 32000,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 3072,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 8192,
|
| 19 |
+
"max_position_embeddings": 4096,
|
| 20 |
+
"model_type": "phi3",
|
| 21 |
+
"num_attention_heads": 32,
|
| 22 |
+
"num_hidden_layers": 32,
|
| 23 |
+
"num_key_value_heads": 32,
|
| 24 |
+
"original_max_position_embeddings": 4096,
|
| 25 |
+
"pad_token_id": 32000,
|
| 26 |
+
"resid_pdrop": 0.0,
|
| 27 |
+
"rms_norm_eps": 1e-05,
|
| 28 |
+
"rope_scaling": null,
|
| 29 |
+
"rope_theta": 10000.0,
|
| 30 |
+
"sliding_window": 2047,
|
| 31 |
+
"tie_word_embeddings": false,
|
| 32 |
+
"torch_dtype": "bfloat16",
|
| 33 |
+
"transformers_version": "4.45.2",
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32064
|
| 36 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/configuration_phi3.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" Phi-3 model configuration"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 20 |
+
from transformers.utils import logging
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
logger = logging.get_logger(__name__)
|
| 24 |
+
|
| 25 |
+
PHI3_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
| 26 |
+
"microsoft/Phi-3-mini-4k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/resolve/main/config.json",
|
| 27 |
+
"microsoft/Phi-3-mini-128k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/resolve/main/config.json",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Phi3Config(PretrainedConfig):
|
| 32 |
+
r"""
|
| 33 |
+
This is the configuration class to store the configuration of a [`Phi3Model`]. It is used to instantiate a Phi-3
|
| 34 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 35 |
+
defaults will yield a similar configuration to that of the
|
| 36 |
+
[microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
|
| 37 |
+
|
| 38 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 39 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
vocab_size (`int`, *optional*, defaults to 32064):
|
| 43 |
+
Vocabulary size of the Phi-3 model. Defines the number of different tokens that can be represented by the
|
| 44 |
+
`inputs_ids` passed when calling [`Phi3Model`].
|
| 45 |
+
hidden_size (`int`, *optional*, defaults to 3072):
|
| 46 |
+
Dimension of the hidden representations.
|
| 47 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
| 48 |
+
Dimension of the MLP representations.
|
| 49 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 50 |
+
Number of hidden layers in the Transformer decoder.
|
| 51 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 52 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 53 |
+
num_key_value_heads (`int`, *optional*):
|
| 54 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 55 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 56 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 57 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 58 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 59 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 60 |
+
`num_attention_heads`.
|
| 61 |
+
resid_pdrop (`float`, *optional*, defaults to 0.0):
|
| 62 |
+
Dropout probability for mlp outputs.
|
| 63 |
+
embd_pdrop (`int`, *optional*, defaults to 0.0):
|
| 64 |
+
The dropout ratio for the embeddings.
|
| 65 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 66 |
+
The dropout ratio after computing the attention scores.
|
| 67 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 68 |
+
The non-linear activation function (function or string) in the decoder.
|
| 69 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 70 |
+
The maximum sequence length that this model might ever be used with.
|
| 71 |
+
original_max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 72 |
+
The maximum sequence length that this model was trained with. This is used to determine the size of the
|
| 73 |
+
original RoPE embeddings when using long scaling.
|
| 74 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 75 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 76 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 77 |
+
The epsilon value used for the RMSNorm.
|
| 78 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 79 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 80 |
+
relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
|
| 81 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 82 |
+
Whether to tie weight embeddings
|
| 83 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 84 |
+
The base period of the RoPE embeddings.
|
| 85 |
+
rope_scaling (`dict`, *optional*):
|
| 86 |
+
The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
|
| 87 |
+
contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be `longrope` and
|
| 88 |
+
the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
|
| 89 |
+
divided by the number of attention heads divided by 2.
|
| 90 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 91 |
+
The id of the "beginning-of-sequence" token.
|
| 92 |
+
eos_token_id (`int`, *optional*, defaults to 32000):
|
| 93 |
+
The id of the "end-of-sequence" token.
|
| 94 |
+
pad_token_id (`int`, *optional*, defaults to 32000):
|
| 95 |
+
The id of the padding token.
|
| 96 |
+
sliding_window (`int`, *optional*):
|
| 97 |
+
Sliding window attention window size. If `None`, no sliding window is applied.
|
| 98 |
+
|
| 99 |
+
Example:
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
>>> from transformers import Phi3Model, Phi3Config
|
| 103 |
+
|
| 104 |
+
>>> # Initializing a Phi-3 style configuration
|
| 105 |
+
>>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 106 |
+
|
| 107 |
+
>>> # Initializing a model from the configuration
|
| 108 |
+
>>> model = Phi3Model(configuration)
|
| 109 |
+
|
| 110 |
+
>>> # Accessing the model configuration
|
| 111 |
+
>>> configuration = model.config
|
| 112 |
+
```"""
|
| 113 |
+
|
| 114 |
+
model_type = "phi3"
|
| 115 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
+
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
vocab_size=32064,
|
| 120 |
+
hidden_size=3072,
|
| 121 |
+
intermediate_size=8192,
|
| 122 |
+
num_hidden_layers=32,
|
| 123 |
+
num_attention_heads=32,
|
| 124 |
+
num_key_value_heads=None,
|
| 125 |
+
resid_pdrop=0.0,
|
| 126 |
+
embd_pdrop=0.0,
|
| 127 |
+
attention_dropout=0.0,
|
| 128 |
+
hidden_act="silu",
|
| 129 |
+
max_position_embeddings=4096,
|
| 130 |
+
original_max_position_embeddings=4096,
|
| 131 |
+
initializer_range=0.02,
|
| 132 |
+
rms_norm_eps=1e-5,
|
| 133 |
+
use_cache=True,
|
| 134 |
+
tie_word_embeddings=False,
|
| 135 |
+
rope_theta=10000.0,
|
| 136 |
+
rope_scaling=None,
|
| 137 |
+
bos_token_id=1,
|
| 138 |
+
eos_token_id=32000,
|
| 139 |
+
pad_token_id=32000,
|
| 140 |
+
sliding_window=None,
|
| 141 |
+
**kwargs,
|
| 142 |
+
):
|
| 143 |
+
self.vocab_size = vocab_size
|
| 144 |
+
self.hidden_size = hidden_size
|
| 145 |
+
self.intermediate_size = intermediate_size
|
| 146 |
+
self.num_hidden_layers = num_hidden_layers
|
| 147 |
+
self.num_attention_heads = num_attention_heads
|
| 148 |
+
|
| 149 |
+
if num_key_value_heads is None:
|
| 150 |
+
num_key_value_heads = num_attention_heads
|
| 151 |
+
|
| 152 |
+
self.num_key_value_heads = num_key_value_heads
|
| 153 |
+
self.resid_pdrop = resid_pdrop
|
| 154 |
+
self.embd_pdrop = embd_pdrop
|
| 155 |
+
self.attention_dropout = attention_dropout
|
| 156 |
+
self.hidden_act = hidden_act
|
| 157 |
+
self.max_position_embeddings = max_position_embeddings
|
| 158 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
| 159 |
+
self.initializer_range = initializer_range
|
| 160 |
+
self.rms_norm_eps = rms_norm_eps
|
| 161 |
+
self.use_cache = use_cache
|
| 162 |
+
self.rope_theta = rope_theta
|
| 163 |
+
self.rope_scaling = rope_scaling
|
| 164 |
+
self._rope_scaling_adjustment()
|
| 165 |
+
self._rope_scaling_validation()
|
| 166 |
+
self.sliding_window = sliding_window
|
| 167 |
+
|
| 168 |
+
super().__init__(
|
| 169 |
+
bos_token_id=bos_token_id,
|
| 170 |
+
eos_token_id=eos_token_id,
|
| 171 |
+
pad_token_id=pad_token_id,
|
| 172 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 173 |
+
**kwargs,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
def _rope_scaling_adjustment(self):
|
| 177 |
+
"""
|
| 178 |
+
Adjust the `type` of the `rope_scaling` configuration for backward compatibility.
|
| 179 |
+
"""
|
| 180 |
+
if self.rope_scaling is None:
|
| 181 |
+
return
|
| 182 |
+
|
| 183 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 184 |
+
|
| 185 |
+
# For backward compatibility if previous version used "su" or "yarn"
|
| 186 |
+
if rope_scaling_type is not None and rope_scaling_type in ["su", "yarn"]:
|
| 187 |
+
self.rope_scaling["type"] = "longrope"
|
| 188 |
+
|
| 189 |
+
def _rope_scaling_validation(self):
|
| 190 |
+
"""
|
| 191 |
+
Validate the `rope_scaling` configuration.
|
| 192 |
+
"""
|
| 193 |
+
if self.rope_scaling is None:
|
| 194 |
+
return
|
| 195 |
+
|
| 196 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
|
| 197 |
+
raise ValueError(
|
| 198 |
+
"`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
|
| 199 |
+
f"got {self.rope_scaling}"
|
| 200 |
+
)
|
| 201 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 202 |
+
rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
|
| 203 |
+
rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
|
| 204 |
+
if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
|
| 205 |
+
raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
|
| 206 |
+
if not (
|
| 207 |
+
isinstance(rope_scaling_short_factor, list)
|
| 208 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
|
| 209 |
+
):
|
| 210 |
+
raise ValueError(
|
| 211 |
+
f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
|
| 212 |
+
)
|
| 213 |
+
if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 214 |
+
raise ValueError(
|
| 215 |
+
f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
|
| 216 |
+
)
|
| 217 |
+
if not (
|
| 218 |
+
isinstance(rope_scaling_long_factor, list)
|
| 219 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
|
| 220 |
+
):
|
| 221 |
+
raise ValueError(
|
| 222 |
+
f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
|
| 223 |
+
)
|
| 224 |
+
if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 225 |
+
raise ValueError(
|
| 226 |
+
f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
|
| 227 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
32000,
|
| 6 |
+
32001,
|
| 7 |
+
32007
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 32000,
|
| 10 |
+
"transformers_version": "4.45.2"
|
| 11 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7b6261df0a4511f7b4ddb173e44c5f5dc641ad0a9097b0632f48e85e4b1c0f29
|
| 3 |
+
size 4972489328
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff70ad3e3b71e5ee069c623a39d2c191291bfe47b5b4853f22dd9b3d0f06b27f
|
| 3 |
+
size 2669692552
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/model.safetensors.index.json
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 7642159104
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 7 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.10.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.10.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.11.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.11.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.12.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.12.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.13.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.13.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.14.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.14.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.15.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.15.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.16.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.16.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.17.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.17.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.18.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"model.layers.18.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"model.layers.19.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.19.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.20.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.20.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 93 |
+
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 94 |
+
"model.layers.21.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 95 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 96 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.21.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 98 |
+
"model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 99 |
+
"model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 100 |
+
"model.layers.22.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 101 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 102 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 103 |
+
"model.layers.22.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 104 |
+
"model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 105 |
+
"model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 106 |
+
"model.layers.23.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 107 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 108 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 109 |
+
"model.layers.23.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 110 |
+
"model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 111 |
+
"model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 112 |
+
"model.layers.24.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 113 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 114 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 115 |
+
"model.layers.24.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 116 |
+
"model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 117 |
+
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 118 |
+
"model.layers.25.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 119 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 120 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 121 |
+
"model.layers.25.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 122 |
+
"model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 123 |
+
"model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 124 |
+
"model.layers.26.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 125 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 126 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 127 |
+
"model.layers.26.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 128 |
+
"model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 129 |
+
"model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 130 |
+
"model.layers.27.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 131 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 132 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 133 |
+
"model.layers.27.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 134 |
+
"model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 135 |
+
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 136 |
+
"model.layers.28.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 137 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 138 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 139 |
+
"model.layers.28.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 140 |
+
"model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 141 |
+
"model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 142 |
+
"model.layers.29.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 143 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 144 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 145 |
+
"model.layers.29.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 146 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 152 |
+
"model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 153 |
+
"model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 154 |
+
"model.layers.30.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 155 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 156 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 157 |
+
"model.layers.30.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 158 |
+
"model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 159 |
+
"model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 160 |
+
"model.layers.31.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 161 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 162 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 163 |
+
"model.layers.31.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 164 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 165 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 166 |
+
"model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 167 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 168 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 169 |
+
"model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 170 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 171 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 172 |
+
"model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 173 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 174 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 175 |
+
"model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 176 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 177 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 178 |
+
"model.layers.6.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 179 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 180 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 181 |
+
"model.layers.6.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 182 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 183 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 184 |
+
"model.layers.7.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 185 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 186 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 187 |
+
"model.layers.7.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 188 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 189 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 190 |
+
"model.layers.8.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 191 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 192 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 193 |
+
"model.layers.8.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 194 |
+
"model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 195 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 196 |
+
"model.layers.9.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 197 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 198 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 199 |
+
"model.layers.9.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 200 |
+
"model.norm.weight": "model-00002-of-00002.safetensors"
|
| 201 |
+
}
|
| 202 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/modeling_phi3.py
ADDED
|
@@ -0,0 +1,1563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" PyTorch Phi-3 model."""
|
| 17 |
+
|
| 18 |
+
import inspect
|
| 19 |
+
import math
|
| 20 |
+
import warnings
|
| 21 |
+
from typing import List, Optional, Tuple, Union
|
| 22 |
+
|
| 23 |
+
import torch
|
| 24 |
+
import torch.nn.functional as F
|
| 25 |
+
import torch.utils.checkpoint
|
| 26 |
+
from torch import nn
|
| 27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 28 |
+
|
| 29 |
+
from transformers.activations import ACT2FN
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
|
| 32 |
+
from transformers.modeling_outputs import (
|
| 33 |
+
BaseModelOutputWithPast,
|
| 34 |
+
CausalLMOutputWithPast,
|
| 35 |
+
SequenceClassifierOutputWithPast,
|
| 36 |
+
TokenClassifierOutput,
|
| 37 |
+
)
|
| 38 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 39 |
+
from transformers.utils import (
|
| 40 |
+
add_code_sample_docstrings,
|
| 41 |
+
add_start_docstrings,
|
| 42 |
+
add_start_docstrings_to_model_forward,
|
| 43 |
+
is_flash_attn_2_available,
|
| 44 |
+
is_flash_attn_greater_or_equal_2_10,
|
| 45 |
+
logging,
|
| 46 |
+
replace_return_docstrings,
|
| 47 |
+
)
|
| 48 |
+
from .configuration_phi3 import Phi3Config
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
logger = logging.get_logger(__name__)
|
| 52 |
+
|
| 53 |
+
# Transformers scans dependencies in the modeling file, causing issues on conditional loading. The regex only ignores try/catch blocks, but not if statements
|
| 54 |
+
# if is_flash_attn_2_available():
|
| 55 |
+
_flash_supports_window_size = False
|
| 56 |
+
try:
|
| 57 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 58 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 59 |
+
|
| 60 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 61 |
+
except ImportError as error:
|
| 62 |
+
logger.warning(
|
| 63 |
+
f"`flash-attention` package not found, consider installing for better performance: {error}."
|
| 64 |
+
)
|
| 65 |
+
if not _flash_supports_window_size:
|
| 66 |
+
logger.warning(
|
| 67 |
+
"Current `flash-attention` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`."
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
_CHECKPOINT_FOR_DOC = "microsoft/Phi-3-mini-4k-instruct"
|
| 71 |
+
_CONFIG_FOR_DOC = "Phi3Config"
|
| 72 |
+
|
| 73 |
+
PHI3_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
| 74 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
| 75 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 76 |
+
# See all Phi-3 models at https://huggingface.co/models?filter=Phi-3
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Phi3
|
| 81 |
+
class Phi3RMSNorm(nn.Module):
|
| 82 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 83 |
+
"""
|
| 84 |
+
Phi3RMSNorm is equivalent to T5LayerNorm
|
| 85 |
+
"""
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 88 |
+
self.variance_epsilon = eps
|
| 89 |
+
|
| 90 |
+
def forward(self, hidden_states):
|
| 91 |
+
input_dtype = hidden_states.dtype
|
| 92 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 93 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 94 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 95 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
| 99 |
+
def _get_unpad_data(attention_mask):
|
| 100 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
| 101 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
| 102 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
| 103 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
| 104 |
+
return (
|
| 105 |
+
indices,
|
| 106 |
+
cu_seqlens,
|
| 107 |
+
max_seqlen_in_batch,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# Copied from transformers.models.gemma.modeling_gemma.GemmaRotaryEmbedding with gemma->phi3, Gemma->Phi3
|
| 112 |
+
class Phi3RotaryEmbedding(nn.Module):
|
| 113 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
| 114 |
+
super().__init__()
|
| 115 |
+
|
| 116 |
+
self.dim = dim
|
| 117 |
+
self.max_position_embeddings = max_position_embeddings
|
| 118 |
+
self.base = base
|
| 119 |
+
self.register_buffer("inv_freq", None, persistent=False)
|
| 120 |
+
|
| 121 |
+
@torch.no_grad()
|
| 122 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 123 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
| 124 |
+
if self.inv_freq is None:
|
| 125 |
+
self.inv_freq = 1.0 / (
|
| 126 |
+
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
|
| 127 |
+
)
|
| 128 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 129 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 130 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 131 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 132 |
+
device_type = x.device.type
|
| 133 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 134 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 135 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 136 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 137 |
+
cos = emb.cos()
|
| 138 |
+
sin = emb.sin()
|
| 139 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class Phi3LongRoPEScaledRotaryEmbedding(Phi3RotaryEmbedding):
|
| 143 |
+
def __init__(self, dim, config, device=None):
|
| 144 |
+
super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
|
| 145 |
+
|
| 146 |
+
self.short_factor = config.rope_scaling["short_factor"]
|
| 147 |
+
self.long_factor = config.rope_scaling["long_factor"]
|
| 148 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 149 |
+
|
| 150 |
+
@torch.no_grad()
|
| 151 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 152 |
+
seq_len = torch.max(position_ids) + 1
|
| 153 |
+
if seq_len > self.original_max_position_embeddings:
|
| 154 |
+
ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
|
| 155 |
+
else:
|
| 156 |
+
ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
|
| 157 |
+
|
| 158 |
+
inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
|
| 159 |
+
self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
|
| 160 |
+
|
| 161 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 162 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 163 |
+
|
| 164 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 165 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 166 |
+
device_type = x.device.type
|
| 167 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 168 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 169 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 170 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 171 |
+
|
| 172 |
+
scale = self.max_position_embeddings / self.original_max_position_embeddings
|
| 173 |
+
if scale <= 1.0:
|
| 174 |
+
scaling_factor = 1.0
|
| 175 |
+
else:
|
| 176 |
+
scaling_factor = math.sqrt(1 + math.log(scale) / math.log(self.original_max_position_embeddings))
|
| 177 |
+
|
| 178 |
+
cos = emb.cos() * scaling_factor
|
| 179 |
+
sin = emb.sin() * scaling_factor
|
| 180 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
| 184 |
+
def rotate_half(x):
|
| 185 |
+
"""Rotates half the hidden dims of the input."""
|
| 186 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 187 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 188 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
|
| 192 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 193 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 194 |
+
|
| 195 |
+
Args:
|
| 196 |
+
q (`torch.Tensor`): The query tensor.
|
| 197 |
+
k (`torch.Tensor`): The key tensor.
|
| 198 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 199 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 200 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 201 |
+
Deprecated and unused.
|
| 202 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 203 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 204 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 205 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 206 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 207 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 208 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 209 |
+
Returns:
|
| 210 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 211 |
+
"""
|
| 212 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 213 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 214 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 215 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 216 |
+
return q_embed, k_embed
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class Phi3MLP(nn.Module):
|
| 220 |
+
def __init__(self, config):
|
| 221 |
+
super().__init__()
|
| 222 |
+
|
| 223 |
+
self.config = config
|
| 224 |
+
self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
|
| 225 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 226 |
+
|
| 227 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
| 228 |
+
|
| 229 |
+
def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
|
| 230 |
+
up_states = self.gate_up_proj(hidden_states)
|
| 231 |
+
|
| 232 |
+
gate, up_states = up_states.chunk(2, dim=-1)
|
| 233 |
+
up_states = up_states * self.activation_fn(gate)
|
| 234 |
+
|
| 235 |
+
return self.down_proj(up_states)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
|
| 239 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 240 |
+
"""
|
| 241 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 242 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 243 |
+
"""
|
| 244 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 245 |
+
if n_rep == 1:
|
| 246 |
+
return hidden_states
|
| 247 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 248 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class Phi3Attention(nn.Module):
|
| 252 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 253 |
+
|
| 254 |
+
def __init__(self, config: Phi3Config, layer_idx: Optional[int] = None):
|
| 255 |
+
super().__init__()
|
| 256 |
+
self.config = config
|
| 257 |
+
self.layer_idx = layer_idx
|
| 258 |
+
if layer_idx is None:
|
| 259 |
+
logger.warning_once(
|
| 260 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 261 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 262 |
+
"when creating this class."
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
self.attention_dropout = config.attention_dropout
|
| 266 |
+
self.hidden_size = config.hidden_size
|
| 267 |
+
self.num_heads = config.num_attention_heads
|
| 268 |
+
self.head_dim = self.hidden_size // self.num_heads
|
| 269 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 270 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
| 271 |
+
self.max_position_embeddings = config.max_position_embeddings
|
| 272 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 273 |
+
self.rope_theta = config.rope_theta
|
| 274 |
+
self.rope_scaling = config.rope_scaling
|
| 275 |
+
self.is_causal = True
|
| 276 |
+
|
| 277 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
| 278 |
+
raise ValueError(
|
| 279 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
| 280 |
+
f" and `num_heads`: {self.num_heads})."
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
op_size = self.num_heads * self.head_dim + 2 * (self.num_key_value_heads * self.head_dim)
|
| 284 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
| 285 |
+
self.qkv_proj = nn.Linear(self.hidden_size, op_size, bias=False)
|
| 286 |
+
self._init_rope()
|
| 287 |
+
|
| 288 |
+
def _init_rope(self):
|
| 289 |
+
if self.rope_scaling is None:
|
| 290 |
+
self.rotary_emb = Phi3RotaryEmbedding(
|
| 291 |
+
self.head_dim,
|
| 292 |
+
max_position_embeddings=self.max_position_embeddings,
|
| 293 |
+
base=self.rope_theta,
|
| 294 |
+
)
|
| 295 |
+
else:
|
| 296 |
+
scaling_type = self.config.rope_scaling["type"]
|
| 297 |
+
if scaling_type == "longrope":
|
| 298 |
+
self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
|
| 299 |
+
else:
|
| 300 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
| 301 |
+
|
| 302 |
+
def forward(
|
| 303 |
+
self,
|
| 304 |
+
hidden_states: torch.Tensor,
|
| 305 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 306 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 307 |
+
past_key_value: Optional[Cache] = None,
|
| 308 |
+
output_attentions: bool = False,
|
| 309 |
+
use_cache: bool = False,
|
| 310 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 311 |
+
logger.warning_once("You are not running the flash-attention implementation, expect numerical differences.")
|
| 312 |
+
|
| 313 |
+
bsz, q_len, _ = hidden_states.size()
|
| 314 |
+
|
| 315 |
+
qkv = self.qkv_proj(hidden_states)
|
| 316 |
+
query_pos = self.num_heads * self.head_dim
|
| 317 |
+
query_states = qkv[..., :query_pos]
|
| 318 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 319 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 320 |
+
|
| 321 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 322 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 323 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 324 |
+
|
| 325 |
+
kv_seq_len = key_states.shape[-2]
|
| 326 |
+
if past_key_value is not None:
|
| 327 |
+
if self.layer_idx is None:
|
| 328 |
+
raise ValueError(
|
| 329 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 330 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 331 |
+
"with a layer index."
|
| 332 |
+
)
|
| 333 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 334 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 335 |
+
|
| 336 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 337 |
+
|
| 338 |
+
if past_key_value is not None:
|
| 339 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 340 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 341 |
+
|
| 342 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 343 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 344 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 345 |
+
|
| 346 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
| 347 |
+
|
| 348 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
| 349 |
+
raise ValueError(
|
| 350 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
| 351 |
+
f" {attn_weights.size()}"
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
if attention_mask is not None:
|
| 355 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 356 |
+
raise ValueError(
|
| 357 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 358 |
+
)
|
| 359 |
+
attn_weights = attn_weights + attention_mask
|
| 360 |
+
|
| 361 |
+
# upcast attention to fp32
|
| 362 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
|
| 363 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
| 364 |
+
|
| 365 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 366 |
+
|
| 367 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
| 368 |
+
raise ValueError(
|
| 369 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
| 370 |
+
f" {attn_output.size()}"
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 374 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
| 375 |
+
|
| 376 |
+
attn_output = self.o_proj(attn_output)
|
| 377 |
+
|
| 378 |
+
if not output_attentions:
|
| 379 |
+
attn_weights = None
|
| 380 |
+
|
| 381 |
+
return attn_output, attn_weights, past_key_value
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class Phi3FlashAttention2(Phi3Attention):
|
| 385 |
+
"""
|
| 386 |
+
Phi-3 flash attention module. This module inherits from `Phi3Attention` as the weights of the module stays
|
| 387 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
| 388 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
| 389 |
+
"""
|
| 390 |
+
|
| 391 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
|
| 392 |
+
def __init__(self, *args, **kwargs):
|
| 393 |
+
super().__init__(*args, **kwargs)
|
| 394 |
+
|
| 395 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
| 396 |
+
# 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.
|
| 397 |
+
# 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).
|
| 398 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
| 399 |
+
|
| 400 |
+
def forward(
|
| 401 |
+
self,
|
| 402 |
+
hidden_states: torch.Tensor,
|
| 403 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 404 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 405 |
+
past_key_value: Optional[Cache] = None,
|
| 406 |
+
output_attentions: bool = False,
|
| 407 |
+
use_cache: bool = False,
|
| 408 |
+
**kwargs,
|
| 409 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 410 |
+
# Phi3FlashAttention2 attention does not support output_attentions
|
| 411 |
+
|
| 412 |
+
if not _flash_supports_window_size:
|
| 413 |
+
logger.warning_once(
|
| 414 |
+
"The current flash attention version does not support sliding window attention. Please use `attn_implementation='eager'` or upgrade flash-attn library."
|
| 415 |
+
)
|
| 416 |
+
raise ValueError("The current flash attention version does not support sliding window attention.")
|
| 417 |
+
|
| 418 |
+
output_attentions = False
|
| 419 |
+
|
| 420 |
+
if "padding_mask" in kwargs:
|
| 421 |
+
warnings.warn(
|
| 422 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
# overwrite attention_mask with padding_mask
|
| 426 |
+
attention_mask = kwargs.pop("padding_mask")
|
| 427 |
+
|
| 428 |
+
bsz, q_len, _ = hidden_states.size()
|
| 429 |
+
|
| 430 |
+
qkv = self.qkv_proj(hidden_states)
|
| 431 |
+
query_pos = self.num_heads * self.head_dim
|
| 432 |
+
query_states = qkv[..., :query_pos]
|
| 433 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 434 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 435 |
+
|
| 436 |
+
# Flash attention requires the input to have the shape
|
| 437 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
| 438 |
+
# therefore we just need to keep the original shape
|
| 439 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 440 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 441 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 442 |
+
|
| 443 |
+
kv_seq_len = key_states.shape[-2]
|
| 444 |
+
if past_key_value is not None:
|
| 445 |
+
if self.layer_idx is None:
|
| 446 |
+
raise ValueError(
|
| 447 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 448 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 449 |
+
"with a layer index."
|
| 450 |
+
)
|
| 451 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 452 |
+
|
| 453 |
+
# Because the input can be padded, the absolute sequence length depends on the max position id.
|
| 454 |
+
rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
|
| 455 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=rotary_seq_len)
|
| 456 |
+
|
| 457 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 458 |
+
|
| 459 |
+
use_sliding_windows = (
|
| 460 |
+
_flash_supports_window_size
|
| 461 |
+
and getattr(self.config, "sliding_window", None) is not None
|
| 462 |
+
and kv_seq_len > self.config.sliding_window
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
if past_key_value is not None:
|
| 466 |
+
# Activate slicing cache only if the config has a value `sliding_windows` attribute
|
| 467 |
+
cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
|
| 468 |
+
if (
|
| 469 |
+
getattr(self.config, "sliding_window", None) is not None
|
| 470 |
+
and kv_seq_len > self.config.sliding_window
|
| 471 |
+
and cache_has_contents
|
| 472 |
+
):
|
| 473 |
+
slicing_tokens = 1 - self.config.sliding_window
|
| 474 |
+
|
| 475 |
+
past_key = past_key_value[self.layer_idx][0]
|
| 476 |
+
past_value = past_key_value[self.layer_idx][1]
|
| 477 |
+
|
| 478 |
+
past_key = past_key[:, :, slicing_tokens:, :].contiguous()
|
| 479 |
+
past_value = past_value[:, :, slicing_tokens:, :].contiguous()
|
| 480 |
+
|
| 481 |
+
if past_key.shape[-2] != self.config.sliding_window - 1:
|
| 482 |
+
raise ValueError(
|
| 483 |
+
f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
|
| 484 |
+
f" {past_key.shape}"
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
if attention_mask is not None:
|
| 488 |
+
attention_mask = attention_mask[:, slicing_tokens:]
|
| 489 |
+
attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
|
| 490 |
+
|
| 491 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 492 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 493 |
+
|
| 494 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 495 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 496 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 497 |
+
|
| 498 |
+
attn_dropout = self.attention_dropout if self.training else 0.0
|
| 499 |
+
|
| 500 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
| 501 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
| 502 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
| 503 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
| 504 |
+
# in fp32.
|
| 505 |
+
|
| 506 |
+
if query_states.dtype == torch.float32:
|
| 507 |
+
if torch.is_autocast_enabled():
|
| 508 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
| 509 |
+
# Handle the case where the model is quantized
|
| 510 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
| 511 |
+
target_dtype = self.config._pre_quantization_dtype
|
| 512 |
+
else:
|
| 513 |
+
target_dtype = self.qkv_proj.weight.dtype
|
| 514 |
+
|
| 515 |
+
logger.warning_once(
|
| 516 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
| 517 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
| 518 |
+
f" {target_dtype}."
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
query_states = query_states.to(target_dtype)
|
| 522 |
+
key_states = key_states.to(target_dtype)
|
| 523 |
+
value_states = value_states.to(target_dtype)
|
| 524 |
+
|
| 525 |
+
# Reashape to the expected shape for Flash Attention
|
| 526 |
+
query_states = query_states.transpose(1, 2)
|
| 527 |
+
key_states = key_states.transpose(1, 2)
|
| 528 |
+
value_states = value_states.transpose(1, 2)
|
| 529 |
+
|
| 530 |
+
attn_output = self._flash_attention_forward(
|
| 531 |
+
query_states,
|
| 532 |
+
key_states,
|
| 533 |
+
value_states,
|
| 534 |
+
attention_mask,
|
| 535 |
+
q_len,
|
| 536 |
+
dropout=attn_dropout,
|
| 537 |
+
use_sliding_windows=use_sliding_windows,
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
| 541 |
+
attn_output = self.o_proj(attn_output)
|
| 542 |
+
|
| 543 |
+
if not output_attentions:
|
| 544 |
+
attn_weights = None
|
| 545 |
+
|
| 546 |
+
return attn_output, attn_weights, past_key_value
|
| 547 |
+
|
| 548 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._flash_attention_forward
|
| 549 |
+
def _flash_attention_forward(
|
| 550 |
+
self,
|
| 551 |
+
query_states,
|
| 552 |
+
key_states,
|
| 553 |
+
value_states,
|
| 554 |
+
attention_mask,
|
| 555 |
+
query_length,
|
| 556 |
+
dropout=0.0,
|
| 557 |
+
softmax_scale=None,
|
| 558 |
+
use_sliding_windows=False,
|
| 559 |
+
):
|
| 560 |
+
"""
|
| 561 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
| 562 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
| 563 |
+
|
| 564 |
+
Args:
|
| 565 |
+
query_states (`torch.Tensor`):
|
| 566 |
+
Input query states to be passed to Flash Attention API
|
| 567 |
+
key_states (`torch.Tensor`):
|
| 568 |
+
Input key states to be passed to Flash Attention API
|
| 569 |
+
value_states (`torch.Tensor`):
|
| 570 |
+
Input value states to be passed to Flash Attention API
|
| 571 |
+
attention_mask (`torch.Tensor`):
|
| 572 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
| 573 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
| 574 |
+
dropout (`float`):
|
| 575 |
+
Attention dropout
|
| 576 |
+
softmax_scale (`float`, *optional*):
|
| 577 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
| 578 |
+
use_sliding_windows (`bool`, *optional*):
|
| 579 |
+
Whether to activate sliding window attention.
|
| 580 |
+
"""
|
| 581 |
+
if not self._flash_attn_uses_top_left_mask:
|
| 582 |
+
causal = self.is_causal
|
| 583 |
+
else:
|
| 584 |
+
# 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__.
|
| 585 |
+
causal = self.is_causal and query_length != 1
|
| 586 |
+
|
| 587 |
+
# Contains at least one padding token in the sequence
|
| 588 |
+
if attention_mask is not None:
|
| 589 |
+
batch_size = query_states.shape[0]
|
| 590 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
| 591 |
+
query_states, key_states, value_states, attention_mask, query_length
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
| 595 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
| 596 |
+
|
| 597 |
+
if not use_sliding_windows:
|
| 598 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 599 |
+
query_states,
|
| 600 |
+
key_states,
|
| 601 |
+
value_states,
|
| 602 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 603 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 604 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 605 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 606 |
+
dropout_p=dropout,
|
| 607 |
+
softmax_scale=softmax_scale,
|
| 608 |
+
causal=causal,
|
| 609 |
+
)
|
| 610 |
+
else:
|
| 611 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 612 |
+
query_states,
|
| 613 |
+
key_states,
|
| 614 |
+
value_states,
|
| 615 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 616 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 617 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 618 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 619 |
+
dropout_p=dropout,
|
| 620 |
+
softmax_scale=softmax_scale,
|
| 621 |
+
causal=causal,
|
| 622 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 623 |
+
)
|
| 624 |
+
|
| 625 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
| 626 |
+
else:
|
| 627 |
+
if not use_sliding_windows:
|
| 628 |
+
attn_output = flash_attn_func(
|
| 629 |
+
query_states,
|
| 630 |
+
key_states,
|
| 631 |
+
value_states,
|
| 632 |
+
dropout,
|
| 633 |
+
softmax_scale=softmax_scale,
|
| 634 |
+
causal=causal,
|
| 635 |
+
)
|
| 636 |
+
else:
|
| 637 |
+
attn_output = flash_attn_func(
|
| 638 |
+
query_states,
|
| 639 |
+
key_states,
|
| 640 |
+
value_states,
|
| 641 |
+
dropout,
|
| 642 |
+
softmax_scale=softmax_scale,
|
| 643 |
+
causal=causal,
|
| 644 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
return attn_output
|
| 648 |
+
|
| 649 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
|
| 650 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
| 651 |
+
batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
|
| 652 |
+
|
| 653 |
+
# On the first iteration we need to properly re-create the padding mask
|
| 654 |
+
# by slicing it on the proper place
|
| 655 |
+
if kv_seq_len != attention_mask.shape[-1]:
|
| 656 |
+
attention_mask_num_tokens = attention_mask.shape[-1]
|
| 657 |
+
attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
|
| 658 |
+
|
| 659 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
| 660 |
+
|
| 661 |
+
key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 662 |
+
value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 663 |
+
|
| 664 |
+
if query_length == kv_seq_len:
|
| 665 |
+
query_layer = index_first_axis(
|
| 666 |
+
query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
|
| 667 |
+
)
|
| 668 |
+
cu_seqlens_q = cu_seqlens_k
|
| 669 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
| 670 |
+
indices_q = indices_k
|
| 671 |
+
elif query_length == 1:
|
| 672 |
+
max_seqlen_in_batch_q = 1
|
| 673 |
+
cu_seqlens_q = torch.arange(
|
| 674 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
| 675 |
+
) # There is a memcpy here, that is very bad.
|
| 676 |
+
indices_q = cu_seqlens_q[:-1]
|
| 677 |
+
query_layer = query_layer.squeeze(1)
|
| 678 |
+
else:
|
| 679 |
+
# The -q_len: slice assumes left padding.
|
| 680 |
+
attention_mask = attention_mask[:, -query_length:]
|
| 681 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
| 682 |
+
|
| 683 |
+
return (
|
| 684 |
+
query_layer,
|
| 685 |
+
key_layer,
|
| 686 |
+
value_layer,
|
| 687 |
+
indices_q,
|
| 688 |
+
(cu_seqlens_q, cu_seqlens_k),
|
| 689 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
| 690 |
+
)
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
# copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Phi3
|
| 694 |
+
# TODO @Arthur no longer copied from LLama after static cache
|
| 695 |
+
class Phi3SdpaAttention(Phi3Attention):
|
| 696 |
+
"""
|
| 697 |
+
Phi3 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
| 698 |
+
`Phi3Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
| 699 |
+
SDPA API.
|
| 700 |
+
"""
|
| 701 |
+
|
| 702 |
+
# Adapted from Phi3Attention.forward
|
| 703 |
+
def forward(
|
| 704 |
+
self,
|
| 705 |
+
hidden_states: torch.Tensor,
|
| 706 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 707 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 708 |
+
past_key_value: Optional[Cache] = None,
|
| 709 |
+
output_attentions: bool = False,
|
| 710 |
+
use_cache: bool = False,
|
| 711 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 712 |
+
if output_attentions:
|
| 713 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
| 714 |
+
logger.warning_once(
|
| 715 |
+
"Phi3Model is using Phi3SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
| 716 |
+
'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.'
|
| 717 |
+
)
|
| 718 |
+
return super().forward(
|
| 719 |
+
hidden_states=hidden_states,
|
| 720 |
+
attention_mask=attention_mask,
|
| 721 |
+
position_ids=position_ids,
|
| 722 |
+
past_key_value=past_key_value,
|
| 723 |
+
output_attentions=output_attentions,
|
| 724 |
+
use_cache=use_cache,
|
| 725 |
+
)
|
| 726 |
+
|
| 727 |
+
bsz, q_len, _ = hidden_states.size()
|
| 728 |
+
|
| 729 |
+
qkv = self.qkv_proj(hidden_states)
|
| 730 |
+
query_pos = self.num_heads * self.head_dim
|
| 731 |
+
query_states = qkv[..., :query_pos]
|
| 732 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 733 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 734 |
+
|
| 735 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 736 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 737 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 738 |
+
|
| 739 |
+
kv_seq_len = key_states.shape[-2]
|
| 740 |
+
if past_key_value is not None:
|
| 741 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 742 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 743 |
+
|
| 744 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 745 |
+
|
| 746 |
+
if past_key_value is not None:
|
| 747 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 748 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 749 |
+
|
| 750 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 751 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 752 |
+
|
| 753 |
+
if attention_mask is not None:
|
| 754 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 755 |
+
raise ValueError(
|
| 756 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 757 |
+
)
|
| 758 |
+
|
| 759 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
| 760 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
| 761 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
| 762 |
+
query_states = query_states.contiguous()
|
| 763 |
+
key_states = key_states.contiguous()
|
| 764 |
+
value_states = value_states.contiguous()
|
| 765 |
+
|
| 766 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
| 767 |
+
query_states,
|
| 768 |
+
key_states,
|
| 769 |
+
value_states,
|
| 770 |
+
attn_mask=attention_mask,
|
| 771 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
| 772 |
+
# 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.
|
| 773 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
| 774 |
+
)
|
| 775 |
+
|
| 776 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 777 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
| 778 |
+
|
| 779 |
+
attn_output = self.o_proj(attn_output)
|
| 780 |
+
|
| 781 |
+
return attn_output, None, past_key_value
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
PHI3_ATTENTION_CLASSES = {
|
| 785 |
+
"eager": Phi3Attention,
|
| 786 |
+
"flash_attention_2": Phi3FlashAttention2,
|
| 787 |
+
"sdpa": Phi3SdpaAttention,
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
class Phi3DecoderLayer(nn.Module):
|
| 792 |
+
def __init__(self, config: Phi3Config, layer_idx: int):
|
| 793 |
+
super().__init__()
|
| 794 |
+
|
| 795 |
+
self.config = config
|
| 796 |
+
self.self_attn = PHI3_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
|
| 797 |
+
|
| 798 |
+
self.mlp = Phi3MLP(config)
|
| 799 |
+
self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 800 |
+
|
| 801 |
+
self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
|
| 802 |
+
self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
|
| 803 |
+
self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 804 |
+
|
| 805 |
+
def forward(
|
| 806 |
+
self,
|
| 807 |
+
hidden_states: torch.Tensor,
|
| 808 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 809 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 810 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
| 811 |
+
output_attentions: Optional[bool] = False,
|
| 812 |
+
use_cache: Optional[bool] = False,
|
| 813 |
+
**kwargs,
|
| 814 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 815 |
+
if "padding_mask" in kwargs:
|
| 816 |
+
warnings.warn(
|
| 817 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 818 |
+
)
|
| 819 |
+
"""
|
| 820 |
+
Args:
|
| 821 |
+
hidden_states (`torch.FloatTensor`):
|
| 822 |
+
input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 823 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 824 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 825 |
+
position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
|
| 826 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
|
| 827 |
+
`[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
| 828 |
+
output_attentions (`bool`, *optional*):
|
| 829 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 830 |
+
returned tensors for more detail.
|
| 831 |
+
use_cache (`bool`, *optional*):
|
| 832 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 833 |
+
(see `past_key_values`).
|
| 834 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
| 835 |
+
"""
|
| 836 |
+
|
| 837 |
+
residual = hidden_states
|
| 838 |
+
|
| 839 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 840 |
+
|
| 841 |
+
# Self Attention
|
| 842 |
+
attn_outputs, self_attn_weights, present_key_value = self.self_attn(
|
| 843 |
+
hidden_states=hidden_states,
|
| 844 |
+
attention_mask=attention_mask,
|
| 845 |
+
position_ids=position_ids,
|
| 846 |
+
past_key_value=past_key_value,
|
| 847 |
+
output_attentions=output_attentions,
|
| 848 |
+
use_cache=use_cache,
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
hidden_states = residual + self.resid_attn_dropout(attn_outputs)
|
| 852 |
+
|
| 853 |
+
residual = hidden_states
|
| 854 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 855 |
+
hidden_states = self.mlp(hidden_states)
|
| 856 |
+
hidden_states = residual + self.resid_mlp_dropout(hidden_states)
|
| 857 |
+
|
| 858 |
+
outputs = (hidden_states,)
|
| 859 |
+
|
| 860 |
+
if output_attentions:
|
| 861 |
+
outputs += (self_attn_weights,)
|
| 862 |
+
|
| 863 |
+
if use_cache:
|
| 864 |
+
outputs += (present_key_value,)
|
| 865 |
+
|
| 866 |
+
return outputs
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
PHI3_START_DOCSTRING = r"""
|
| 870 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 871 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 872 |
+
etc.)
|
| 873 |
+
|
| 874 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 875 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 876 |
+
and behavior.
|
| 877 |
+
|
| 878 |
+
Parameters:
|
| 879 |
+
config ([`Phi3Config`]):
|
| 880 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 881 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 882 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 883 |
+
"""
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
@add_start_docstrings(
|
| 887 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 888 |
+
PHI3_START_DOCSTRING,
|
| 889 |
+
)
|
| 890 |
+
class Phi3PreTrainedModel(PreTrainedModel):
|
| 891 |
+
config_class = Phi3Config
|
| 892 |
+
base_model_prefix = "model"
|
| 893 |
+
supports_gradient_checkpointing = True
|
| 894 |
+
_no_split_modules = ["Phi3DecoderLayer"]
|
| 895 |
+
_skip_keys_device_placement = "past_key_values"
|
| 896 |
+
_supports_flash_attn_2 = True
|
| 897 |
+
_supports_sdpa = False
|
| 898 |
+
_supports_cache_class = True
|
| 899 |
+
|
| 900 |
+
_version = "0.0.5"
|
| 901 |
+
|
| 902 |
+
def _init_weights(self, module):
|
| 903 |
+
std = self.config.initializer_range
|
| 904 |
+
if isinstance(module, nn.Linear):
|
| 905 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 906 |
+
if module.bias is not None:
|
| 907 |
+
module.bias.data.zero_()
|
| 908 |
+
elif isinstance(module, nn.Embedding):
|
| 909 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 910 |
+
if module.padding_idx is not None:
|
| 911 |
+
module.weight.data[module.padding_idx].zero_()
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
PHI3_INPUTS_DOCSTRING = r"""
|
| 915 |
+
Args:
|
| 916 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 917 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 918 |
+
it.
|
| 919 |
+
|
| 920 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 921 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 922 |
+
|
| 923 |
+
[What are input IDs?](../glossary#input-ids)
|
| 924 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 925 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 926 |
+
|
| 927 |
+
- 1 for tokens that are **not masked**,
|
| 928 |
+
- 0 for tokens that are **masked**.
|
| 929 |
+
|
| 930 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 931 |
+
|
| 932 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 933 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 934 |
+
|
| 935 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
| 936 |
+
`past_key_values`).
|
| 937 |
+
|
| 938 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 939 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 940 |
+
information on the default strategy.
|
| 941 |
+
|
| 942 |
+
- 1 indicates the head is **not masked**,
|
| 943 |
+
- 0 indicates the head is **masked**.
|
| 944 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 945 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 946 |
+
config.n_positions - 1]`.
|
| 947 |
+
|
| 948 |
+
[What are position IDs?](../glossary#position-ids)
|
| 949 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 950 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 951 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 952 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 953 |
+
|
| 954 |
+
Two formats are allowed:
|
| 955 |
+
- a [`~cache_utils.Cache`] instance;
|
| 956 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 957 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 958 |
+
cache format.
|
| 959 |
+
|
| 960 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 961 |
+
legacy cache format will be returned.
|
| 962 |
+
|
| 963 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 964 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 965 |
+
of shape `(batch_size, sequence_length)`.
|
| 966 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 967 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 968 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 969 |
+
model's internal embedding lookup matrix.
|
| 970 |
+
use_cache (`bool`, *optional*):
|
| 971 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 972 |
+
`past_key_values`).
|
| 973 |
+
output_attentions (`bool`, *optional*):
|
| 974 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 975 |
+
tensors for more detail.
|
| 976 |
+
output_hidden_states (`bool`, *optional*):
|
| 977 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 978 |
+
more detail.
|
| 979 |
+
return_dict (`bool`, *optional*):
|
| 980 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 981 |
+
"""
|
| 982 |
+
|
| 983 |
+
|
| 984 |
+
@add_start_docstrings(
|
| 985 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 986 |
+
PHI3_START_DOCSTRING,
|
| 987 |
+
)
|
| 988 |
+
class Phi3Model(Phi3PreTrainedModel):
|
| 989 |
+
"""
|
| 990 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Phi3DecoderLayer`]
|
| 991 |
+
|
| 992 |
+
Args:
|
| 993 |
+
config: Phi3Config
|
| 994 |
+
"""
|
| 995 |
+
|
| 996 |
+
def __init__(self, config: Phi3Config):
|
| 997 |
+
super().__init__(config)
|
| 998 |
+
self.padding_idx = config.pad_token_id
|
| 999 |
+
self.vocab_size = config.vocab_size
|
| 1000 |
+
|
| 1001 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 1002 |
+
self.embed_dropout = nn.Dropout(config.embd_pdrop)
|
| 1003 |
+
self.layers = nn.ModuleList(
|
| 1004 |
+
[Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 1005 |
+
)
|
| 1006 |
+
self._attn_implementation = config._attn_implementation
|
| 1007 |
+
self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 1008 |
+
|
| 1009 |
+
self.gradient_checkpointing = False
|
| 1010 |
+
# Initialize weights and apply final processing
|
| 1011 |
+
self.post_init()
|
| 1012 |
+
|
| 1013 |
+
def get_input_embeddings(self):
|
| 1014 |
+
return self.embed_tokens
|
| 1015 |
+
|
| 1016 |
+
def set_input_embeddings(self, value):
|
| 1017 |
+
self.embed_tokens = value
|
| 1018 |
+
|
| 1019 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1020 |
+
def forward(
|
| 1021 |
+
self,
|
| 1022 |
+
input_ids: torch.LongTensor = None,
|
| 1023 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1024 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1025 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1026 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1027 |
+
use_cache: Optional[bool] = None,
|
| 1028 |
+
output_attentions: Optional[bool] = None,
|
| 1029 |
+
output_hidden_states: Optional[bool] = None,
|
| 1030 |
+
return_dict: Optional[bool] = None,
|
| 1031 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 1032 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1033 |
+
output_hidden_states = (
|
| 1034 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1035 |
+
)
|
| 1036 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1037 |
+
|
| 1038 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1039 |
+
|
| 1040 |
+
# retrieve input_ids and inputs_embeds
|
| 1041 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 1042 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
| 1043 |
+
elif input_ids is not None:
|
| 1044 |
+
batch_size, seq_length = input_ids.shape[:2]
|
| 1045 |
+
elif inputs_embeds is not None:
|
| 1046 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
| 1047 |
+
else:
|
| 1048 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
| 1049 |
+
|
| 1050 |
+
past_key_values_length = 0
|
| 1051 |
+
|
| 1052 |
+
if self.gradient_checkpointing and self.training:
|
| 1053 |
+
if use_cache:
|
| 1054 |
+
logger.warning_once(
|
| 1055 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
| 1056 |
+
)
|
| 1057 |
+
use_cache = False
|
| 1058 |
+
|
| 1059 |
+
if use_cache:
|
| 1060 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
| 1061 |
+
if use_legacy_cache:
|
| 1062 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
| 1063 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
| 1064 |
+
|
| 1065 |
+
if position_ids is None:
|
| 1066 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
| 1067 |
+
position_ids = torch.arange(
|
| 1068 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
| 1069 |
+
)
|
| 1070 |
+
position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
|
| 1071 |
+
else:
|
| 1072 |
+
position_ids = position_ids.view(-1, seq_length).long()
|
| 1073 |
+
|
| 1074 |
+
if inputs_embeds is None:
|
| 1075 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 1076 |
+
|
| 1077 |
+
if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
|
| 1078 |
+
is_padding_right = attention_mask[:, -1].sum().item() != batch_size
|
| 1079 |
+
if is_padding_right:
|
| 1080 |
+
raise ValueError(
|
| 1081 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 1082 |
+
" this may lead to unexpected behaviour for Flash Attention version of Phi3. Make sure to "
|
| 1083 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 1084 |
+
)
|
| 1085 |
+
|
| 1086 |
+
if self._attn_implementation == "flash_attention_2":
|
| 1087 |
+
# 2d mask is passed through the layers
|
| 1088 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
| 1089 |
+
else:
|
| 1090 |
+
# 4d mask is passed through the layers
|
| 1091 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
| 1092 |
+
attention_mask,
|
| 1093 |
+
(batch_size, seq_length),
|
| 1094 |
+
inputs_embeds,
|
| 1095 |
+
past_key_values_length,
|
| 1096 |
+
sliding_window=self.config.sliding_window,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
hidden_states = inputs_embeds
|
| 1100 |
+
|
| 1101 |
+
# decoder layers
|
| 1102 |
+
all_hidden_states = () if output_hidden_states else None
|
| 1103 |
+
all_self_attns = () if output_attentions else None
|
| 1104 |
+
next_decoder_cache = None
|
| 1105 |
+
|
| 1106 |
+
for decoder_layer in self.layers:
|
| 1107 |
+
if output_hidden_states:
|
| 1108 |
+
all_hidden_states += (hidden_states,)
|
| 1109 |
+
|
| 1110 |
+
if self.gradient_checkpointing and self.training:
|
| 1111 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 1112 |
+
decoder_layer.__call__,
|
| 1113 |
+
hidden_states,
|
| 1114 |
+
attention_mask,
|
| 1115 |
+
position_ids,
|
| 1116 |
+
past_key_values,
|
| 1117 |
+
output_attentions,
|
| 1118 |
+
use_cache,
|
| 1119 |
+
)
|
| 1120 |
+
else:
|
| 1121 |
+
layer_outputs = decoder_layer(
|
| 1122 |
+
hidden_states,
|
| 1123 |
+
attention_mask=attention_mask,
|
| 1124 |
+
position_ids=position_ids,
|
| 1125 |
+
past_key_value=past_key_values,
|
| 1126 |
+
output_attentions=output_attentions,
|
| 1127 |
+
use_cache=use_cache,
|
| 1128 |
+
)
|
| 1129 |
+
|
| 1130 |
+
hidden_states = layer_outputs[0]
|
| 1131 |
+
|
| 1132 |
+
if use_cache:
|
| 1133 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
| 1134 |
+
|
| 1135 |
+
if output_attentions:
|
| 1136 |
+
all_self_attns += (layer_outputs[1],)
|
| 1137 |
+
|
| 1138 |
+
hidden_states = self.norm(hidden_states)
|
| 1139 |
+
|
| 1140 |
+
# add hidden states from the last decoder layer
|
| 1141 |
+
if output_hidden_states:
|
| 1142 |
+
all_hidden_states += (hidden_states,)
|
| 1143 |
+
|
| 1144 |
+
next_cache = None
|
| 1145 |
+
if use_cache:
|
| 1146 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
| 1147 |
+
if not return_dict:
|
| 1148 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
| 1149 |
+
return BaseModelOutputWithPast(
|
| 1150 |
+
last_hidden_state=hidden_states,
|
| 1151 |
+
past_key_values=next_cache,
|
| 1152 |
+
hidden_states=all_hidden_states,
|
| 1153 |
+
attentions=all_self_attns,
|
| 1154 |
+
)
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
class Phi3ForCausalLM(Phi3PreTrainedModel):
|
| 1158 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 1159 |
+
|
| 1160 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi3
|
| 1161 |
+
def __init__(self, config):
|
| 1162 |
+
super().__init__(config)
|
| 1163 |
+
self.model = Phi3Model(config)
|
| 1164 |
+
self.vocab_size = config.vocab_size
|
| 1165 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1166 |
+
|
| 1167 |
+
# Initialize weights and apply final processing
|
| 1168 |
+
self.post_init()
|
| 1169 |
+
|
| 1170 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
|
| 1171 |
+
def get_input_embeddings(self):
|
| 1172 |
+
return self.model.embed_tokens
|
| 1173 |
+
|
| 1174 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
|
| 1175 |
+
def set_input_embeddings(self, value):
|
| 1176 |
+
self.model.embed_tokens = value
|
| 1177 |
+
|
| 1178 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
|
| 1179 |
+
def get_output_embeddings(self):
|
| 1180 |
+
return self.lm_head
|
| 1181 |
+
|
| 1182 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
|
| 1183 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1184 |
+
self.lm_head = new_embeddings
|
| 1185 |
+
|
| 1186 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
|
| 1187 |
+
def set_decoder(self, decoder):
|
| 1188 |
+
self.model = decoder
|
| 1189 |
+
|
| 1190 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
|
| 1191 |
+
def get_decoder(self):
|
| 1192 |
+
return self.model
|
| 1193 |
+
|
| 1194 |
+
# Ignore copy
|
| 1195 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1196 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
| 1197 |
+
def forward(
|
| 1198 |
+
self,
|
| 1199 |
+
input_ids: torch.LongTensor = None,
|
| 1200 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1201 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1202 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1203 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1204 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1205 |
+
use_cache: Optional[bool] = None,
|
| 1206 |
+
output_attentions: Optional[bool] = None,
|
| 1207 |
+
output_hidden_states: Optional[bool] = None,
|
| 1208 |
+
return_dict: Optional[bool] = None,
|
| 1209 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1210 |
+
r"""
|
| 1211 |
+
Args:
|
| 1212 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1213 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1214 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1215 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1216 |
+
|
| 1217 |
+
Returns:
|
| 1218 |
+
|
| 1219 |
+
Example:
|
| 1220 |
+
|
| 1221 |
+
```python
|
| 1222 |
+
>>> from transformers import AutoTokenizer, Phi3ForCausalLM
|
| 1223 |
+
|
| 1224 |
+
>>> model = Phi3ForCausalLM.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1225 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1226 |
+
|
| 1227 |
+
>>> prompt = "This is an example script ."
|
| 1228 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1229 |
+
|
| 1230 |
+
>>> # Generate
|
| 1231 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1232 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1233 |
+
'This is an example script .\n Certainly! Below is a sample script that demonstrates a simple task, such as calculating the sum'
|
| 1234 |
+
```"""
|
| 1235 |
+
|
| 1236 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1237 |
+
output_hidden_states = (
|
| 1238 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1239 |
+
)
|
| 1240 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1241 |
+
|
| 1242 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1243 |
+
outputs = self.model(
|
| 1244 |
+
input_ids=input_ids,
|
| 1245 |
+
attention_mask=attention_mask,
|
| 1246 |
+
position_ids=position_ids,
|
| 1247 |
+
past_key_values=past_key_values,
|
| 1248 |
+
inputs_embeds=inputs_embeds,
|
| 1249 |
+
use_cache=use_cache,
|
| 1250 |
+
output_attentions=output_attentions,
|
| 1251 |
+
output_hidden_states=output_hidden_states,
|
| 1252 |
+
return_dict=return_dict,
|
| 1253 |
+
)
|
| 1254 |
+
|
| 1255 |
+
hidden_states = outputs[0]
|
| 1256 |
+
logits = self.lm_head(hidden_states)
|
| 1257 |
+
logits = logits.float()
|
| 1258 |
+
|
| 1259 |
+
loss = None
|
| 1260 |
+
if labels is not None:
|
| 1261 |
+
# Shift so that tokens < n predict n
|
| 1262 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 1263 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 1264 |
+
# Flatten the tokens
|
| 1265 |
+
loss_fct = CrossEntropyLoss()
|
| 1266 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
| 1267 |
+
shift_labels = shift_labels.view(-1)
|
| 1268 |
+
# Enable model parallelism
|
| 1269 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 1270 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 1271 |
+
|
| 1272 |
+
if not return_dict:
|
| 1273 |
+
output = (logits,) + outputs[1:]
|
| 1274 |
+
return (loss,) + output if loss is not None else output
|
| 1275 |
+
|
| 1276 |
+
return CausalLMOutputWithPast(
|
| 1277 |
+
loss=loss,
|
| 1278 |
+
logits=logits,
|
| 1279 |
+
past_key_values=outputs.past_key_values,
|
| 1280 |
+
hidden_states=outputs.hidden_states,
|
| 1281 |
+
attentions=outputs.attentions,
|
| 1282 |
+
)
|
| 1283 |
+
|
| 1284 |
+
# Copied from transformers.models.persimmon.modeling_persimmon.PersimmonForCausalLM.prepare_inputs_for_generation
|
| 1285 |
+
def prepare_inputs_for_generation(
|
| 1286 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
|
| 1287 |
+
):
|
| 1288 |
+
if past_key_values is not None:
|
| 1289 |
+
if isinstance(past_key_values, Cache):
|
| 1290 |
+
cache_length = past_key_values.get_seq_length()
|
| 1291 |
+
past_length = past_key_values.seen_tokens
|
| 1292 |
+
max_cache_length = past_key_values.get_max_length()
|
| 1293 |
+
else:
|
| 1294 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
| 1295 |
+
max_cache_length = None
|
| 1296 |
+
|
| 1297 |
+
# Keep only the unprocessed tokens:
|
| 1298 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
| 1299 |
+
# some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
|
| 1300 |
+
# input)
|
| 1301 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
| 1302 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
| 1303 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
| 1304 |
+
# input_ids based on the past_length.
|
| 1305 |
+
elif past_length < input_ids.shape[1]:
|
| 1306 |
+
input_ids = input_ids[:, past_length:]
|
| 1307 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
| 1308 |
+
|
| 1309 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
| 1310 |
+
if (
|
| 1311 |
+
max_cache_length is not None
|
| 1312 |
+
and attention_mask is not None
|
| 1313 |
+
and cache_length + input_ids.shape[1] > max_cache_length
|
| 1314 |
+
):
|
| 1315 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
| 1316 |
+
|
| 1317 |
+
position_ids = kwargs.get("position_ids", None)
|
| 1318 |
+
if attention_mask is not None and position_ids is None:
|
| 1319 |
+
# create position_ids on the fly for batch generation
|
| 1320 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 1321 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 1322 |
+
if past_key_values:
|
| 1323 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
| 1324 |
+
|
| 1325 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
| 1326 |
+
if inputs_embeds is not None and past_key_values is None:
|
| 1327 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
| 1328 |
+
else:
|
| 1329 |
+
model_inputs = {"input_ids": input_ids}
|
| 1330 |
+
|
| 1331 |
+
model_inputs.update(
|
| 1332 |
+
{
|
| 1333 |
+
"position_ids": position_ids,
|
| 1334 |
+
"past_key_values": past_key_values,
|
| 1335 |
+
"use_cache": kwargs.get("use_cache"),
|
| 1336 |
+
"attention_mask": attention_mask,
|
| 1337 |
+
}
|
| 1338 |
+
)
|
| 1339 |
+
return model_inputs
|
| 1340 |
+
|
| 1341 |
+
@staticmethod
|
| 1342 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
|
| 1343 |
+
def _reorder_cache(past_key_values, beam_idx):
|
| 1344 |
+
reordered_past = ()
|
| 1345 |
+
for layer_past in past_key_values:
|
| 1346 |
+
reordered_past += (
|
| 1347 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
| 1348 |
+
)
|
| 1349 |
+
return reordered_past
|
| 1350 |
+
|
| 1351 |
+
|
| 1352 |
+
@add_start_docstrings(
|
| 1353 |
+
"""
|
| 1354 |
+
The [`Phi3Model`] with a sequence classification head on top (linear layer).
|
| 1355 |
+
|
| 1356 |
+
[`Phi3ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
| 1357 |
+
(e.g. GPT-2) do.
|
| 1358 |
+
|
| 1359 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
| 1360 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
| 1361 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
| 1362 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
| 1363 |
+
each row of the batch).
|
| 1364 |
+
""",
|
| 1365 |
+
PHI3_START_DOCSTRING,
|
| 1366 |
+
)
|
| 1367 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->Phi3, LLAMA->PHI3, self.transformer->self.model, transformer_outputs->model_outputs
|
| 1368 |
+
class Phi3ForSequenceClassification(Phi3PreTrainedModel):
|
| 1369 |
+
def __init__(self, config):
|
| 1370 |
+
super().__init__(config)
|
| 1371 |
+
self.num_labels = config.num_labels
|
| 1372 |
+
self.model = Phi3Model(config)
|
| 1373 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
| 1374 |
+
|
| 1375 |
+
# Initialize weights and apply final processing
|
| 1376 |
+
self.post_init()
|
| 1377 |
+
|
| 1378 |
+
def get_input_embeddings(self):
|
| 1379 |
+
return self.model.embed_tokens
|
| 1380 |
+
|
| 1381 |
+
def set_input_embeddings(self, value):
|
| 1382 |
+
self.model.embed_tokens = value
|
| 1383 |
+
|
| 1384 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1385 |
+
def forward(
|
| 1386 |
+
self,
|
| 1387 |
+
input_ids: torch.LongTensor = None,
|
| 1388 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1389 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1390 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1391 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1392 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1393 |
+
use_cache: Optional[bool] = None,
|
| 1394 |
+
output_attentions: Optional[bool] = None,
|
| 1395 |
+
output_hidden_states: Optional[bool] = None,
|
| 1396 |
+
return_dict: Optional[bool] = None,
|
| 1397 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
| 1398 |
+
r"""
|
| 1399 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1400 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1401 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1402 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1403 |
+
"""
|
| 1404 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1405 |
+
|
| 1406 |
+
model_outputs = self.model(
|
| 1407 |
+
input_ids,
|
| 1408 |
+
attention_mask=attention_mask,
|
| 1409 |
+
position_ids=position_ids,
|
| 1410 |
+
past_key_values=past_key_values,
|
| 1411 |
+
inputs_embeds=inputs_embeds,
|
| 1412 |
+
use_cache=use_cache,
|
| 1413 |
+
output_attentions=output_attentions,
|
| 1414 |
+
output_hidden_states=output_hidden_states,
|
| 1415 |
+
return_dict=return_dict,
|
| 1416 |
+
)
|
| 1417 |
+
hidden_states = model_outputs[0]
|
| 1418 |
+
logits = self.score(hidden_states)
|
| 1419 |
+
|
| 1420 |
+
if input_ids is not None:
|
| 1421 |
+
batch_size = input_ids.shape[0]
|
| 1422 |
+
else:
|
| 1423 |
+
batch_size = inputs_embeds.shape[0]
|
| 1424 |
+
|
| 1425 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
| 1426 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
| 1427 |
+
if self.config.pad_token_id is None:
|
| 1428 |
+
sequence_lengths = -1
|
| 1429 |
+
else:
|
| 1430 |
+
if input_ids is not None:
|
| 1431 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
| 1432 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
| 1433 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
| 1434 |
+
sequence_lengths = sequence_lengths.to(logits.device)
|
| 1435 |
+
else:
|
| 1436 |
+
sequence_lengths = -1
|
| 1437 |
+
|
| 1438 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
| 1439 |
+
|
| 1440 |
+
loss = None
|
| 1441 |
+
if labels is not None:
|
| 1442 |
+
labels = labels.to(logits.device)
|
| 1443 |
+
if self.config.problem_type is None:
|
| 1444 |
+
if self.num_labels == 1:
|
| 1445 |
+
self.config.problem_type = "regression"
|
| 1446 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 1447 |
+
self.config.problem_type = "single_label_classification"
|
| 1448 |
+
else:
|
| 1449 |
+
self.config.problem_type = "multi_label_classification"
|
| 1450 |
+
|
| 1451 |
+
if self.config.problem_type == "regression":
|
| 1452 |
+
loss_fct = MSELoss()
|
| 1453 |
+
if self.num_labels == 1:
|
| 1454 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
| 1455 |
+
else:
|
| 1456 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1457 |
+
elif self.config.problem_type == "single_label_classification":
|
| 1458 |
+
loss_fct = CrossEntropyLoss()
|
| 1459 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
| 1460 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 1461 |
+
loss_fct = BCEWithLogitsLoss()
|
| 1462 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1463 |
+
if not return_dict:
|
| 1464 |
+
output = (pooled_logits,) + model_outputs[1:]
|
| 1465 |
+
return ((loss,) + output) if loss is not None else output
|
| 1466 |
+
|
| 1467 |
+
return SequenceClassifierOutputWithPast(
|
| 1468 |
+
loss=loss,
|
| 1469 |
+
logits=pooled_logits,
|
| 1470 |
+
past_key_values=model_outputs.past_key_values,
|
| 1471 |
+
hidden_states=model_outputs.hidden_states,
|
| 1472 |
+
attentions=model_outputs.attentions,
|
| 1473 |
+
)
|
| 1474 |
+
|
| 1475 |
+
|
| 1476 |
+
@add_start_docstrings(
|
| 1477 |
+
"""
|
| 1478 |
+
[`Phi3Model`] with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
|
| 1479 |
+
Named-Entity-Recognition (NER) tasks.
|
| 1480 |
+
""",
|
| 1481 |
+
PHI3_START_DOCSTRING,
|
| 1482 |
+
)
|
| 1483 |
+
# Copied from transformers.models.mpt.modeling_mpt.MptForTokenClassification with Mpt->Phi3,MPT->PHI3,self.transformer->self.model,transformer_outputs->model_outputs
|
| 1484 |
+
class Phi3ForTokenClassification(Phi3PreTrainedModel):
|
| 1485 |
+
def __init__(self, config: Phi3Config):
|
| 1486 |
+
super().__init__(config)
|
| 1487 |
+
self.num_labels = config.num_labels
|
| 1488 |
+
|
| 1489 |
+
self.model = Phi3Model(config)
|
| 1490 |
+
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
|
| 1491 |
+
classifier_dropout = config.classifier_dropout
|
| 1492 |
+
elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
|
| 1493 |
+
classifier_dropout = config.hidden_dropout
|
| 1494 |
+
else:
|
| 1495 |
+
classifier_dropout = 0.1
|
| 1496 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
| 1497 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
| 1498 |
+
|
| 1499 |
+
# Initialize weights and apply final processing
|
| 1500 |
+
self.post_init()
|
| 1501 |
+
|
| 1502 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1503 |
+
@add_code_sample_docstrings(
|
| 1504 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 1505 |
+
output_type=TokenClassifierOutput,
|
| 1506 |
+
config_class=_CONFIG_FOR_DOC,
|
| 1507 |
+
)
|
| 1508 |
+
def forward(
|
| 1509 |
+
self,
|
| 1510 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1511 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
| 1512 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1513 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1514 |
+
labels: Optional[torch.Tensor] = None,
|
| 1515 |
+
use_cache: Optional[bool] = None,
|
| 1516 |
+
output_attentions: Optional[bool] = None,
|
| 1517 |
+
output_hidden_states: Optional[bool] = None,
|
| 1518 |
+
return_dict: Optional[bool] = None,
|
| 1519 |
+
**deprecated_arguments,
|
| 1520 |
+
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
| 1521 |
+
r"""
|
| 1522 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1523 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1524 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1525 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1526 |
+
"""
|
| 1527 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1528 |
+
|
| 1529 |
+
model_outputs = self.model(
|
| 1530 |
+
input_ids,
|
| 1531 |
+
past_key_values=past_key_values,
|
| 1532 |
+
attention_mask=attention_mask,
|
| 1533 |
+
inputs_embeds=inputs_embeds,
|
| 1534 |
+
use_cache=use_cache,
|
| 1535 |
+
output_attentions=output_attentions,
|
| 1536 |
+
output_hidden_states=output_hidden_states,
|
| 1537 |
+
return_dict=return_dict,
|
| 1538 |
+
)
|
| 1539 |
+
|
| 1540 |
+
hidden_states = model_outputs[0]
|
| 1541 |
+
hidden_states = self.dropout(hidden_states)
|
| 1542 |
+
logits = self.classifier(hidden_states)
|
| 1543 |
+
|
| 1544 |
+
loss = None
|
| 1545 |
+
if labels is not None:
|
| 1546 |
+
# move labels to correct device to enable model parallelism
|
| 1547 |
+
labels = labels.to(logits.device)
|
| 1548 |
+
batch_size, seq_length = labels.shape
|
| 1549 |
+
loss_fct = CrossEntropyLoss()
|
| 1550 |
+
loss = loss_fct(
|
| 1551 |
+
logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length)
|
| 1552 |
+
)
|
| 1553 |
+
|
| 1554 |
+
if not return_dict:
|
| 1555 |
+
output = (logits,) + model_outputs[2:]
|
| 1556 |
+
return ((loss,) + output) if loss is not None else output
|
| 1557 |
+
|
| 1558 |
+
return TokenClassifierOutput(
|
| 1559 |
+
loss=loss,
|
| 1560 |
+
logits=logits,
|
| 1561 |
+
hidden_states=model_outputs.hidden_states,
|
| 1562 |
+
attentions=model_outputs.attentions,
|
| 1563 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|endoftext|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|endoftext|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "<unk>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/tokenizer_config.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": null,
|
| 5 |
+
"added_tokens_decoder": {
|
| 6 |
+
"0": {
|
| 7 |
+
"content": "<unk>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false,
|
| 12 |
+
"special": true
|
| 13 |
+
},
|
| 14 |
+
"1": {
|
| 15 |
+
"content": "<s>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": false,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false,
|
| 20 |
+
"special": true
|
| 21 |
+
},
|
| 22 |
+
"2": {
|
| 23 |
+
"content": "</s>",
|
| 24 |
+
"lstrip": false,
|
| 25 |
+
"normalized": false,
|
| 26 |
+
"rstrip": true,
|
| 27 |
+
"single_word": false,
|
| 28 |
+
"special": false
|
| 29 |
+
},
|
| 30 |
+
"32000": {
|
| 31 |
+
"content": "<|endoftext|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false,
|
| 36 |
+
"special": true
|
| 37 |
+
},
|
| 38 |
+
"32001": {
|
| 39 |
+
"content": "<|assistant|>",
|
| 40 |
+
"lstrip": false,
|
| 41 |
+
"normalized": false,
|
| 42 |
+
"rstrip": true,
|
| 43 |
+
"single_word": false,
|
| 44 |
+
"special": true
|
| 45 |
+
},
|
| 46 |
+
"32002": {
|
| 47 |
+
"content": "<|placeholder1|>",
|
| 48 |
+
"lstrip": false,
|
| 49 |
+
"normalized": false,
|
| 50 |
+
"rstrip": true,
|
| 51 |
+
"single_word": false,
|
| 52 |
+
"special": true
|
| 53 |
+
},
|
| 54 |
+
"32003": {
|
| 55 |
+
"content": "<|placeholder2|>",
|
| 56 |
+
"lstrip": false,
|
| 57 |
+
"normalized": false,
|
| 58 |
+
"rstrip": true,
|
| 59 |
+
"single_word": false,
|
| 60 |
+
"special": true
|
| 61 |
+
},
|
| 62 |
+
"32004": {
|
| 63 |
+
"content": "<|placeholder3|>",
|
| 64 |
+
"lstrip": false,
|
| 65 |
+
"normalized": false,
|
| 66 |
+
"rstrip": true,
|
| 67 |
+
"single_word": false,
|
| 68 |
+
"special": true
|
| 69 |
+
},
|
| 70 |
+
"32005": {
|
| 71 |
+
"content": "<|placeholder4|>",
|
| 72 |
+
"lstrip": false,
|
| 73 |
+
"normalized": false,
|
| 74 |
+
"rstrip": true,
|
| 75 |
+
"single_word": false,
|
| 76 |
+
"special": true
|
| 77 |
+
},
|
| 78 |
+
"32006": {
|
| 79 |
+
"content": "<|system|>",
|
| 80 |
+
"lstrip": false,
|
| 81 |
+
"normalized": false,
|
| 82 |
+
"rstrip": true,
|
| 83 |
+
"single_word": false,
|
| 84 |
+
"special": true
|
| 85 |
+
},
|
| 86 |
+
"32007": {
|
| 87 |
+
"content": "<|end|>",
|
| 88 |
+
"lstrip": false,
|
| 89 |
+
"normalized": false,
|
| 90 |
+
"rstrip": true,
|
| 91 |
+
"single_word": false,
|
| 92 |
+
"special": true
|
| 93 |
+
},
|
| 94 |
+
"32008": {
|
| 95 |
+
"content": "<|placeholder5|>",
|
| 96 |
+
"lstrip": false,
|
| 97 |
+
"normalized": false,
|
| 98 |
+
"rstrip": true,
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"special": true
|
| 101 |
+
},
|
| 102 |
+
"32009": {
|
| 103 |
+
"content": "<|placeholder6|>",
|
| 104 |
+
"lstrip": false,
|
| 105 |
+
"normalized": false,
|
| 106 |
+
"rstrip": true,
|
| 107 |
+
"single_word": false,
|
| 108 |
+
"special": true
|
| 109 |
+
},
|
| 110 |
+
"32010": {
|
| 111 |
+
"content": "<|user|>",
|
| 112 |
+
"lstrip": false,
|
| 113 |
+
"normalized": false,
|
| 114 |
+
"rstrip": true,
|
| 115 |
+
"single_word": false,
|
| 116 |
+
"special": true
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
"bos_token": "<s>",
|
| 120 |
+
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
|
| 121 |
+
"clean_up_tokenization_spaces": false,
|
| 122 |
+
"eos_token": "<|endoftext|>",
|
| 123 |
+
"legacy": false,
|
| 124 |
+
"model_max_length": 4096,
|
| 125 |
+
"pad_token": "<|endoftext|>",
|
| 126 |
+
"padding_side": "left",
|
| 127 |
+
"sp_model_kwargs": {},
|
| 128 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 129 |
+
"unk_token": "<unk>",
|
| 130 |
+
"use_default_system_prompt": false
|
| 131 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/train_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9880609304240429,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 2099.8924772135415,
|
| 5 |
+
"train_runtime": 5573.0674,
|
| 6 |
+
"train_samples": 9715,
|
| 7 |
+
"train_samples_per_second": 1.743,
|
| 8 |
+
"train_steps_per_second": 0.013
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/trainer_state.json
ADDED
|
@@ -0,0 +1,1317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"best_metric": null,
|
| 3 |
+
"best_model_checkpoint": null,
|
| 4 |
+
"epoch": 0.9880609304240429,
|
| 5 |
+
"eval_steps": 500,
|
| 6 |
+
"global_step": 75,
|
| 7 |
+
"is_hyper_param_search": false,
|
| 8 |
+
"is_local_process_zero": true,
|
| 9 |
+
"is_world_process_zero": true,
|
| 10 |
+
"log_history": [
|
| 11 |
+
{
|
| 12 |
+
"epoch": 0.013174145738987238,
|
| 13 |
+
"grad_norm": 9400.6708984375,
|
| 14 |
+
"learning_rate": 6.25e-08,
|
| 15 |
+
"logits/chosen": 10.82703685760498,
|
| 16 |
+
"logits/rejected": 12.926292419433594,
|
| 17 |
+
"logps/chosen": -165.34439086914062,
|
| 18 |
+
"logps/ref_chosen": -165.34439086914062,
|
| 19 |
+
"logps/ref_rejected": -242.91778564453125,
|
| 20 |
+
"logps/rejected": -242.91778564453125,
|
| 21 |
+
"loss": 2500.0,
|
| 22 |
+
"rewards/accuracies": 0.0,
|
| 23 |
+
"rewards/chosen": 0.0,
|
| 24 |
+
"rewards/margins": 0.0,
|
| 25 |
+
"rewards/rejected": 0.0,
|
| 26 |
+
"step": 1
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"epoch": 0.026348291477974475,
|
| 30 |
+
"grad_norm": 21221.01171875,
|
| 31 |
+
"learning_rate": 1.25e-07,
|
| 32 |
+
"logits/chosen": 11.265995025634766,
|
| 33 |
+
"logits/rejected": 12.976096153259277,
|
| 34 |
+
"logps/chosen": -160.45846557617188,
|
| 35 |
+
"logps/ref_chosen": -160.45846557617188,
|
| 36 |
+
"logps/ref_rejected": -219.51760864257812,
|
| 37 |
+
"logps/rejected": -219.51760864257812,
|
| 38 |
+
"loss": 2500.0,
|
| 39 |
+
"rewards/accuracies": 0.0,
|
| 40 |
+
"rewards/chosen": 0.0,
|
| 41 |
+
"rewards/margins": 0.0,
|
| 42 |
+
"rewards/rejected": 0.0,
|
| 43 |
+
"step": 2
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"epoch": 0.03952243721696171,
|
| 47 |
+
"grad_norm": 10734.4990234375,
|
| 48 |
+
"learning_rate": 1.875e-07,
|
| 49 |
+
"logits/chosen": 10.50310230255127,
|
| 50 |
+
"logits/rejected": 12.375176429748535,
|
| 51 |
+
"logps/chosen": -157.18942260742188,
|
| 52 |
+
"logps/ref_chosen": -156.8568572998047,
|
| 53 |
+
"logps/ref_rejected": -221.9997100830078,
|
| 54 |
+
"logps/rejected": -222.2828369140625,
|
| 55 |
+
"loss": 2507.1133,
|
| 56 |
+
"rewards/accuracies": 0.4921875,
|
| 57 |
+
"rewards/chosen": -0.003325503319501877,
|
| 58 |
+
"rewards/margins": -0.000494096428155899,
|
| 59 |
+
"rewards/rejected": -0.0028314071241766214,
|
| 60 |
+
"step": 3
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"epoch": 0.05269658295594895,
|
| 64 |
+
"grad_norm": 13656.8974609375,
|
| 65 |
+
"learning_rate": 2.5e-07,
|
| 66 |
+
"logits/chosen": 10.842596054077148,
|
| 67 |
+
"logits/rejected": 12.673099517822266,
|
| 68 |
+
"logps/chosen": -155.01283264160156,
|
| 69 |
+
"logps/ref_chosen": -154.8412322998047,
|
| 70 |
+
"logps/ref_rejected": -214.8475341796875,
|
| 71 |
+
"logps/rejected": -215.06759643554688,
|
| 72 |
+
"loss": 2497.209,
|
| 73 |
+
"rewards/accuracies": 0.5234375,
|
| 74 |
+
"rewards/chosen": -0.001716194674372673,
|
| 75 |
+
"rewards/margins": 0.00048447016160935163,
|
| 76 |
+
"rewards/rejected": -0.0022006649523973465,
|
| 77 |
+
"step": 4
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"epoch": 0.06587072869493618,
|
| 81 |
+
"grad_norm": 14539.0771484375,
|
| 82 |
+
"learning_rate": 3.1249999999999997e-07,
|
| 83 |
+
"logits/chosen": 10.595704078674316,
|
| 84 |
+
"logits/rejected": 12.763114929199219,
|
| 85 |
+
"logps/chosen": -150.18836975097656,
|
| 86 |
+
"logps/ref_chosen": -149.982666015625,
|
| 87 |
+
"logps/ref_rejected": -214.53823852539062,
|
| 88 |
+
"logps/rejected": -214.69732666015625,
|
| 89 |
+
"loss": 2507.5791,
|
| 90 |
+
"rewards/accuracies": 0.5,
|
| 91 |
+
"rewards/chosen": -0.002057099947705865,
|
| 92 |
+
"rewards/margins": -0.00046626399853266776,
|
| 93 |
+
"rewards/rejected": -0.0015908360946923494,
|
| 94 |
+
"step": 5
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"epoch": 0.07904487443392343,
|
| 98 |
+
"grad_norm": 10673.970703125,
|
| 99 |
+
"learning_rate": 3.75e-07,
|
| 100 |
+
"logits/chosen": 10.63157844543457,
|
| 101 |
+
"logits/rejected": 12.672566413879395,
|
| 102 |
+
"logps/chosen": -159.777587890625,
|
| 103 |
+
"logps/ref_chosen": -159.91261291503906,
|
| 104 |
+
"logps/ref_rejected": -226.92630004882812,
|
| 105 |
+
"logps/rejected": -226.7730255126953,
|
| 106 |
+
"loss": 2504.6182,
|
| 107 |
+
"rewards/accuracies": 0.4609375,
|
| 108 |
+
"rewards/chosen": 0.0013501166831701994,
|
| 109 |
+
"rewards/margins": -0.00018252059817314148,
|
| 110 |
+
"rewards/rejected": 0.0015326375141739845,
|
| 111 |
+
"step": 6
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"epoch": 0.09221902017291066,
|
| 115 |
+
"grad_norm": 9153.2353515625,
|
| 116 |
+
"learning_rate": 4.375e-07,
|
| 117 |
+
"logits/chosen": 11.292702674865723,
|
| 118 |
+
"logits/rejected": 12.292116165161133,
|
| 119 |
+
"logps/chosen": -152.76022338867188,
|
| 120 |
+
"logps/ref_chosen": -152.6621856689453,
|
| 121 |
+
"logps/ref_rejected": -198.2692108154297,
|
| 122 |
+
"logps/rejected": -198.61947631835938,
|
| 123 |
+
"loss": 2476.8022,
|
| 124 |
+
"rewards/accuracies": 0.5703125,
|
| 125 |
+
"rewards/chosen": -0.0009803608991205692,
|
| 126 |
+
"rewards/margins": 0.0025223135016858578,
|
| 127 |
+
"rewards/rejected": -0.0035026748664677143,
|
| 128 |
+
"step": 7
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"epoch": 0.1053931659118979,
|
| 132 |
+
"grad_norm": 8650.978515625,
|
| 133 |
+
"learning_rate": 5e-07,
|
| 134 |
+
"logits/chosen": 11.386577606201172,
|
| 135 |
+
"logits/rejected": 12.966550827026367,
|
| 136 |
+
"logps/chosen": -159.4679412841797,
|
| 137 |
+
"logps/ref_chosen": -159.27700805664062,
|
| 138 |
+
"logps/ref_rejected": -219.18795776367188,
|
| 139 |
+
"logps/rejected": -219.41989135742188,
|
| 140 |
+
"loss": 2498.0945,
|
| 141 |
+
"rewards/accuracies": 0.46875,
|
| 142 |
+
"rewards/chosen": -0.0019092548172920942,
|
| 143 |
+
"rewards/margins": 0.00041025702375918627,
|
| 144 |
+
"rewards/rejected": -0.002319511491805315,
|
| 145 |
+
"step": 8
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"epoch": 0.11856731165088513,
|
| 149 |
+
"grad_norm": 7768.45751953125,
|
| 150 |
+
"learning_rate": 4.997252228714278e-07,
|
| 151 |
+
"logits/chosen": 11.336045265197754,
|
| 152 |
+
"logits/rejected": 12.81601619720459,
|
| 153 |
+
"logps/chosen": -164.18777465820312,
|
| 154 |
+
"logps/ref_chosen": -163.563720703125,
|
| 155 |
+
"logps/ref_rejected": -206.53392028808594,
|
| 156 |
+
"logps/rejected": -207.12802124023438,
|
| 157 |
+
"loss": 2505.5759,
|
| 158 |
+
"rewards/accuracies": 0.53125,
|
| 159 |
+
"rewards/chosen": -0.00624053506180644,
|
| 160 |
+
"rewards/margins": -0.0002995343238580972,
|
| 161 |
+
"rewards/rejected": -0.005941001232713461,
|
| 162 |
+
"step": 9
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"epoch": 0.13174145738987236,
|
| 166 |
+
"grad_norm": 8879.0400390625,
|
| 167 |
+
"learning_rate": 4.989014955054745e-07,
|
| 168 |
+
"logits/chosen": 10.808611869812012,
|
| 169 |
+
"logits/rejected": 12.567419052124023,
|
| 170 |
+
"logps/chosen": -152.06289672851562,
|
| 171 |
+
"logps/ref_chosen": -151.8050537109375,
|
| 172 |
+
"logps/ref_rejected": -204.39674377441406,
|
| 173 |
+
"logps/rejected": -204.71380615234375,
|
| 174 |
+
"loss": 2497.0557,
|
| 175 |
+
"rewards/accuracies": 0.5234375,
|
| 176 |
+
"rewards/chosen": -0.0025784748140722513,
|
| 177 |
+
"rewards/margins": 0.0005921997362747788,
|
| 178 |
+
"rewards/rejected": -0.0031706742011010647,
|
| 179 |
+
"step": 10
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"epoch": 0.14491560312885962,
|
| 183 |
+
"grad_norm": 8570.2255859375,
|
| 184 |
+
"learning_rate": 4.975306286336627e-07,
|
| 185 |
+
"logits/chosen": 11.010796546936035,
|
| 186 |
+
"logits/rejected": 13.206514358520508,
|
| 187 |
+
"logps/chosen": -160.0948944091797,
|
| 188 |
+
"logps/ref_chosen": -159.0467071533203,
|
| 189 |
+
"logps/ref_rejected": -233.74176025390625,
|
| 190 |
+
"logps/rejected": -235.1316680908203,
|
| 191 |
+
"loss": 2469.0793,
|
| 192 |
+
"rewards/accuracies": 0.6171875,
|
| 193 |
+
"rewards/chosen": -0.010481750592589378,
|
| 194 |
+
"rewards/margins": 0.0034171338193118572,
|
| 195 |
+
"rewards/rejected": -0.013898883946239948,
|
| 196 |
+
"step": 11
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"epoch": 0.15808974886784685,
|
| 200 |
+
"grad_norm": 9268.015625,
|
| 201 |
+
"learning_rate": 4.956156357188939e-07,
|
| 202 |
+
"logits/chosen": 10.943115234375,
|
| 203 |
+
"logits/rejected": 12.651875495910645,
|
| 204 |
+
"logps/chosen": -152.80560302734375,
|
| 205 |
+
"logps/ref_chosen": -151.5620880126953,
|
| 206 |
+
"logps/ref_rejected": -215.70706176757812,
|
| 207 |
+
"logps/rejected": -217.47042846679688,
|
| 208 |
+
"loss": 2452.4263,
|
| 209 |
+
"rewards/accuracies": 0.640625,
|
| 210 |
+
"rewards/chosen": -0.012435104697942734,
|
| 211 |
+
"rewards/margins": 0.005198378581553698,
|
| 212 |
+
"rewards/rejected": -0.017633484676480293,
|
| 213 |
+
"step": 12
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"epoch": 0.17126389460683408,
|
| 217 |
+
"grad_norm": 27639.7734375,
|
| 218 |
+
"learning_rate": 4.931607263312032e-07,
|
| 219 |
+
"logits/chosen": 10.944581985473633,
|
| 220 |
+
"logits/rejected": 12.781681060791016,
|
| 221 |
+
"logps/chosen": -158.21554565429688,
|
| 222 |
+
"logps/ref_chosen": -156.93284606933594,
|
| 223 |
+
"logps/ref_rejected": -225.4108123779297,
|
| 224 |
+
"logps/rejected": -227.0956268310547,
|
| 225 |
+
"loss": 2463.0876,
|
| 226 |
+
"rewards/accuracies": 0.640625,
|
| 227 |
+
"rewards/chosen": -0.01282706018537283,
|
| 228 |
+
"rewards/margins": 0.004021066706627607,
|
| 229 |
+
"rewards/rejected": -0.0168481282889843,
|
| 230 |
+
"step": 13
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"epoch": 0.1844380403458213,
|
| 234 |
+
"grad_norm": 11111.037109375,
|
| 235 |
+
"learning_rate": 4.9017129689421e-07,
|
| 236 |
+
"logits/chosen": 11.499626159667969,
|
| 237 |
+
"logits/rejected": 13.092345237731934,
|
| 238 |
+
"logps/chosen": -159.65853881835938,
|
| 239 |
+
"logps/ref_chosen": -158.00955200195312,
|
| 240 |
+
"logps/ref_rejected": -205.81216430664062,
|
| 241 |
+
"logps/rejected": -208.04916381835938,
|
| 242 |
+
"loss": 2444.844,
|
| 243 |
+
"rewards/accuracies": 0.640625,
|
| 244 |
+
"rewards/chosen": -0.016489841043949127,
|
| 245 |
+
"rewards/margins": 0.005880346521735191,
|
| 246 |
+
"rewards/rejected": -0.02237018570303917,
|
| 247 |
+
"step": 14
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"epoch": 0.19761218608480857,
|
| 251 |
+
"grad_norm": 16165.2041015625,
|
| 252 |
+
"learning_rate": 4.866539188226085e-07,
|
| 253 |
+
"logits/chosen": 11.359992027282715,
|
| 254 |
+
"logits/rejected": 12.714128494262695,
|
| 255 |
+
"logps/chosen": -164.4410858154297,
|
| 256 |
+
"logps/ref_chosen": -162.4319305419922,
|
| 257 |
+
"logps/ref_rejected": -207.7700958251953,
|
| 258 |
+
"logps/rejected": -210.54400634765625,
|
| 259 |
+
"loss": 2427.8018,
|
| 260 |
+
"rewards/accuracies": 0.703125,
|
| 261 |
+
"rewards/chosen": -0.020091760903596878,
|
| 262 |
+
"rewards/margins": 0.007647011429071426,
|
| 263 |
+
"rewards/rejected": -0.027738770470023155,
|
| 264 |
+
"step": 15
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
"epoch": 0.2107863318237958,
|
| 268 |
+
"grad_norm": 17296.9921875,
|
| 269 |
+
"learning_rate": 4.826163240767716e-07,
|
| 270 |
+
"logits/chosen": 10.857002258300781,
|
| 271 |
+
"logits/rejected": 12.381790161132812,
|
| 272 |
+
"logps/chosen": -149.5753631591797,
|
| 273 |
+
"logps/ref_chosen": -147.0189208984375,
|
| 274 |
+
"logps/ref_rejected": -200.2494659423828,
|
| 275 |
+
"logps/rejected": -203.5308837890625,
|
| 276 |
+
"loss": 2433.1763,
|
| 277 |
+
"rewards/accuracies": 0.65625,
|
| 278 |
+
"rewards/chosen": -0.025564489886164665,
|
| 279 |
+
"rewards/margins": 0.007249732501804829,
|
| 280 |
+
"rewards/rejected": -0.03281421959400177,
|
| 281 |
+
"step": 16
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"epoch": 0.22396047756278303,
|
| 285 |
+
"grad_norm": 10344.2060546875,
|
| 286 |
+
"learning_rate": 4.780673881662242e-07,
|
| 287 |
+
"logits/chosen": 10.619227409362793,
|
| 288 |
+
"logits/rejected": 12.975680351257324,
|
| 289 |
+
"logps/chosen": -154.77279663085938,
|
| 290 |
+
"logps/ref_chosen": -152.0904998779297,
|
| 291 |
+
"logps/ref_rejected": -235.09388732910156,
|
| 292 |
+
"logps/rejected": -238.4860076904297,
|
| 293 |
+
"loss": 2435.364,
|
| 294 |
+
"rewards/accuracies": 0.6328125,
|
| 295 |
+
"rewards/chosen": -0.02682284638285637,
|
| 296 |
+
"rewards/margins": 0.007098468951880932,
|
| 297 |
+
"rewards/rejected": -0.033921316266059875,
|
| 298 |
+
"step": 17
|
| 299 |
+
},
|
| 300 |
+
{
|
| 301 |
+
"epoch": 0.23713462330177026,
|
| 302 |
+
"grad_norm": 14072.92578125,
|
| 303 |
+
"learning_rate": 4.730171106393466e-07,
|
| 304 |
+
"logits/chosen": 10.697549819946289,
|
| 305 |
+
"logits/rejected": 12.313844680786133,
|
| 306 |
+
"logps/chosen": -153.66888427734375,
|
| 307 |
+
"logps/ref_chosen": -150.8133087158203,
|
| 308 |
+
"logps/ref_rejected": -200.70692443847656,
|
| 309 |
+
"logps/rejected": -204.89768981933594,
|
| 310 |
+
"loss": 2372.866,
|
| 311 |
+
"rewards/accuracies": 0.7578125,
|
| 312 |
+
"rewards/chosen": -0.028555531054735184,
|
| 313 |
+
"rewards/margins": 0.01335221715271473,
|
| 314 |
+
"rewards/rejected": -0.041907746344804764,
|
| 315 |
+
"step": 18
|
| 316 |
+
},
|
| 317 |
+
{
|
| 318 |
+
"epoch": 0.2503087690407575,
|
| 319 |
+
"grad_norm": 10882.427734375,
|
| 320 |
+
"learning_rate": 4.6747659310219757e-07,
|
| 321 |
+
"logits/chosen": 11.209357261657715,
|
| 322 |
+
"logits/rejected": 12.688121795654297,
|
| 323 |
+
"logps/chosen": -160.84046936035156,
|
| 324 |
+
"logps/ref_chosen": -158.5968017578125,
|
| 325 |
+
"logps/ref_rejected": -212.07949829101562,
|
| 326 |
+
"logps/rejected": -215.5081787109375,
|
| 327 |
+
"loss": 2388.6646,
|
| 328 |
+
"rewards/accuracies": 0.671875,
|
| 329 |
+
"rewards/chosen": -0.0224367156624794,
|
| 330 |
+
"rewards/margins": 0.011850089766085148,
|
| 331 |
+
"rewards/rejected": -0.03428680822253227,
|
| 332 |
+
"step": 19
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"epoch": 0.2634829147797447,
|
| 336 |
+
"grad_norm": 10401.9365234375,
|
| 337 |
+
"learning_rate": 4.6145801481477433e-07,
|
| 338 |
+
"logits/chosen": 10.668277740478516,
|
| 339 |
+
"logits/rejected": 12.550891876220703,
|
| 340 |
+
"logps/chosen": -166.43222045898438,
|
| 341 |
+
"logps/ref_chosen": -163.39842224121094,
|
| 342 |
+
"logps/ref_rejected": -229.50796508789062,
|
| 343 |
+
"logps/rejected": -233.9080352783203,
|
| 344 |
+
"loss": 2373.105,
|
| 345 |
+
"rewards/accuracies": 0.6640625,
|
| 346 |
+
"rewards/chosen": -0.03033788874745369,
|
| 347 |
+
"rewards/margins": 0.01366282720118761,
|
| 348 |
+
"rewards/rejected": -0.044000715017318726,
|
| 349 |
+
"step": 20
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"epoch": 0.276657060518732,
|
| 353 |
+
"grad_norm": 8655.169921875,
|
| 354 |
+
"learning_rate": 4.549746059183561e-07,
|
| 355 |
+
"logits/chosen": 10.736316680908203,
|
| 356 |
+
"logits/rejected": 12.37639331817627,
|
| 357 |
+
"logps/chosen": -155.8470001220703,
|
| 358 |
+
"logps/ref_chosen": -152.2843475341797,
|
| 359 |
+
"logps/ref_rejected": -207.0301971435547,
|
| 360 |
+
"logps/rejected": -212.4528350830078,
|
| 361 |
+
"loss": 2325.9807,
|
| 362 |
+
"rewards/accuracies": 0.75,
|
| 363 |
+
"rewards/chosen": -0.03562622517347336,
|
| 364 |
+
"rewards/margins": 0.018600180745124817,
|
| 365 |
+
"rewards/rejected": -0.054226409643888474,
|
| 366 |
+
"step": 21
|
| 367 |
+
},
|
| 368 |
+
{
|
| 369 |
+
"epoch": 0.28983120625771924,
|
| 370 |
+
"grad_norm": 12543.3515625,
|
| 371 |
+
"learning_rate": 4.480406183527823e-07,
|
| 372 |
+
"logits/chosen": 10.920833587646484,
|
| 373 |
+
"logits/rejected": 13.167766571044922,
|
| 374 |
+
"logps/chosen": -162.93035888671875,
|
| 375 |
+
"logps/ref_chosen": -158.80386352539062,
|
| 376 |
+
"logps/ref_rejected": -238.517822265625,
|
| 377 |
+
"logps/rejected": -244.45428466796875,
|
| 378 |
+
"loss": 2332.4531,
|
| 379 |
+
"rewards/accuracies": 0.7109375,
|
| 380 |
+
"rewards/chosen": -0.04126487299799919,
|
| 381 |
+
"rewards/margins": 0.018099676817655563,
|
| 382 |
+
"rewards/rejected": -0.05936455726623535,
|
| 383 |
+
"step": 22
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"epoch": 0.3030053519967065,
|
| 387 |
+
"grad_norm": 24078.228515625,
|
| 388 |
+
"learning_rate": 4.4067129452759546e-07,
|
| 389 |
+
"logits/chosen": 10.791974067687988,
|
| 390 |
+
"logits/rejected": 12.902603149414062,
|
| 391 |
+
"logps/chosen": -158.752685546875,
|
| 392 |
+
"logps/ref_chosen": -154.57838439941406,
|
| 393 |
+
"logps/ref_rejected": -224.06118774414062,
|
| 394 |
+
"logps/rejected": -230.06097412109375,
|
| 395 |
+
"loss": 2333.0601,
|
| 396 |
+
"rewards/accuracies": 0.6953125,
|
| 397 |
+
"rewards/chosen": -0.04174318164587021,
|
| 398 |
+
"rewards/margins": 0.01825462281703949,
|
| 399 |
+
"rewards/rejected": -0.0599978044629097,
|
| 400 |
+
"step": 23
|
| 401 |
+
},
|
| 402 |
+
{
|
| 403 |
+
"epoch": 0.3161794977356937,
|
| 404 |
+
"grad_norm": 16774.41015625,
|
| 405 |
+
"learning_rate": 4.3288283381591725e-07,
|
| 406 |
+
"logits/chosen": 11.075492858886719,
|
| 407 |
+
"logits/rejected": 12.924552917480469,
|
| 408 |
+
"logps/chosen": -162.48556518554688,
|
| 409 |
+
"logps/ref_chosen": -158.0958709716797,
|
| 410 |
+
"logps/ref_rejected": -227.6788787841797,
|
| 411 |
+
"logps/rejected": -234.5062255859375,
|
| 412 |
+
"loss": 2273.0808,
|
| 413 |
+
"rewards/accuracies": 0.7421875,
|
| 414 |
+
"rewards/chosen": -0.043896887451410294,
|
| 415 |
+
"rewards/margins": 0.02437680959701538,
|
| 416 |
+
"rewards/rejected": -0.06827369332313538,
|
| 417 |
+
"step": 24
|
| 418 |
+
},
|
| 419 |
+
{
|
| 420 |
+
"epoch": 0.32935364347468093,
|
| 421 |
+
"grad_norm": 15178.0029296875,
|
| 422 |
+
"learning_rate": 4.246923569447104e-07,
|
| 423 |
+
"logits/chosen": 11.007344245910645,
|
| 424 |
+
"logits/rejected": 12.212202072143555,
|
| 425 |
+
"logps/chosen": -162.5133514404297,
|
| 426 |
+
"logps/ref_chosen": -158.1756591796875,
|
| 427 |
+
"logps/ref_rejected": -208.99362182617188,
|
| 428 |
+
"logps/rejected": -215.74468994140625,
|
| 429 |
+
"loss": 2280.9648,
|
| 430 |
+
"rewards/accuracies": 0.71875,
|
| 431 |
+
"rewards/chosen": -0.043377190828323364,
|
| 432 |
+
"rewards/margins": 0.024133291095495224,
|
| 433 |
+
"rewards/rejected": -0.06751047819852829,
|
| 434 |
+
"step": 25
|
| 435 |
+
},
|
| 436 |
+
{
|
| 437 |
+
"epoch": 0.34252778921366817,
|
| 438 |
+
"grad_norm": 26384.228515625,
|
| 439 |
+
"learning_rate": 4.161178683597054e-07,
|
| 440 |
+
"logits/chosen": 10.682706832885742,
|
| 441 |
+
"logits/rejected": 11.836393356323242,
|
| 442 |
+
"logps/chosen": -166.22201538085938,
|
| 443 |
+
"logps/ref_chosen": -161.83668518066406,
|
| 444 |
+
"logps/ref_rejected": -219.0419158935547,
|
| 445 |
+
"logps/rejected": -226.38525390625,
|
| 446 |
+
"loss": 2228.3735,
|
| 447 |
+
"rewards/accuracies": 0.7578125,
|
| 448 |
+
"rewards/chosen": -0.043853215873241425,
|
| 449 |
+
"rewards/margins": 0.029579948633909225,
|
| 450 |
+
"rewards/rejected": -0.07343316078186035,
|
| 451 |
+
"step": 26
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"epoch": 0.3557019349526554,
|
| 455 |
+
"grad_norm": 15863.474609375,
|
| 456 |
+
"learning_rate": 4.0717821664772124e-07,
|
| 457 |
+
"logits/chosen": 11.154513359069824,
|
| 458 |
+
"logits/rejected": 12.91202163696289,
|
| 459 |
+
"logps/chosen": -153.80191040039062,
|
| 460 |
+
"logps/ref_chosen": -148.73416137695312,
|
| 461 |
+
"logps/ref_rejected": -215.90719604492188,
|
| 462 |
+
"logps/rejected": -223.44522094726562,
|
| 463 |
+
"loss": 2277.9224,
|
| 464 |
+
"rewards/accuracies": 0.671875,
|
| 465 |
+
"rewards/chosen": -0.05067756399512291,
|
| 466 |
+
"rewards/margins": 0.02470243163406849,
|
| 467 |
+
"rewards/rejected": -0.07537999749183655,
|
| 468 |
+
"step": 27
|
| 469 |
+
},
|
| 470 |
+
{
|
| 471 |
+
"epoch": 0.3688760806916426,
|
| 472 |
+
"grad_norm": 14232.365234375,
|
| 473 |
+
"learning_rate": 3.978930531033806e-07,
|
| 474 |
+
"logits/chosen": 10.889751434326172,
|
| 475 |
+
"logits/rejected": 12.690634727478027,
|
| 476 |
+
"logps/chosen": -161.13949584960938,
|
| 477 |
+
"logps/ref_chosen": -155.64901733398438,
|
| 478 |
+
"logps/ref_rejected": -225.31777954101562,
|
| 479 |
+
"logps/rejected": -234.314697265625,
|
| 480 |
+
"loss": 2181.4084,
|
| 481 |
+
"rewards/accuracies": 0.75,
|
| 482 |
+
"rewards/chosen": -0.05490463599562645,
|
| 483 |
+
"rewards/margins": 0.03506467118859291,
|
| 484 |
+
"rewards/rejected": -0.08996930718421936,
|
| 485 |
+
"step": 28
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"epoch": 0.3820502264306299,
|
| 489 |
+
"grad_norm": 18916.439453125,
|
| 490 |
+
"learning_rate": 3.882827885312998e-07,
|
| 491 |
+
"logits/chosen": 11.007489204406738,
|
| 492 |
+
"logits/rejected": 12.633637428283691,
|
| 493 |
+
"logps/chosen": -158.77105712890625,
|
| 494 |
+
"logps/ref_chosen": -153.41664123535156,
|
| 495 |
+
"logps/ref_rejected": -207.1138153076172,
|
| 496 |
+
"logps/rejected": -216.37054443359375,
|
| 497 |
+
"loss": 2145.0813,
|
| 498 |
+
"rewards/accuracies": 0.8203125,
|
| 499 |
+
"rewards/chosen": -0.053544167429208755,
|
| 500 |
+
"rewards/margins": 0.039023347198963165,
|
| 501 |
+
"rewards/rejected": -0.09256751090288162,
|
| 502 |
+
"step": 29
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"epoch": 0.39522437216961714,
|
| 506 |
+
"grad_norm": 10493.50390625,
|
| 507 |
+
"learning_rate": 3.7836854837871044e-07,
|
| 508 |
+
"logits/chosen": 10.605050086975098,
|
| 509 |
+
"logits/rejected": 12.352598190307617,
|
| 510 |
+
"logps/chosen": -160.17990112304688,
|
| 511 |
+
"logps/ref_chosen": -153.88478088378906,
|
| 512 |
+
"logps/ref_rejected": -212.717041015625,
|
| 513 |
+
"logps/rejected": -222.16250610351562,
|
| 514 |
+
"loss": 2221.1169,
|
| 515 |
+
"rewards/accuracies": 0.765625,
|
| 516 |
+
"rewards/chosen": -0.06295125931501389,
|
| 517 |
+
"rewards/margins": 0.031503234058618546,
|
| 518 |
+
"rewards/rejected": -0.09445449709892273,
|
| 519 |
+
"step": 30
|
| 520 |
+
},
|
| 521 |
+
{
|
| 522 |
+
"epoch": 0.4083985179086044,
|
| 523 |
+
"grad_norm": 9682.4736328125,
|
| 524 |
+
"learning_rate": 3.681721262971413e-07,
|
| 525 |
+
"logits/chosen": 10.964306831359863,
|
| 526 |
+
"logits/rejected": 12.461715698242188,
|
| 527 |
+
"logps/chosen": -159.40370178222656,
|
| 528 |
+
"logps/ref_chosen": -152.5292205810547,
|
| 529 |
+
"logps/ref_rejected": -195.53961181640625,
|
| 530 |
+
"logps/rejected": -205.14572143554688,
|
| 531 |
+
"loss": 2268.2305,
|
| 532 |
+
"rewards/accuracies": 0.6875,
|
| 533 |
+
"rewards/chosen": -0.06874459236860275,
|
| 534 |
+
"rewards/margins": 0.027316508814692497,
|
| 535 |
+
"rewards/rejected": -0.0960611030459404,
|
| 536 |
+
"step": 31
|
| 537 |
+
},
|
| 538 |
+
{
|
| 539 |
+
"epoch": 0.4215726636475916,
|
| 540 |
+
"grad_norm": 11582.8642578125,
|
| 541 |
+
"learning_rate": 3.577159362352426e-07,
|
| 542 |
+
"logits/chosen": 11.044258117675781,
|
| 543 |
+
"logits/rejected": 12.617271423339844,
|
| 544 |
+
"logps/chosen": -159.27413940429688,
|
| 545 |
+
"logps/ref_chosen": -153.38961791992188,
|
| 546 |
+
"logps/ref_rejected": -215.3624267578125,
|
| 547 |
+
"logps/rejected": -225.04229736328125,
|
| 548 |
+
"loss": 2160.7576,
|
| 549 |
+
"rewards/accuracies": 0.78125,
|
| 550 |
+
"rewards/chosen": -0.058845154941082,
|
| 551 |
+
"rewards/margins": 0.03795357793569565,
|
| 552 |
+
"rewards/rejected": -0.09679872542619705,
|
| 553 |
+
"step": 32
|
| 554 |
+
},
|
| 555 |
+
{
|
| 556 |
+
"epoch": 0.43474680938657884,
|
| 557 |
+
"grad_norm": 10598.3251953125,
|
| 558 |
+
"learning_rate": 3.470229631680624e-07,
|
| 559 |
+
"logits/chosen": 11.065394401550293,
|
| 560 |
+
"logits/rejected": 12.650857925415039,
|
| 561 |
+
"logps/chosen": -166.10433959960938,
|
| 562 |
+
"logps/ref_chosen": -159.08718872070312,
|
| 563 |
+
"logps/ref_rejected": -211.2034912109375,
|
| 564 |
+
"logps/rejected": -222.69808959960938,
|
| 565 |
+
"loss": 2105.9622,
|
| 566 |
+
"rewards/accuracies": 0.8125,
|
| 567 |
+
"rewards/chosen": -0.07017137110233307,
|
| 568 |
+
"rewards/margins": 0.04477447643876076,
|
| 569 |
+
"rewards/rejected": -0.11494585126638412,
|
| 570 |
+
"step": 33
|
| 571 |
+
},
|
| 572 |
+
{
|
| 573 |
+
"epoch": 0.44792095512556607,
|
| 574 |
+
"grad_norm": 13881.9091796875,
|
| 575 |
+
"learning_rate": 3.361167125710832e-07,
|
| 576 |
+
"logits/chosen": 10.507146835327148,
|
| 577 |
+
"logits/rejected": 12.532270431518555,
|
| 578 |
+
"logps/chosen": -165.39614868164062,
|
| 579 |
+
"logps/ref_chosen": -158.19137573242188,
|
| 580 |
+
"logps/ref_rejected": -221.2183837890625,
|
| 581 |
+
"logps/rejected": -231.75192260742188,
|
| 582 |
+
"loss": 2207.9556,
|
| 583 |
+
"rewards/accuracies": 0.6953125,
|
| 584 |
+
"rewards/chosen": -0.0720476508140564,
|
| 585 |
+
"rewards/margins": 0.03328781574964523,
|
| 586 |
+
"rewards/rejected": -0.10533546656370163,
|
| 587 |
+
"step": 34
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"epoch": 0.4610951008645533,
|
| 591 |
+
"grad_norm": 9820.82421875,
|
| 592 |
+
"learning_rate": 3.2502115875008516e-07,
|
| 593 |
+
"logits/chosen": 11.050285339355469,
|
| 594 |
+
"logits/rejected": 12.682265281677246,
|
| 595 |
+
"logps/chosen": -159.96206665039062,
|
| 596 |
+
"logps/ref_chosen": -152.84747314453125,
|
| 597 |
+
"logps/ref_rejected": -193.7710723876953,
|
| 598 |
+
"logps/rejected": -205.7515869140625,
|
| 599 |
+
"loss": 2071.1167,
|
| 600 |
+
"rewards/accuracies": 0.765625,
|
| 601 |
+
"rewards/chosen": -0.07114598900079727,
|
| 602 |
+
"rewards/margins": 0.0486593097448349,
|
| 603 |
+
"rewards/rejected": -0.11980530619621277,
|
| 604 |
+
"step": 35
|
| 605 |
+
},
|
| 606 |
+
{
|
| 607 |
+
"epoch": 0.47426924660354053,
|
| 608 |
+
"grad_norm": 11415.3212890625,
|
| 609 |
+
"learning_rate": 3.137606921404191e-07,
|
| 610 |
+
"logits/chosen": 11.087711334228516,
|
| 611 |
+
"logits/rejected": 12.402737617492676,
|
| 612 |
+
"logps/chosen": -166.2897186279297,
|
| 613 |
+
"logps/ref_chosen": -158.5576629638672,
|
| 614 |
+
"logps/ref_rejected": -212.30044555664062,
|
| 615 |
+
"logps/rejected": -225.1736602783203,
|
| 616 |
+
"loss": 2060.9187,
|
| 617 |
+
"rewards/accuracies": 0.765625,
|
| 618 |
+
"rewards/chosen": -0.07732091844081879,
|
| 619 |
+
"rewards/margins": 0.051411230117082596,
|
| 620 |
+
"rewards/rejected": -0.12873214483261108,
|
| 621 |
+
"step": 36
|
| 622 |
+
},
|
| 623 |
+
{
|
| 624 |
+
"epoch": 0.4874433923425278,
|
| 625 |
+
"grad_norm": 13971.23828125,
|
| 626 |
+
"learning_rate": 3.0236006569153616e-07,
|
| 627 |
+
"logits/chosen": 10.429332733154297,
|
| 628 |
+
"logits/rejected": 12.33328914642334,
|
| 629 |
+
"logps/chosen": -166.51292419433594,
|
| 630 |
+
"logps/ref_chosen": -158.58470153808594,
|
| 631 |
+
"logps/ref_rejected": -235.19139099121094,
|
| 632 |
+
"logps/rejected": -248.8429412841797,
|
| 633 |
+
"loss": 2007.0973,
|
| 634 |
+
"rewards/accuracies": 0.8046875,
|
| 635 |
+
"rewards/chosen": -0.07928227633237839,
|
| 636 |
+
"rewards/margins": 0.0572332963347435,
|
| 637 |
+
"rewards/rejected": -0.1365155577659607,
|
| 638 |
+
"step": 37
|
| 639 |
+
},
|
| 640 |
+
{
|
| 641 |
+
"epoch": 0.500617538081515,
|
| 642 |
+
"grad_norm": 17963.12890625,
|
| 643 |
+
"learning_rate": 2.9084434045463254e-07,
|
| 644 |
+
"logits/chosen": 10.52884578704834,
|
| 645 |
+
"logits/rejected": 12.01021957397461,
|
| 646 |
+
"logps/chosen": -171.40647888183594,
|
| 647 |
+
"logps/ref_chosen": -163.09234619140625,
|
| 648 |
+
"logps/ref_rejected": -207.53245544433594,
|
| 649 |
+
"logps/rejected": -221.10321044921875,
|
| 650 |
+
"loss": 2055.542,
|
| 651 |
+
"rewards/accuracies": 0.7578125,
|
| 652 |
+
"rewards/chosen": -0.0831414982676506,
|
| 653 |
+
"rewards/margins": 0.05256626009941101,
|
| 654 |
+
"rewards/rejected": -0.13570775091648102,
|
| 655 |
+
"step": 38
|
| 656 |
+
},
|
| 657 |
+
{
|
| 658 |
+
"epoch": 0.5137916838205022,
|
| 659 |
+
"grad_norm": 25816.57421875,
|
| 660 |
+
"learning_rate": 2.7923883049302066e-07,
|
| 661 |
+
"logits/chosen": 10.744199752807617,
|
| 662 |
+
"logits/rejected": 11.991629600524902,
|
| 663 |
+
"logps/chosen": -168.72080993652344,
|
| 664 |
+
"logps/ref_chosen": -160.3236541748047,
|
| 665 |
+
"logps/ref_rejected": -209.6466827392578,
|
| 666 |
+
"logps/rejected": -223.9167938232422,
|
| 667 |
+
"loss": 2006.2753,
|
| 668 |
+
"rewards/accuracies": 0.7578125,
|
| 669 |
+
"rewards/chosen": -0.08397158235311508,
|
| 670 |
+
"rewards/margins": 0.05872953683137894,
|
| 671 |
+
"rewards/rejected": -0.14270111918449402,
|
| 672 |
+
"step": 39
|
| 673 |
+
},
|
| 674 |
+
{
|
| 675 |
+
"epoch": 0.5269658295594895,
|
| 676 |
+
"grad_norm": 15037.15234375,
|
| 677 |
+
"learning_rate": 2.6756904723632324e-07,
|
| 678 |
+
"logits/chosen": 11.01625919342041,
|
| 679 |
+
"logits/rejected": 12.564811706542969,
|
| 680 |
+
"logps/chosen": -158.7521514892578,
|
| 681 |
+
"logps/ref_chosen": -149.23289489746094,
|
| 682 |
+
"logps/ref_rejected": -206.46856689453125,
|
| 683 |
+
"logps/rejected": -222.3318328857422,
|
| 684 |
+
"loss": 1976.5437,
|
| 685 |
+
"rewards/accuracies": 0.8046875,
|
| 686 |
+
"rewards/chosen": -0.09519265592098236,
|
| 687 |
+
"rewards/margins": 0.06343982368707657,
|
| 688 |
+
"rewards/rejected": -0.15863248705863953,
|
| 689 |
+
"step": 40
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"epoch": 0.5401399752984768,
|
| 693 |
+
"grad_norm": 10468.275390625,
|
| 694 |
+
"learning_rate": 2.5586064340081516e-07,
|
| 695 |
+
"logits/chosen": 10.919938087463379,
|
| 696 |
+
"logits/rejected": 12.452343940734863,
|
| 697 |
+
"logps/chosen": -174.4501953125,
|
| 698 |
+
"logps/ref_chosen": -164.6531524658203,
|
| 699 |
+
"logps/ref_rejected": -217.58392333984375,
|
| 700 |
+
"logps/rejected": -233.07186889648438,
|
| 701 |
+
"loss": 2025.8909,
|
| 702 |
+
"rewards/accuracies": 0.7578125,
|
| 703 |
+
"rewards/chosen": -0.09797056019306183,
|
| 704 |
+
"rewards/margins": 0.0569089911878109,
|
| 705 |
+
"rewards/rejected": -0.15487954020500183,
|
| 706 |
+
"step": 41
|
| 707 |
+
},
|
| 708 |
+
{
|
| 709 |
+
"epoch": 0.553314121037464,
|
| 710 |
+
"grad_norm": 11281.0556640625,
|
| 711 |
+
"learning_rate": 2.4413935659918487e-07,
|
| 712 |
+
"logits/chosen": 10.305431365966797,
|
| 713 |
+
"logits/rejected": 11.99144172668457,
|
| 714 |
+
"logps/chosen": -163.74720764160156,
|
| 715 |
+
"logps/ref_chosen": -153.57626342773438,
|
| 716 |
+
"logps/ref_rejected": -222.79940795898438,
|
| 717 |
+
"logps/rejected": -239.41419982910156,
|
| 718 |
+
"loss": 1986.8146,
|
| 719 |
+
"rewards/accuracies": 0.734375,
|
| 720 |
+
"rewards/chosen": -0.10170932859182358,
|
| 721 |
+
"rewards/margins": 0.06443872302770615,
|
| 722 |
+
"rewards/rejected": -0.16614805161952972,
|
| 723 |
+
"step": 42
|
| 724 |
+
},
|
| 725 |
+
{
|
| 726 |
+
"epoch": 0.5664882667764513,
|
| 727 |
+
"grad_norm": 22486.40625,
|
| 728 |
+
"learning_rate": 2.3243095276367684e-07,
|
| 729 |
+
"logits/chosen": 11.014253616333008,
|
| 730 |
+
"logits/rejected": 12.564366340637207,
|
| 731 |
+
"logps/chosen": -169.32418823242188,
|
| 732 |
+
"logps/ref_chosen": -158.31723022460938,
|
| 733 |
+
"logps/ref_rejected": -210.85391235351562,
|
| 734 |
+
"logps/rejected": -228.50164794921875,
|
| 735 |
+
"loss": 1958.2251,
|
| 736 |
+
"rewards/accuracies": 0.765625,
|
| 737 |
+
"rewards/chosen": -0.11006948351860046,
|
| 738 |
+
"rewards/margins": 0.06640826165676117,
|
| 739 |
+
"rewards/rejected": -0.17647776007652283,
|
| 740 |
+
"step": 43
|
| 741 |
+
},
|
| 742 |
+
{
|
| 743 |
+
"epoch": 0.5796624125154385,
|
| 744 |
+
"grad_norm": 11780.6904296875,
|
| 745 |
+
"learning_rate": 2.2076116950697937e-07,
|
| 746 |
+
"logits/chosen": 10.247262001037598,
|
| 747 |
+
"logits/rejected": 12.395702362060547,
|
| 748 |
+
"logps/chosen": -171.3905792236328,
|
| 749 |
+
"logps/ref_chosen": -160.19940185546875,
|
| 750 |
+
"logps/ref_rejected": -237.79849243164062,
|
| 751 |
+
"logps/rejected": -255.21876525878906,
|
| 752 |
+
"loss": 2017.8268,
|
| 753 |
+
"rewards/accuracies": 0.734375,
|
| 754 |
+
"rewards/chosen": -0.11191190779209137,
|
| 755 |
+
"rewards/margins": 0.06229105591773987,
|
| 756 |
+
"rewards/rejected": -0.17420296370983124,
|
| 757 |
+
"step": 44
|
| 758 |
+
},
|
| 759 |
+
{
|
| 760 |
+
"epoch": 0.5928365582544257,
|
| 761 |
+
"grad_norm": 14130.494140625,
|
| 762 |
+
"learning_rate": 2.091556595453674e-07,
|
| 763 |
+
"logits/chosen": 11.594133377075195,
|
| 764 |
+
"logits/rejected": 13.111774444580078,
|
| 765 |
+
"logps/chosen": -173.94357299804688,
|
| 766 |
+
"logps/ref_chosen": -163.90086364746094,
|
| 767 |
+
"logps/ref_rejected": -217.97494506835938,
|
| 768 |
+
"logps/rejected": -235.41470336914062,
|
| 769 |
+
"loss": 1904.377,
|
| 770 |
+
"rewards/accuracies": 0.765625,
|
| 771 |
+
"rewards/chosen": -0.10042709112167358,
|
| 772 |
+
"rewards/margins": 0.07397040724754333,
|
| 773 |
+
"rewards/rejected": -0.17439748346805573,
|
| 774 |
+
"step": 45
|
| 775 |
+
},
|
| 776 |
+
{
|
| 777 |
+
"epoch": 0.606010703993413,
|
| 778 |
+
"grad_norm": 8916.85546875,
|
| 779 |
+
"learning_rate": 1.9763993430846392e-07,
|
| 780 |
+
"logits/chosen": 10.761359214782715,
|
| 781 |
+
"logits/rejected": 12.22790813446045,
|
| 782 |
+
"logps/chosen": -166.23931884765625,
|
| 783 |
+
"logps/ref_chosen": -155.1966552734375,
|
| 784 |
+
"logps/ref_rejected": -214.27117919921875,
|
| 785 |
+
"logps/rejected": -232.93251037597656,
|
| 786 |
+
"loss": 1896.7078,
|
| 787 |
+
"rewards/accuracies": 0.75,
|
| 788 |
+
"rewards/chosen": -0.11042674630880356,
|
| 789 |
+
"rewards/margins": 0.07618650048971176,
|
| 790 |
+
"rewards/rejected": -0.18661323189735413,
|
| 791 |
+
"step": 46
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"epoch": 0.6191848497324002,
|
| 795 |
+
"grad_norm": 10609.7197265625,
|
| 796 |
+
"learning_rate": 1.862393078595809e-07,
|
| 797 |
+
"logits/chosen": 10.880764961242676,
|
| 798 |
+
"logits/rejected": 12.460386276245117,
|
| 799 |
+
"logps/chosen": -176.01988220214844,
|
| 800 |
+
"logps/ref_chosen": -164.49806213378906,
|
| 801 |
+
"logps/ref_rejected": -210.54478454589844,
|
| 802 |
+
"logps/rejected": -230.46044921875,
|
| 803 |
+
"loss": 1833.8613,
|
| 804 |
+
"rewards/accuracies": 0.7734375,
|
| 805 |
+
"rewards/chosen": -0.11521796137094498,
|
| 806 |
+
"rewards/margins": 0.08393879234790802,
|
| 807 |
+
"rewards/rejected": -0.1991567462682724,
|
| 808 |
+
"step": 47
|
| 809 |
+
},
|
| 810 |
+
{
|
| 811 |
+
"epoch": 0.6323589954713874,
|
| 812 |
+
"grad_norm": 14657.07421875,
|
| 813 |
+
"learning_rate": 1.7497884124991485e-07,
|
| 814 |
+
"logits/chosen": 10.337532043457031,
|
| 815 |
+
"logits/rejected": 12.653590202331543,
|
| 816 |
+
"logps/chosen": -172.46270751953125,
|
| 817 |
+
"logps/ref_chosen": -161.3790283203125,
|
| 818 |
+
"logps/ref_rejected": -241.97048950195312,
|
| 819 |
+
"logps/rejected": -260.27685546875,
|
| 820 |
+
"loss": 1913.8575,
|
| 821 |
+
"rewards/accuracies": 0.78125,
|
| 822 |
+
"rewards/chosen": -0.11083672940731049,
|
| 823 |
+
"rewards/margins": 0.07222721725702286,
|
| 824 |
+
"rewards/rejected": -0.18306395411491394,
|
| 825 |
+
"step": 48
|
| 826 |
+
},
|
| 827 |
+
{
|
| 828 |
+
"epoch": 0.6455331412103746,
|
| 829 |
+
"grad_norm": 16674.568359375,
|
| 830 |
+
"learning_rate": 1.6388328742891678e-07,
|
| 831 |
+
"logits/chosen": 10.696357727050781,
|
| 832 |
+
"logits/rejected": 12.33877182006836,
|
| 833 |
+
"logps/chosen": -165.397216796875,
|
| 834 |
+
"logps/ref_chosen": -153.8616943359375,
|
| 835 |
+
"logps/ref_rejected": -213.1271209716797,
|
| 836 |
+
"logps/rejected": -231.73365783691406,
|
| 837 |
+
"loss": 1968.993,
|
| 838 |
+
"rewards/accuracies": 0.7421875,
|
| 839 |
+
"rewards/chosen": -0.11535505205392838,
|
| 840 |
+
"rewards/margins": 0.07071049511432648,
|
| 841 |
+
"rewards/rejected": -0.18606556951999664,
|
| 842 |
+
"step": 49
|
| 843 |
+
},
|
| 844 |
+
{
|
| 845 |
+
"epoch": 0.6587072869493619,
|
| 846 |
+
"grad_norm": 11774.1298828125,
|
| 847 |
+
"learning_rate": 1.5297703683193753e-07,
|
| 848 |
+
"logits/chosen": 10.659011840820312,
|
| 849 |
+
"logits/rejected": 12.590448379516602,
|
| 850 |
+
"logps/chosen": -168.46041870117188,
|
| 851 |
+
"logps/ref_chosen": -159.17498779296875,
|
| 852 |
+
"logps/ref_rejected": -222.2801055908203,
|
| 853 |
+
"logps/rejected": -240.4370574951172,
|
| 854 |
+
"loss": 1804.9274,
|
| 855 |
+
"rewards/accuracies": 0.7890625,
|
| 856 |
+
"rewards/chosen": -0.09285451471805573,
|
| 857 |
+
"rewards/margins": 0.08871510624885559,
|
| 858 |
+
"rewards/rejected": -0.1815696358680725,
|
| 859 |
+
"step": 50
|
| 860 |
+
},
|
| 861 |
+
{
|
| 862 |
+
"epoch": 0.6718814326883491,
|
| 863 |
+
"grad_norm": 17470.318359375,
|
| 864 |
+
"learning_rate": 1.422840637647574e-07,
|
| 865 |
+
"logits/chosen": 10.45498275756836,
|
| 866 |
+
"logits/rejected": 11.927793502807617,
|
| 867 |
+
"logps/chosen": -178.29295349121094,
|
| 868 |
+
"logps/ref_chosen": -167.52182006835938,
|
| 869 |
+
"logps/ref_rejected": -227.38404846191406,
|
| 870 |
+
"logps/rejected": -247.32546997070312,
|
| 871 |
+
"loss": 1791.5856,
|
| 872 |
+
"rewards/accuracies": 0.7734375,
|
| 873 |
+
"rewards/chosen": -0.10771138221025467,
|
| 874 |
+
"rewards/margins": 0.09170287102460861,
|
| 875 |
+
"rewards/rejected": -0.19941426813602448,
|
| 876 |
+
"step": 51
|
| 877 |
+
},
|
| 878 |
+
{
|
| 879 |
+
"epoch": 0.6850555784273363,
|
| 880 |
+
"grad_norm": 12265.9453125,
|
| 881 |
+
"learning_rate": 1.3182787370285865e-07,
|
| 882 |
+
"logits/chosen": 10.356386184692383,
|
| 883 |
+
"logits/rejected": 12.254987716674805,
|
| 884 |
+
"logps/chosen": -177.23435974121094,
|
| 885 |
+
"logps/ref_chosen": -164.61024475097656,
|
| 886 |
+
"logps/ref_rejected": -229.43984985351562,
|
| 887 |
+
"logps/rejected": -250.8160400390625,
|
| 888 |
+
"loss": 1826.7301,
|
| 889 |
+
"rewards/accuracies": 0.75,
|
| 890 |
+
"rewards/chosen": -0.12624132633209229,
|
| 891 |
+
"rewards/margins": 0.08752066642045975,
|
| 892 |
+
"rewards/rejected": -0.21376200020313263,
|
| 893 |
+
"step": 52
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"epoch": 0.6982297241663236,
|
| 897 |
+
"grad_norm": 25398.646484375,
|
| 898 |
+
"learning_rate": 1.2163145162128946e-07,
|
| 899 |
+
"logits/chosen": 11.139243125915527,
|
| 900 |
+
"logits/rejected": 12.77961254119873,
|
| 901 |
+
"logps/chosen": -175.96458435058594,
|
| 902 |
+
"logps/ref_chosen": -162.58197021484375,
|
| 903 |
+
"logps/ref_rejected": -229.28993225097656,
|
| 904 |
+
"logps/rejected": -250.81256103515625,
|
| 905 |
+
"loss": 1859.8025,
|
| 906 |
+
"rewards/accuracies": 0.7734375,
|
| 907 |
+
"rewards/chosen": -0.13382621109485626,
|
| 908 |
+
"rewards/margins": 0.08140003681182861,
|
| 909 |
+
"rewards/rejected": -0.21522626280784607,
|
| 910 |
+
"step": 53
|
| 911 |
+
},
|
| 912 |
+
{
|
| 913 |
+
"epoch": 0.7114038699053108,
|
| 914 |
+
"grad_norm": 10311.740234375,
|
| 915 |
+
"learning_rate": 1.1171721146870014e-07,
|
| 916 |
+
"logits/chosen": 10.100930213928223,
|
| 917 |
+
"logits/rejected": 11.922209739685059,
|
| 918 |
+
"logps/chosen": -167.86460876464844,
|
| 919 |
+
"logps/ref_chosen": -155.794921875,
|
| 920 |
+
"logps/ref_rejected": -222.0970001220703,
|
| 921 |
+
"logps/rejected": -242.7193603515625,
|
| 922 |
+
"loss": 1835.6443,
|
| 923 |
+
"rewards/accuracies": 0.7421875,
|
| 924 |
+
"rewards/chosen": -0.12069660425186157,
|
| 925 |
+
"rewards/margins": 0.08552709221839905,
|
| 926 |
+
"rewards/rejected": -0.20622371137142181,
|
| 927 |
+
"step": 54
|
| 928 |
+
},
|
| 929 |
+
{
|
| 930 |
+
"epoch": 0.724578015644298,
|
| 931 |
+
"grad_norm": 20666.41796875,
|
| 932 |
+
"learning_rate": 1.0210694689661939e-07,
|
| 933 |
+
"logits/chosen": 10.870552062988281,
|
| 934 |
+
"logits/rejected": 12.210179328918457,
|
| 935 |
+
"logps/chosen": -167.26083374023438,
|
| 936 |
+
"logps/ref_chosen": -154.5961151123047,
|
| 937 |
+
"logps/ref_rejected": -198.23287963867188,
|
| 938 |
+
"logps/rejected": -219.563232421875,
|
| 939 |
+
"loss": 1838.6727,
|
| 940 |
+
"rewards/accuracies": 0.734375,
|
| 941 |
+
"rewards/chosen": -0.12664711475372314,
|
| 942 |
+
"rewards/margins": 0.08665640652179718,
|
| 943 |
+
"rewards/rejected": -0.21330350637435913,
|
| 944 |
+
"step": 55
|
| 945 |
+
},
|
| 946 |
+
{
|
| 947 |
+
"epoch": 0.7377521613832853,
|
| 948 |
+
"grad_norm": 12419.9189453125,
|
| 949 |
+
"learning_rate": 9.282178335227883e-08,
|
| 950 |
+
"logits/chosen": 10.5328369140625,
|
| 951 |
+
"logits/rejected": 12.453206062316895,
|
| 952 |
+
"logps/chosen": -174.7346954345703,
|
| 953 |
+
"logps/ref_chosen": -161.43161010742188,
|
| 954 |
+
"logps/ref_rejected": -234.3523406982422,
|
| 955 |
+
"logps/rejected": -255.97085571289062,
|
| 956 |
+
"loss": 1872.5292,
|
| 957 |
+
"rewards/accuracies": 0.734375,
|
| 958 |
+
"rewards/chosen": -0.1330309808254242,
|
| 959 |
+
"rewards/margins": 0.08315423130989075,
|
| 960 |
+
"rewards/rejected": -0.21618521213531494,
|
| 961 |
+
"step": 56
|
| 962 |
+
},
|
| 963 |
+
{
|
| 964 |
+
"epoch": 0.7509263071222725,
|
| 965 |
+
"grad_norm": 12207.43359375,
|
| 966 |
+
"learning_rate": 8.388213164029459e-08,
|
| 967 |
+
"logits/chosen": 10.50916862487793,
|
| 968 |
+
"logits/rejected": 12.343366622924805,
|
| 969 |
+
"logps/chosen": -172.4225311279297,
|
| 970 |
+
"logps/ref_chosen": -160.62217712402344,
|
| 971 |
+
"logps/ref_rejected": -219.34567260742188,
|
| 972 |
+
"logps/rejected": -239.6280975341797,
|
| 973 |
+
"loss": 1856.4233,
|
| 974 |
+
"rewards/accuracies": 0.7890625,
|
| 975 |
+
"rewards/chosen": -0.11800336837768555,
|
| 976 |
+
"rewards/margins": 0.08482098579406738,
|
| 977 |
+
"rewards/rejected": -0.20282435417175293,
|
| 978 |
+
"step": 57
|
| 979 |
+
},
|
| 980 |
+
{
|
| 981 |
+
"epoch": 0.7641004528612598,
|
| 982 |
+
"grad_norm": 27370.607421875,
|
| 983 |
+
"learning_rate": 7.530764305528958e-08,
|
| 984 |
+
"logits/chosen": 10.724642753601074,
|
| 985 |
+
"logits/rejected": 12.51488208770752,
|
| 986 |
+
"logps/chosen": -174.37432861328125,
|
| 987 |
+
"logps/ref_chosen": -161.2979278564453,
|
| 988 |
+
"logps/ref_rejected": -216.2406768798828,
|
| 989 |
+
"logps/rejected": -237.42999267578125,
|
| 990 |
+
"loss": 1883.3052,
|
| 991 |
+
"rewards/accuracies": 0.75,
|
| 992 |
+
"rewards/chosen": -0.13076403737068176,
|
| 993 |
+
"rewards/margins": 0.08112910389900208,
|
| 994 |
+
"rewards/rejected": -0.21189314126968384,
|
| 995 |
+
"step": 58
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"epoch": 0.7772745986002471,
|
| 999 |
+
"grad_norm": 15603.9853515625,
|
| 1000 |
+
"learning_rate": 6.711716618408281e-08,
|
| 1001 |
+
"logits/chosen": 10.534276008605957,
|
| 1002 |
+
"logits/rejected": 12.399603843688965,
|
| 1003 |
+
"logps/chosen": -182.76055908203125,
|
| 1004 |
+
"logps/ref_chosen": -169.86993408203125,
|
| 1005 |
+
"logps/ref_rejected": -228.6754150390625,
|
| 1006 |
+
"logps/rejected": -250.46022033691406,
|
| 1007 |
+
"loss": 1815.3439,
|
| 1008 |
+
"rewards/accuracies": 0.7578125,
|
| 1009 |
+
"rewards/chosen": -0.1289062201976776,
|
| 1010 |
+
"rewards/margins": 0.08894172310829163,
|
| 1011 |
+
"rewards/rejected": -0.21784794330596924,
|
| 1012 |
+
"step": 59
|
| 1013 |
+
},
|
| 1014 |
+
{
|
| 1015 |
+
"epoch": 0.7904487443392343,
|
| 1016 |
+
"grad_norm": 71340.25,
|
| 1017 |
+
"learning_rate": 5.932870547240454e-08,
|
| 1018 |
+
"logits/chosen": 10.734026908874512,
|
| 1019 |
+
"logits/rejected": 12.618619918823242,
|
| 1020 |
+
"logps/chosen": -178.24600219726562,
|
| 1021 |
+
"logps/ref_chosen": -165.35691833496094,
|
| 1022 |
+
"logps/ref_rejected": -216.50196838378906,
|
| 1023 |
+
"logps/rejected": -238.1607666015625,
|
| 1024 |
+
"loss": 1852.4353,
|
| 1025 |
+
"rewards/accuracies": 0.734375,
|
| 1026 |
+
"rewards/chosen": -0.12889079749584198,
|
| 1027 |
+
"rewards/margins": 0.08769731223583221,
|
| 1028 |
+
"rewards/rejected": -0.216588094830513,
|
| 1029 |
+
"step": 60
|
| 1030 |
+
},
|
| 1031 |
+
{
|
| 1032 |
+
"epoch": 0.8036228900782215,
|
| 1033 |
+
"grad_norm": 9574.0517578125,
|
| 1034 |
+
"learning_rate": 5.1959381647217665e-08,
|
| 1035 |
+
"logits/chosen": 10.777511596679688,
|
| 1036 |
+
"logits/rejected": 12.479795455932617,
|
| 1037 |
+
"logps/chosen": -175.54603576660156,
|
| 1038 |
+
"logps/ref_chosen": -162.25531005859375,
|
| 1039 |
+
"logps/ref_rejected": -220.494384765625,
|
| 1040 |
+
"logps/rejected": -243.2533416748047,
|
| 1041 |
+
"loss": 1753.2714,
|
| 1042 |
+
"rewards/accuracies": 0.7578125,
|
| 1043 |
+
"rewards/chosen": -0.13290727138519287,
|
| 1044 |
+
"rewards/margins": 0.09468262642621994,
|
| 1045 |
+
"rewards/rejected": -0.2275899201631546,
|
| 1046 |
+
"step": 61
|
| 1047 |
+
},
|
| 1048 |
+
{
|
| 1049 |
+
"epoch": 0.8167970358172087,
|
| 1050 |
+
"grad_norm": 26564.2890625,
|
| 1051 |
+
"learning_rate": 4.502539408164385e-08,
|
| 1052 |
+
"logits/chosen": 10.69074535369873,
|
| 1053 |
+
"logits/rejected": 12.0176420211792,
|
| 1054 |
+
"logps/chosen": -171.533447265625,
|
| 1055 |
+
"logps/ref_chosen": -158.19802856445312,
|
| 1056 |
+
"logps/ref_rejected": -208.67080688476562,
|
| 1057 |
+
"logps/rejected": -232.66183471679688,
|
| 1058 |
+
"loss": 1677.411,
|
| 1059 |
+
"rewards/accuracies": 0.78125,
|
| 1060 |
+
"rewards/chosen": -0.1333540380001068,
|
| 1061 |
+
"rewards/margins": 0.10655638575553894,
|
| 1062 |
+
"rewards/rejected": -0.23991039395332336,
|
| 1063 |
+
"step": 62
|
| 1064 |
+
},
|
| 1065 |
+
{
|
| 1066 |
+
"epoch": 0.829971181556196,
|
| 1067 |
+
"grad_norm": 24166.138671875,
|
| 1068 |
+
"learning_rate": 3.854198518522564e-08,
|
| 1069 |
+
"logits/chosen": 11.202211380004883,
|
| 1070 |
+
"logits/rejected": 12.737436294555664,
|
| 1071 |
+
"logps/chosen": -161.5748748779297,
|
| 1072 |
+
"logps/ref_chosen": -148.0422821044922,
|
| 1073 |
+
"logps/ref_rejected": -207.79806518554688,
|
| 1074 |
+
"logps/rejected": -231.32986450195312,
|
| 1075 |
+
"loss": 1745.3698,
|
| 1076 |
+
"rewards/accuracies": 0.78125,
|
| 1077 |
+
"rewards/chosen": -0.13532598316669464,
|
| 1078 |
+
"rewards/margins": 0.09999207407236099,
|
| 1079 |
+
"rewards/rejected": -0.23531804978847504,
|
| 1080 |
+
"step": 63
|
| 1081 |
+
},
|
| 1082 |
+
{
|
| 1083 |
+
"epoch": 0.8431453272951832,
|
| 1084 |
+
"grad_norm": 12767.322265625,
|
| 1085 |
+
"learning_rate": 3.2523406897802444e-08,
|
| 1086 |
+
"logits/chosen": 10.359135627746582,
|
| 1087 |
+
"logits/rejected": 12.093786239624023,
|
| 1088 |
+
"logps/chosen": -177.4307098388672,
|
| 1089 |
+
"logps/ref_chosen": -163.5407257080078,
|
| 1090 |
+
"logps/ref_rejected": -224.48919677734375,
|
| 1091 |
+
"logps/rejected": -246.38369750976562,
|
| 1092 |
+
"loss": 1874.9249,
|
| 1093 |
+
"rewards/accuracies": 0.75,
|
| 1094 |
+
"rewards/chosen": -0.13889965415000916,
|
| 1095 |
+
"rewards/margins": 0.08004540950059891,
|
| 1096 |
+
"rewards/rejected": -0.21894504129886627,
|
| 1097 |
+
"step": 64
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"epoch": 0.8563194730341704,
|
| 1101 |
+
"grad_norm": 14668.08984375,
|
| 1102 |
+
"learning_rate": 2.6982889360653376e-08,
|
| 1103 |
+
"logits/chosen": 10.696892738342285,
|
| 1104 |
+
"logits/rejected": 12.215542793273926,
|
| 1105 |
+
"logps/chosen": -173.01846313476562,
|
| 1106 |
+
"logps/ref_chosen": -160.5009002685547,
|
| 1107 |
+
"logps/ref_rejected": -211.37118530273438,
|
| 1108 |
+
"logps/rejected": -233.85008239746094,
|
| 1109 |
+
"loss": 1776.182,
|
| 1110 |
+
"rewards/accuracies": 0.734375,
|
| 1111 |
+
"rewards/chosen": -0.12517546117305756,
|
| 1112 |
+
"rewards/margins": 0.09961352497339249,
|
| 1113 |
+
"rewards/rejected": -0.22478897869586945,
|
| 1114 |
+
"step": 65
|
| 1115 |
+
},
|
| 1116 |
+
{
|
| 1117 |
+
"epoch": 0.8694936187731577,
|
| 1118 |
+
"grad_norm": 12370.1103515625,
|
| 1119 |
+
"learning_rate": 2.1932611833775843e-08,
|
| 1120 |
+
"logits/chosen": 10.37360954284668,
|
| 1121 |
+
"logits/rejected": 12.511140823364258,
|
| 1122 |
+
"logps/chosen": -166.63487243652344,
|
| 1123 |
+
"logps/ref_chosen": -154.54409790039062,
|
| 1124 |
+
"logps/ref_rejected": -231.14816284179688,
|
| 1125 |
+
"logps/rejected": -253.3925018310547,
|
| 1126 |
+
"loss": 1777.5796,
|
| 1127 |
+
"rewards/accuracies": 0.71875,
|
| 1128 |
+
"rewards/chosen": -0.12090765684843063,
|
| 1129 |
+
"rewards/margins": 0.10153578966856003,
|
| 1130 |
+
"rewards/rejected": -0.22244344651699066,
|
| 1131 |
+
"step": 66
|
| 1132 |
+
},
|
| 1133 |
+
{
|
| 1134 |
+
"epoch": 0.8826677645121449,
|
| 1135 |
+
"grad_norm": 15428.384765625,
|
| 1136 |
+
"learning_rate": 1.738367592322837e-08,
|
| 1137 |
+
"logits/chosen": 10.974772453308105,
|
| 1138 |
+
"logits/rejected": 12.515716552734375,
|
| 1139 |
+
"logps/chosen": -171.48728942871094,
|
| 1140 |
+
"logps/ref_chosen": -159.49444580078125,
|
| 1141 |
+
"logps/ref_rejected": -230.03280639648438,
|
| 1142 |
+
"logps/rejected": -253.75392150878906,
|
| 1143 |
+
"loss": 1594.3688,
|
| 1144 |
+
"rewards/accuracies": 0.8203125,
|
| 1145 |
+
"rewards/chosen": -0.11992834508419037,
|
| 1146 |
+
"rewards/margins": 0.11728263646364212,
|
| 1147 |
+
"rewards/rejected": -0.23721098899841309,
|
| 1148 |
+
"step": 67
|
| 1149 |
+
},
|
| 1150 |
+
{
|
| 1151 |
+
"epoch": 0.8958419102511321,
|
| 1152 |
+
"grad_norm": 22908.02734375,
|
| 1153 |
+
"learning_rate": 1.3346081177391472e-08,
|
| 1154 |
+
"logits/chosen": 10.686259269714355,
|
| 1155 |
+
"logits/rejected": 12.728968620300293,
|
| 1156 |
+
"logps/chosen": -170.5590362548828,
|
| 1157 |
+
"logps/ref_chosen": -156.81529235839844,
|
| 1158 |
+
"logps/ref_rejected": -221.17074584960938,
|
| 1159 |
+
"logps/rejected": -243.7953643798828,
|
| 1160 |
+
"loss": 1861.9591,
|
| 1161 |
+
"rewards/accuracies": 0.7890625,
|
| 1162 |
+
"rewards/chosen": -0.13743749260902405,
|
| 1163 |
+
"rewards/margins": 0.08880831301212311,
|
| 1164 |
+
"rewards/rejected": -0.22624580562114716,
|
| 1165 |
+
"step": 68
|
| 1166 |
+
},
|
| 1167 |
+
{
|
| 1168 |
+
"epoch": 0.9090160559901194,
|
| 1169 |
+
"grad_norm": 10145.42578125,
|
| 1170 |
+
"learning_rate": 9.828703105789981e-09,
|
| 1171 |
+
"logits/chosen": 10.347036361694336,
|
| 1172 |
+
"logits/rejected": 12.07924747467041,
|
| 1173 |
+
"logps/chosen": -182.86294555664062,
|
| 1174 |
+
"logps/ref_chosen": -169.18344116210938,
|
| 1175 |
+
"logps/ref_rejected": -232.31349182128906,
|
| 1176 |
+
"logps/rejected": -254.97625732421875,
|
| 1177 |
+
"loss": 1865.7443,
|
| 1178 |
+
"rewards/accuracies": 0.7734375,
|
| 1179 |
+
"rewards/chosen": -0.13679496943950653,
|
| 1180 |
+
"rewards/margins": 0.08983256667852402,
|
| 1181 |
+
"rewards/rejected": -0.22662749886512756,
|
| 1182 |
+
"step": 69
|
| 1183 |
+
},
|
| 1184 |
+
{
|
| 1185 |
+
"epoch": 0.9221902017291066,
|
| 1186 |
+
"grad_norm": 8302.9306640625,
|
| 1187 |
+
"learning_rate": 6.839273668796747e-09,
|
| 1188 |
+
"logits/chosen": 10.348489761352539,
|
| 1189 |
+
"logits/rejected": 12.23324966430664,
|
| 1190 |
+
"logps/chosen": -170.16281127929688,
|
| 1191 |
+
"logps/ref_chosen": -158.03448486328125,
|
| 1192 |
+
"logps/ref_rejected": -225.31153869628906,
|
| 1193 |
+
"logps/rejected": -246.83346557617188,
|
| 1194 |
+
"loss": 1775.8556,
|
| 1195 |
+
"rewards/accuracies": 0.84375,
|
| 1196 |
+
"rewards/chosen": -0.12128321081399918,
|
| 1197 |
+
"rewards/margins": 0.09393597394227982,
|
| 1198 |
+
"rewards/rejected": -0.21521919965744019,
|
| 1199 |
+
"step": 70
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"epoch": 0.9353643474680938,
|
| 1203 |
+
"grad_norm": 12248.0986328125,
|
| 1204 |
+
"learning_rate": 4.384364281105973e-09,
|
| 1205 |
+
"logits/chosen": 10.616415023803711,
|
| 1206 |
+
"logits/rejected": 12.532967567443848,
|
| 1207 |
+
"logps/chosen": -171.670166015625,
|
| 1208 |
+
"logps/ref_chosen": -158.83453369140625,
|
| 1209 |
+
"logps/ref_rejected": -239.87445068359375,
|
| 1210 |
+
"logps/rejected": -262.4039306640625,
|
| 1211 |
+
"loss": 1779.5031,
|
| 1212 |
+
"rewards/accuracies": 0.7734375,
|
| 1213 |
+
"rewards/chosen": -0.12835629284381866,
|
| 1214 |
+
"rewards/margins": 0.09693824499845505,
|
| 1215 |
+
"rewards/rejected": -0.22529453039169312,
|
| 1216 |
+
"step": 71
|
| 1217 |
+
},
|
| 1218 |
+
{
|
| 1219 |
+
"epoch": 0.9485384932070811,
|
| 1220 |
+
"grad_norm": 10943.583984375,
|
| 1221 |
+
"learning_rate": 2.469371366337264e-09,
|
| 1222 |
+
"logits/chosen": 10.554719924926758,
|
| 1223 |
+
"logits/rejected": 11.937162399291992,
|
| 1224 |
+
"logps/chosen": -173.85369873046875,
|
| 1225 |
+
"logps/ref_chosen": -159.11024475097656,
|
| 1226 |
+
"logps/ref_rejected": -211.9455108642578,
|
| 1227 |
+
"logps/rejected": -233.4796600341797,
|
| 1228 |
+
"loss": 1994.6278,
|
| 1229 |
+
"rewards/accuracies": 0.71875,
|
| 1230 |
+
"rewards/chosen": -0.14743441343307495,
|
| 1231 |
+
"rewards/margins": 0.06790698319673538,
|
| 1232 |
+
"rewards/rejected": -0.21534140408039093,
|
| 1233 |
+
"step": 72
|
| 1234 |
+
},
|
| 1235 |
+
{
|
| 1236 |
+
"epoch": 0.9617126389460683,
|
| 1237 |
+
"grad_norm": 12969.0283203125,
|
| 1238 |
+
"learning_rate": 1.0985044945254762e-09,
|
| 1239 |
+
"logits/chosen": 10.339526176452637,
|
| 1240 |
+
"logits/rejected": 12.487238883972168,
|
| 1241 |
+
"logps/chosen": -173.41607666015625,
|
| 1242 |
+
"logps/ref_chosen": -157.61448669433594,
|
| 1243 |
+
"logps/ref_rejected": -225.59930419921875,
|
| 1244 |
+
"logps/rejected": -248.25836181640625,
|
| 1245 |
+
"loss": 2010.3801,
|
| 1246 |
+
"rewards/accuracies": 0.703125,
|
| 1247 |
+
"rewards/chosen": -0.15801577270030975,
|
| 1248 |
+
"rewards/margins": 0.06857465207576752,
|
| 1249 |
+
"rewards/rejected": -0.22659042477607727,
|
| 1250 |
+
"step": 73
|
| 1251 |
+
},
|
| 1252 |
+
{
|
| 1253 |
+
"epoch": 0.9748867846850556,
|
| 1254 |
+
"grad_norm": 24462.5859375,
|
| 1255 |
+
"learning_rate": 2.7477712857215675e-10,
|
| 1256 |
+
"logits/chosen": 10.5087251663208,
|
| 1257 |
+
"logits/rejected": 12.400618553161621,
|
| 1258 |
+
"logps/chosen": -177.38507080078125,
|
| 1259 |
+
"logps/ref_chosen": -163.93447875976562,
|
| 1260 |
+
"logps/ref_rejected": -230.9633331298828,
|
| 1261 |
+
"logps/rejected": -254.17288208007812,
|
| 1262 |
+
"loss": 1767.8358,
|
| 1263 |
+
"rewards/accuracies": 0.7265625,
|
| 1264 |
+
"rewards/chosen": -0.13450586795806885,
|
| 1265 |
+
"rewards/margins": 0.09758953750133514,
|
| 1266 |
+
"rewards/rejected": -0.232095405459404,
|
| 1267 |
+
"step": 74
|
| 1268 |
+
},
|
| 1269 |
+
{
|
| 1270 |
+
"epoch": 0.9880609304240429,
|
| 1271 |
+
"grad_norm": 13426.73046875,
|
| 1272 |
+
"learning_rate": 0.0,
|
| 1273 |
+
"logits/chosen": 10.439515113830566,
|
| 1274 |
+
"logits/rejected": 11.782793998718262,
|
| 1275 |
+
"logps/chosen": -171.70106506347656,
|
| 1276 |
+
"logps/ref_chosen": -158.7339324951172,
|
| 1277 |
+
"logps/ref_rejected": -209.8782196044922,
|
| 1278 |
+
"logps/rejected": -233.0037078857422,
|
| 1279 |
+
"loss": 1718.665,
|
| 1280 |
+
"rewards/accuracies": 0.796875,
|
| 1281 |
+
"rewards/chosen": -0.1296713650226593,
|
| 1282 |
+
"rewards/margins": 0.10158350318670273,
|
| 1283 |
+
"rewards/rejected": -0.23125486075878143,
|
| 1284 |
+
"step": 75
|
| 1285 |
+
},
|
| 1286 |
+
{
|
| 1287 |
+
"epoch": 0.9880609304240429,
|
| 1288 |
+
"step": 75,
|
| 1289 |
+
"total_flos": 0.0,
|
| 1290 |
+
"train_loss": 2099.8924772135415,
|
| 1291 |
+
"train_runtime": 5573.0674,
|
| 1292 |
+
"train_samples_per_second": 1.743,
|
| 1293 |
+
"train_steps_per_second": 0.013
|
| 1294 |
+
}
|
| 1295 |
+
],
|
| 1296 |
+
"logging_steps": 1,
|
| 1297 |
+
"max_steps": 75,
|
| 1298 |
+
"num_input_tokens_seen": 0,
|
| 1299 |
+
"num_train_epochs": 1,
|
| 1300 |
+
"save_steps": 100000,
|
| 1301 |
+
"stateful_callbacks": {
|
| 1302 |
+
"TrainerControl": {
|
| 1303 |
+
"args": {
|
| 1304 |
+
"should_epoch_stop": false,
|
| 1305 |
+
"should_evaluate": false,
|
| 1306 |
+
"should_log": false,
|
| 1307 |
+
"should_save": false,
|
| 1308 |
+
"should_training_stop": false
|
| 1309 |
+
},
|
| 1310 |
+
"attributes": {}
|
| 1311 |
+
}
|
| 1312 |
+
},
|
| 1313 |
+
"total_flos": 0.0,
|
| 1314 |
+
"train_batch_size": 2,
|
| 1315 |
+
"trial_name": null,
|
| 1316 |
+
"trial_params": null
|
| 1317 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ecafaaad82867f1455ca0a7e598567ed3377c0316ecfa7db3587eb01b72cef33
|
| 3 |
+
size 7352
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
base_model: /home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct
|
| 4 |
+
tags:
|
| 5 |
+
- alignment-handbook
|
| 6 |
+
- generated_from_trainer
|
| 7 |
+
datasets:
|
| 8 |
+
- /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math
|
| 9 |
+
model-index:
|
| 10 |
+
- name: Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3
|
| 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 |
+
# Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3
|
| 18 |
+
|
| 19 |
+
This model is a fine-tuned version of [/home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct](https://huggingface.co//home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct) on the /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math dataset.
|
| 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: 5e-07
|
| 39 |
+
- train_batch_size: 2
|
| 40 |
+
- eval_batch_size: 4
|
| 41 |
+
- seed: 42
|
| 42 |
+
- distributed_type: multi-GPU
|
| 43 |
+
- gradient_accumulation_steps: 64
|
| 44 |
+
- total_train_batch_size: 128
|
| 45 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
| 46 |
+
- lr_scheduler_type: cosine
|
| 47 |
+
- lr_scheduler_warmup_ratio: 0.1
|
| 48 |
+
- num_epochs: 1
|
| 49 |
+
|
| 50 |
+
### Training results
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
### Framework versions
|
| 55 |
+
|
| 56 |
+
- Transformers 4.45.2
|
| 57 |
+
- Pytorch 2.5.1+cu121
|
| 58 |
+
- Datasets 3.5.0
|
| 59 |
+
- Tokenizers 0.20.3
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/added_tokens.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<|assistant|>": 32001,
|
| 3 |
+
"<|endoftext|>": 32000,
|
| 4 |
+
"<|end|>": 32007,
|
| 5 |
+
"<|placeholder1|>": 32002,
|
| 6 |
+
"<|placeholder2|>": 32003,
|
| 7 |
+
"<|placeholder3|>": 32004,
|
| 8 |
+
"<|placeholder4|>": 32005,
|
| 9 |
+
"<|placeholder5|>": 32008,
|
| 10 |
+
"<|placeholder6|>": 32009,
|
| 11 |
+
"<|system|>": 32006,
|
| 12 |
+
"<|user|>": 32010
|
| 13 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/all_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9969120977149523,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 1546.3839571108376,
|
| 5 |
+
"train_runtime": 17027.6856,
|
| 6 |
+
"train_samples": 29145,
|
| 7 |
+
"train_samples_per_second": 1.712,
|
| 8 |
+
"train_steps_per_second": 0.013
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Phi3ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "configuration_phi3.Phi3Config",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 1,
|
| 13 |
+
"embd_pdrop": 0.0,
|
| 14 |
+
"eos_token_id": 32000,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 3072,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 8192,
|
| 19 |
+
"max_position_embeddings": 4096,
|
| 20 |
+
"model_type": "phi3",
|
| 21 |
+
"num_attention_heads": 32,
|
| 22 |
+
"num_hidden_layers": 32,
|
| 23 |
+
"num_key_value_heads": 32,
|
| 24 |
+
"original_max_position_embeddings": 4096,
|
| 25 |
+
"pad_token_id": 32000,
|
| 26 |
+
"resid_pdrop": 0.0,
|
| 27 |
+
"rms_norm_eps": 1e-05,
|
| 28 |
+
"rope_scaling": null,
|
| 29 |
+
"rope_theta": 10000.0,
|
| 30 |
+
"sliding_window": 2047,
|
| 31 |
+
"tie_word_embeddings": false,
|
| 32 |
+
"torch_dtype": "bfloat16",
|
| 33 |
+
"transformers_version": "4.45.2",
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32064
|
| 36 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/configuration_phi3.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" Phi-3 model configuration"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 20 |
+
from transformers.utils import logging
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
logger = logging.get_logger(__name__)
|
| 24 |
+
|
| 25 |
+
PHI3_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
| 26 |
+
"microsoft/Phi-3-mini-4k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/resolve/main/config.json",
|
| 27 |
+
"microsoft/Phi-3-mini-128k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/resolve/main/config.json",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Phi3Config(PretrainedConfig):
|
| 32 |
+
r"""
|
| 33 |
+
This is the configuration class to store the configuration of a [`Phi3Model`]. It is used to instantiate a Phi-3
|
| 34 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 35 |
+
defaults will yield a similar configuration to that of the
|
| 36 |
+
[microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
|
| 37 |
+
|
| 38 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 39 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
vocab_size (`int`, *optional*, defaults to 32064):
|
| 43 |
+
Vocabulary size of the Phi-3 model. Defines the number of different tokens that can be represented by the
|
| 44 |
+
`inputs_ids` passed when calling [`Phi3Model`].
|
| 45 |
+
hidden_size (`int`, *optional*, defaults to 3072):
|
| 46 |
+
Dimension of the hidden representations.
|
| 47 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
| 48 |
+
Dimension of the MLP representations.
|
| 49 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 50 |
+
Number of hidden layers in the Transformer decoder.
|
| 51 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 52 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 53 |
+
num_key_value_heads (`int`, *optional*):
|
| 54 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 55 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 56 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 57 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 58 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 59 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 60 |
+
`num_attention_heads`.
|
| 61 |
+
resid_pdrop (`float`, *optional*, defaults to 0.0):
|
| 62 |
+
Dropout probability for mlp outputs.
|
| 63 |
+
embd_pdrop (`int`, *optional*, defaults to 0.0):
|
| 64 |
+
The dropout ratio for the embeddings.
|
| 65 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 66 |
+
The dropout ratio after computing the attention scores.
|
| 67 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 68 |
+
The non-linear activation function (function or string) in the decoder.
|
| 69 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 70 |
+
The maximum sequence length that this model might ever be used with.
|
| 71 |
+
original_max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 72 |
+
The maximum sequence length that this model was trained with. This is used to determine the size of the
|
| 73 |
+
original RoPE embeddings when using long scaling.
|
| 74 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 75 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 76 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 77 |
+
The epsilon value used for the RMSNorm.
|
| 78 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 79 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 80 |
+
relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
|
| 81 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 82 |
+
Whether to tie weight embeddings
|
| 83 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 84 |
+
The base period of the RoPE embeddings.
|
| 85 |
+
rope_scaling (`dict`, *optional*):
|
| 86 |
+
The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
|
| 87 |
+
contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be `longrope` and
|
| 88 |
+
the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
|
| 89 |
+
divided by the number of attention heads divided by 2.
|
| 90 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 91 |
+
The id of the "beginning-of-sequence" token.
|
| 92 |
+
eos_token_id (`int`, *optional*, defaults to 32000):
|
| 93 |
+
The id of the "end-of-sequence" token.
|
| 94 |
+
pad_token_id (`int`, *optional*, defaults to 32000):
|
| 95 |
+
The id of the padding token.
|
| 96 |
+
sliding_window (`int`, *optional*):
|
| 97 |
+
Sliding window attention window size. If `None`, no sliding window is applied.
|
| 98 |
+
|
| 99 |
+
Example:
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
>>> from transformers import Phi3Model, Phi3Config
|
| 103 |
+
|
| 104 |
+
>>> # Initializing a Phi-3 style configuration
|
| 105 |
+
>>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 106 |
+
|
| 107 |
+
>>> # Initializing a model from the configuration
|
| 108 |
+
>>> model = Phi3Model(configuration)
|
| 109 |
+
|
| 110 |
+
>>> # Accessing the model configuration
|
| 111 |
+
>>> configuration = model.config
|
| 112 |
+
```"""
|
| 113 |
+
|
| 114 |
+
model_type = "phi3"
|
| 115 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
+
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
vocab_size=32064,
|
| 120 |
+
hidden_size=3072,
|
| 121 |
+
intermediate_size=8192,
|
| 122 |
+
num_hidden_layers=32,
|
| 123 |
+
num_attention_heads=32,
|
| 124 |
+
num_key_value_heads=None,
|
| 125 |
+
resid_pdrop=0.0,
|
| 126 |
+
embd_pdrop=0.0,
|
| 127 |
+
attention_dropout=0.0,
|
| 128 |
+
hidden_act="silu",
|
| 129 |
+
max_position_embeddings=4096,
|
| 130 |
+
original_max_position_embeddings=4096,
|
| 131 |
+
initializer_range=0.02,
|
| 132 |
+
rms_norm_eps=1e-5,
|
| 133 |
+
use_cache=True,
|
| 134 |
+
tie_word_embeddings=False,
|
| 135 |
+
rope_theta=10000.0,
|
| 136 |
+
rope_scaling=None,
|
| 137 |
+
bos_token_id=1,
|
| 138 |
+
eos_token_id=32000,
|
| 139 |
+
pad_token_id=32000,
|
| 140 |
+
sliding_window=None,
|
| 141 |
+
**kwargs,
|
| 142 |
+
):
|
| 143 |
+
self.vocab_size = vocab_size
|
| 144 |
+
self.hidden_size = hidden_size
|
| 145 |
+
self.intermediate_size = intermediate_size
|
| 146 |
+
self.num_hidden_layers = num_hidden_layers
|
| 147 |
+
self.num_attention_heads = num_attention_heads
|
| 148 |
+
|
| 149 |
+
if num_key_value_heads is None:
|
| 150 |
+
num_key_value_heads = num_attention_heads
|
| 151 |
+
|
| 152 |
+
self.num_key_value_heads = num_key_value_heads
|
| 153 |
+
self.resid_pdrop = resid_pdrop
|
| 154 |
+
self.embd_pdrop = embd_pdrop
|
| 155 |
+
self.attention_dropout = attention_dropout
|
| 156 |
+
self.hidden_act = hidden_act
|
| 157 |
+
self.max_position_embeddings = max_position_embeddings
|
| 158 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
| 159 |
+
self.initializer_range = initializer_range
|
| 160 |
+
self.rms_norm_eps = rms_norm_eps
|
| 161 |
+
self.use_cache = use_cache
|
| 162 |
+
self.rope_theta = rope_theta
|
| 163 |
+
self.rope_scaling = rope_scaling
|
| 164 |
+
self._rope_scaling_adjustment()
|
| 165 |
+
self._rope_scaling_validation()
|
| 166 |
+
self.sliding_window = sliding_window
|
| 167 |
+
|
| 168 |
+
super().__init__(
|
| 169 |
+
bos_token_id=bos_token_id,
|
| 170 |
+
eos_token_id=eos_token_id,
|
| 171 |
+
pad_token_id=pad_token_id,
|
| 172 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 173 |
+
**kwargs,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
def _rope_scaling_adjustment(self):
|
| 177 |
+
"""
|
| 178 |
+
Adjust the `type` of the `rope_scaling` configuration for backward compatibility.
|
| 179 |
+
"""
|
| 180 |
+
if self.rope_scaling is None:
|
| 181 |
+
return
|
| 182 |
+
|
| 183 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 184 |
+
|
| 185 |
+
# For backward compatibility if previous version used "su" or "yarn"
|
| 186 |
+
if rope_scaling_type is not None and rope_scaling_type in ["su", "yarn"]:
|
| 187 |
+
self.rope_scaling["type"] = "longrope"
|
| 188 |
+
|
| 189 |
+
def _rope_scaling_validation(self):
|
| 190 |
+
"""
|
| 191 |
+
Validate the `rope_scaling` configuration.
|
| 192 |
+
"""
|
| 193 |
+
if self.rope_scaling is None:
|
| 194 |
+
return
|
| 195 |
+
|
| 196 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
|
| 197 |
+
raise ValueError(
|
| 198 |
+
"`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
|
| 199 |
+
f"got {self.rope_scaling}"
|
| 200 |
+
)
|
| 201 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 202 |
+
rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
|
| 203 |
+
rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
|
| 204 |
+
if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
|
| 205 |
+
raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
|
| 206 |
+
if not (
|
| 207 |
+
isinstance(rope_scaling_short_factor, list)
|
| 208 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
|
| 209 |
+
):
|
| 210 |
+
raise ValueError(
|
| 211 |
+
f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
|
| 212 |
+
)
|
| 213 |
+
if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 214 |
+
raise ValueError(
|
| 215 |
+
f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
|
| 216 |
+
)
|
| 217 |
+
if not (
|
| 218 |
+
isinstance(rope_scaling_long_factor, list)
|
| 219 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
|
| 220 |
+
):
|
| 221 |
+
raise ValueError(
|
| 222 |
+
f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
|
| 223 |
+
)
|
| 224 |
+
if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 225 |
+
raise ValueError(
|
| 226 |
+
f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
|
| 227 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
32000,
|
| 6 |
+
32001,
|
| 7 |
+
32007
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 32000,
|
| 10 |
+
"transformers_version": "4.45.2"
|
| 11 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2458cf054c4ae16997857f1c186ebc7079c2513ff3cc45016bb234d8c98db5ef
|
| 3 |
+
size 4972489328
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ca06fd5061dc694c1717b408b33a930e6dc8c100ab7b442b16283a0391ef504
|
| 3 |
+
size 2669692552
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/model.safetensors.index.json
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 7642159104
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 7 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.10.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.10.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.11.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.11.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.12.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.12.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.13.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.13.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.14.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.14.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.15.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.15.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.16.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.16.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.17.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.17.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.18.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"model.layers.18.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"model.layers.19.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.19.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.20.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.20.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 93 |
+
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 94 |
+
"model.layers.21.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 95 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 96 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.21.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 98 |
+
"model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 99 |
+
"model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 100 |
+
"model.layers.22.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 101 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 102 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 103 |
+
"model.layers.22.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 104 |
+
"model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 105 |
+
"model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 106 |
+
"model.layers.23.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 107 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 108 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 109 |
+
"model.layers.23.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 110 |
+
"model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 111 |
+
"model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 112 |
+
"model.layers.24.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 113 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 114 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 115 |
+
"model.layers.24.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 116 |
+
"model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 117 |
+
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 118 |
+
"model.layers.25.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 119 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 120 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 121 |
+
"model.layers.25.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 122 |
+
"model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 123 |
+
"model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 124 |
+
"model.layers.26.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 125 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 126 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 127 |
+
"model.layers.26.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 128 |
+
"model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 129 |
+
"model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 130 |
+
"model.layers.27.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 131 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 132 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 133 |
+
"model.layers.27.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 134 |
+
"model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 135 |
+
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 136 |
+
"model.layers.28.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 137 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 138 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 139 |
+
"model.layers.28.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 140 |
+
"model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 141 |
+
"model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 142 |
+
"model.layers.29.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 143 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 144 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 145 |
+
"model.layers.29.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 146 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 152 |
+
"model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 153 |
+
"model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 154 |
+
"model.layers.30.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 155 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 156 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 157 |
+
"model.layers.30.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 158 |
+
"model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 159 |
+
"model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 160 |
+
"model.layers.31.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 161 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 162 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 163 |
+
"model.layers.31.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 164 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 165 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 166 |
+
"model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 167 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 168 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 169 |
+
"model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 170 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 171 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 172 |
+
"model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 173 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 174 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 175 |
+
"model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 176 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 177 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 178 |
+
"model.layers.6.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 179 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 180 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 181 |
+
"model.layers.6.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 182 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 183 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 184 |
+
"model.layers.7.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 185 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 186 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 187 |
+
"model.layers.7.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 188 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 189 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 190 |
+
"model.layers.8.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 191 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 192 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 193 |
+
"model.layers.8.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 194 |
+
"model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 195 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 196 |
+
"model.layers.9.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 197 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 198 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 199 |
+
"model.layers.9.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 200 |
+
"model.norm.weight": "model-00002-of-00002.safetensors"
|
| 201 |
+
}
|
| 202 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/modeling_phi3.py
ADDED
|
@@ -0,0 +1,1563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" PyTorch Phi-3 model."""
|
| 17 |
+
|
| 18 |
+
import inspect
|
| 19 |
+
import math
|
| 20 |
+
import warnings
|
| 21 |
+
from typing import List, Optional, Tuple, Union
|
| 22 |
+
|
| 23 |
+
import torch
|
| 24 |
+
import torch.nn.functional as F
|
| 25 |
+
import torch.utils.checkpoint
|
| 26 |
+
from torch import nn
|
| 27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 28 |
+
|
| 29 |
+
from transformers.activations import ACT2FN
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
|
| 32 |
+
from transformers.modeling_outputs import (
|
| 33 |
+
BaseModelOutputWithPast,
|
| 34 |
+
CausalLMOutputWithPast,
|
| 35 |
+
SequenceClassifierOutputWithPast,
|
| 36 |
+
TokenClassifierOutput,
|
| 37 |
+
)
|
| 38 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 39 |
+
from transformers.utils import (
|
| 40 |
+
add_code_sample_docstrings,
|
| 41 |
+
add_start_docstrings,
|
| 42 |
+
add_start_docstrings_to_model_forward,
|
| 43 |
+
is_flash_attn_2_available,
|
| 44 |
+
is_flash_attn_greater_or_equal_2_10,
|
| 45 |
+
logging,
|
| 46 |
+
replace_return_docstrings,
|
| 47 |
+
)
|
| 48 |
+
from .configuration_phi3 import Phi3Config
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
logger = logging.get_logger(__name__)
|
| 52 |
+
|
| 53 |
+
# Transformers scans dependencies in the modeling file, causing issues on conditional loading. The regex only ignores try/catch blocks, but not if statements
|
| 54 |
+
# if is_flash_attn_2_available():
|
| 55 |
+
_flash_supports_window_size = False
|
| 56 |
+
try:
|
| 57 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 58 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 59 |
+
|
| 60 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 61 |
+
except ImportError as error:
|
| 62 |
+
logger.warning(
|
| 63 |
+
f"`flash-attention` package not found, consider installing for better performance: {error}."
|
| 64 |
+
)
|
| 65 |
+
if not _flash_supports_window_size:
|
| 66 |
+
logger.warning(
|
| 67 |
+
"Current `flash-attention` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`."
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
_CHECKPOINT_FOR_DOC = "microsoft/Phi-3-mini-4k-instruct"
|
| 71 |
+
_CONFIG_FOR_DOC = "Phi3Config"
|
| 72 |
+
|
| 73 |
+
PHI3_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
| 74 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
| 75 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 76 |
+
# See all Phi-3 models at https://huggingface.co/models?filter=Phi-3
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Phi3
|
| 81 |
+
class Phi3RMSNorm(nn.Module):
|
| 82 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 83 |
+
"""
|
| 84 |
+
Phi3RMSNorm is equivalent to T5LayerNorm
|
| 85 |
+
"""
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 88 |
+
self.variance_epsilon = eps
|
| 89 |
+
|
| 90 |
+
def forward(self, hidden_states):
|
| 91 |
+
input_dtype = hidden_states.dtype
|
| 92 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 93 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 94 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 95 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
| 99 |
+
def _get_unpad_data(attention_mask):
|
| 100 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
| 101 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
| 102 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
| 103 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
| 104 |
+
return (
|
| 105 |
+
indices,
|
| 106 |
+
cu_seqlens,
|
| 107 |
+
max_seqlen_in_batch,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# Copied from transformers.models.gemma.modeling_gemma.GemmaRotaryEmbedding with gemma->phi3, Gemma->Phi3
|
| 112 |
+
class Phi3RotaryEmbedding(nn.Module):
|
| 113 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
| 114 |
+
super().__init__()
|
| 115 |
+
|
| 116 |
+
self.dim = dim
|
| 117 |
+
self.max_position_embeddings = max_position_embeddings
|
| 118 |
+
self.base = base
|
| 119 |
+
self.register_buffer("inv_freq", None, persistent=False)
|
| 120 |
+
|
| 121 |
+
@torch.no_grad()
|
| 122 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 123 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
| 124 |
+
if self.inv_freq is None:
|
| 125 |
+
self.inv_freq = 1.0 / (
|
| 126 |
+
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
|
| 127 |
+
)
|
| 128 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 129 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 130 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 131 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 132 |
+
device_type = x.device.type
|
| 133 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 134 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 135 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 136 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 137 |
+
cos = emb.cos()
|
| 138 |
+
sin = emb.sin()
|
| 139 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class Phi3LongRoPEScaledRotaryEmbedding(Phi3RotaryEmbedding):
|
| 143 |
+
def __init__(self, dim, config, device=None):
|
| 144 |
+
super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
|
| 145 |
+
|
| 146 |
+
self.short_factor = config.rope_scaling["short_factor"]
|
| 147 |
+
self.long_factor = config.rope_scaling["long_factor"]
|
| 148 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 149 |
+
|
| 150 |
+
@torch.no_grad()
|
| 151 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 152 |
+
seq_len = torch.max(position_ids) + 1
|
| 153 |
+
if seq_len > self.original_max_position_embeddings:
|
| 154 |
+
ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
|
| 155 |
+
else:
|
| 156 |
+
ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
|
| 157 |
+
|
| 158 |
+
inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
|
| 159 |
+
self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
|
| 160 |
+
|
| 161 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 162 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 163 |
+
|
| 164 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 165 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 166 |
+
device_type = x.device.type
|
| 167 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 168 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 169 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 170 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 171 |
+
|
| 172 |
+
scale = self.max_position_embeddings / self.original_max_position_embeddings
|
| 173 |
+
if scale <= 1.0:
|
| 174 |
+
scaling_factor = 1.0
|
| 175 |
+
else:
|
| 176 |
+
scaling_factor = math.sqrt(1 + math.log(scale) / math.log(self.original_max_position_embeddings))
|
| 177 |
+
|
| 178 |
+
cos = emb.cos() * scaling_factor
|
| 179 |
+
sin = emb.sin() * scaling_factor
|
| 180 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
| 184 |
+
def rotate_half(x):
|
| 185 |
+
"""Rotates half the hidden dims of the input."""
|
| 186 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 187 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 188 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
|
| 192 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 193 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 194 |
+
|
| 195 |
+
Args:
|
| 196 |
+
q (`torch.Tensor`): The query tensor.
|
| 197 |
+
k (`torch.Tensor`): The key tensor.
|
| 198 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 199 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 200 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 201 |
+
Deprecated and unused.
|
| 202 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 203 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 204 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 205 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 206 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 207 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 208 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 209 |
+
Returns:
|
| 210 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 211 |
+
"""
|
| 212 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 213 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 214 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 215 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 216 |
+
return q_embed, k_embed
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class Phi3MLP(nn.Module):
|
| 220 |
+
def __init__(self, config):
|
| 221 |
+
super().__init__()
|
| 222 |
+
|
| 223 |
+
self.config = config
|
| 224 |
+
self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
|
| 225 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 226 |
+
|
| 227 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
| 228 |
+
|
| 229 |
+
def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
|
| 230 |
+
up_states = self.gate_up_proj(hidden_states)
|
| 231 |
+
|
| 232 |
+
gate, up_states = up_states.chunk(2, dim=-1)
|
| 233 |
+
up_states = up_states * self.activation_fn(gate)
|
| 234 |
+
|
| 235 |
+
return self.down_proj(up_states)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
|
| 239 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 240 |
+
"""
|
| 241 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 242 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 243 |
+
"""
|
| 244 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 245 |
+
if n_rep == 1:
|
| 246 |
+
return hidden_states
|
| 247 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 248 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class Phi3Attention(nn.Module):
|
| 252 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 253 |
+
|
| 254 |
+
def __init__(self, config: Phi3Config, layer_idx: Optional[int] = None):
|
| 255 |
+
super().__init__()
|
| 256 |
+
self.config = config
|
| 257 |
+
self.layer_idx = layer_idx
|
| 258 |
+
if layer_idx is None:
|
| 259 |
+
logger.warning_once(
|
| 260 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 261 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 262 |
+
"when creating this class."
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
self.attention_dropout = config.attention_dropout
|
| 266 |
+
self.hidden_size = config.hidden_size
|
| 267 |
+
self.num_heads = config.num_attention_heads
|
| 268 |
+
self.head_dim = self.hidden_size // self.num_heads
|
| 269 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 270 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
| 271 |
+
self.max_position_embeddings = config.max_position_embeddings
|
| 272 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 273 |
+
self.rope_theta = config.rope_theta
|
| 274 |
+
self.rope_scaling = config.rope_scaling
|
| 275 |
+
self.is_causal = True
|
| 276 |
+
|
| 277 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
| 278 |
+
raise ValueError(
|
| 279 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
| 280 |
+
f" and `num_heads`: {self.num_heads})."
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
op_size = self.num_heads * self.head_dim + 2 * (self.num_key_value_heads * self.head_dim)
|
| 284 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
| 285 |
+
self.qkv_proj = nn.Linear(self.hidden_size, op_size, bias=False)
|
| 286 |
+
self._init_rope()
|
| 287 |
+
|
| 288 |
+
def _init_rope(self):
|
| 289 |
+
if self.rope_scaling is None:
|
| 290 |
+
self.rotary_emb = Phi3RotaryEmbedding(
|
| 291 |
+
self.head_dim,
|
| 292 |
+
max_position_embeddings=self.max_position_embeddings,
|
| 293 |
+
base=self.rope_theta,
|
| 294 |
+
)
|
| 295 |
+
else:
|
| 296 |
+
scaling_type = self.config.rope_scaling["type"]
|
| 297 |
+
if scaling_type == "longrope":
|
| 298 |
+
self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
|
| 299 |
+
else:
|
| 300 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
| 301 |
+
|
| 302 |
+
def forward(
|
| 303 |
+
self,
|
| 304 |
+
hidden_states: torch.Tensor,
|
| 305 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 306 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 307 |
+
past_key_value: Optional[Cache] = None,
|
| 308 |
+
output_attentions: bool = False,
|
| 309 |
+
use_cache: bool = False,
|
| 310 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 311 |
+
logger.warning_once("You are not running the flash-attention implementation, expect numerical differences.")
|
| 312 |
+
|
| 313 |
+
bsz, q_len, _ = hidden_states.size()
|
| 314 |
+
|
| 315 |
+
qkv = self.qkv_proj(hidden_states)
|
| 316 |
+
query_pos = self.num_heads * self.head_dim
|
| 317 |
+
query_states = qkv[..., :query_pos]
|
| 318 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 319 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 320 |
+
|
| 321 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 322 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 323 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 324 |
+
|
| 325 |
+
kv_seq_len = key_states.shape[-2]
|
| 326 |
+
if past_key_value is not None:
|
| 327 |
+
if self.layer_idx is None:
|
| 328 |
+
raise ValueError(
|
| 329 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 330 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 331 |
+
"with a layer index."
|
| 332 |
+
)
|
| 333 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 334 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 335 |
+
|
| 336 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 337 |
+
|
| 338 |
+
if past_key_value is not None:
|
| 339 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 340 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 341 |
+
|
| 342 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 343 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 344 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 345 |
+
|
| 346 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
| 347 |
+
|
| 348 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
| 349 |
+
raise ValueError(
|
| 350 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
| 351 |
+
f" {attn_weights.size()}"
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
if attention_mask is not None:
|
| 355 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 356 |
+
raise ValueError(
|
| 357 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 358 |
+
)
|
| 359 |
+
attn_weights = attn_weights + attention_mask
|
| 360 |
+
|
| 361 |
+
# upcast attention to fp32
|
| 362 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
|
| 363 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
| 364 |
+
|
| 365 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 366 |
+
|
| 367 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
| 368 |
+
raise ValueError(
|
| 369 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
| 370 |
+
f" {attn_output.size()}"
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 374 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
| 375 |
+
|
| 376 |
+
attn_output = self.o_proj(attn_output)
|
| 377 |
+
|
| 378 |
+
if not output_attentions:
|
| 379 |
+
attn_weights = None
|
| 380 |
+
|
| 381 |
+
return attn_output, attn_weights, past_key_value
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class Phi3FlashAttention2(Phi3Attention):
|
| 385 |
+
"""
|
| 386 |
+
Phi-3 flash attention module. This module inherits from `Phi3Attention` as the weights of the module stays
|
| 387 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
| 388 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
| 389 |
+
"""
|
| 390 |
+
|
| 391 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
|
| 392 |
+
def __init__(self, *args, **kwargs):
|
| 393 |
+
super().__init__(*args, **kwargs)
|
| 394 |
+
|
| 395 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
| 396 |
+
# 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.
|
| 397 |
+
# 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).
|
| 398 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
| 399 |
+
|
| 400 |
+
def forward(
|
| 401 |
+
self,
|
| 402 |
+
hidden_states: torch.Tensor,
|
| 403 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 404 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 405 |
+
past_key_value: Optional[Cache] = None,
|
| 406 |
+
output_attentions: bool = False,
|
| 407 |
+
use_cache: bool = False,
|
| 408 |
+
**kwargs,
|
| 409 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 410 |
+
# Phi3FlashAttention2 attention does not support output_attentions
|
| 411 |
+
|
| 412 |
+
if not _flash_supports_window_size:
|
| 413 |
+
logger.warning_once(
|
| 414 |
+
"The current flash attention version does not support sliding window attention. Please use `attn_implementation='eager'` or upgrade flash-attn library."
|
| 415 |
+
)
|
| 416 |
+
raise ValueError("The current flash attention version does not support sliding window attention.")
|
| 417 |
+
|
| 418 |
+
output_attentions = False
|
| 419 |
+
|
| 420 |
+
if "padding_mask" in kwargs:
|
| 421 |
+
warnings.warn(
|
| 422 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
# overwrite attention_mask with padding_mask
|
| 426 |
+
attention_mask = kwargs.pop("padding_mask")
|
| 427 |
+
|
| 428 |
+
bsz, q_len, _ = hidden_states.size()
|
| 429 |
+
|
| 430 |
+
qkv = self.qkv_proj(hidden_states)
|
| 431 |
+
query_pos = self.num_heads * self.head_dim
|
| 432 |
+
query_states = qkv[..., :query_pos]
|
| 433 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 434 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 435 |
+
|
| 436 |
+
# Flash attention requires the input to have the shape
|
| 437 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
| 438 |
+
# therefore we just need to keep the original shape
|
| 439 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 440 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 441 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 442 |
+
|
| 443 |
+
kv_seq_len = key_states.shape[-2]
|
| 444 |
+
if past_key_value is not None:
|
| 445 |
+
if self.layer_idx is None:
|
| 446 |
+
raise ValueError(
|
| 447 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 448 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 449 |
+
"with a layer index."
|
| 450 |
+
)
|
| 451 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 452 |
+
|
| 453 |
+
# Because the input can be padded, the absolute sequence length depends on the max position id.
|
| 454 |
+
rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
|
| 455 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=rotary_seq_len)
|
| 456 |
+
|
| 457 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 458 |
+
|
| 459 |
+
use_sliding_windows = (
|
| 460 |
+
_flash_supports_window_size
|
| 461 |
+
and getattr(self.config, "sliding_window", None) is not None
|
| 462 |
+
and kv_seq_len > self.config.sliding_window
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
if past_key_value is not None:
|
| 466 |
+
# Activate slicing cache only if the config has a value `sliding_windows` attribute
|
| 467 |
+
cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
|
| 468 |
+
if (
|
| 469 |
+
getattr(self.config, "sliding_window", None) is not None
|
| 470 |
+
and kv_seq_len > self.config.sliding_window
|
| 471 |
+
and cache_has_contents
|
| 472 |
+
):
|
| 473 |
+
slicing_tokens = 1 - self.config.sliding_window
|
| 474 |
+
|
| 475 |
+
past_key = past_key_value[self.layer_idx][0]
|
| 476 |
+
past_value = past_key_value[self.layer_idx][1]
|
| 477 |
+
|
| 478 |
+
past_key = past_key[:, :, slicing_tokens:, :].contiguous()
|
| 479 |
+
past_value = past_value[:, :, slicing_tokens:, :].contiguous()
|
| 480 |
+
|
| 481 |
+
if past_key.shape[-2] != self.config.sliding_window - 1:
|
| 482 |
+
raise ValueError(
|
| 483 |
+
f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
|
| 484 |
+
f" {past_key.shape}"
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
if attention_mask is not None:
|
| 488 |
+
attention_mask = attention_mask[:, slicing_tokens:]
|
| 489 |
+
attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
|
| 490 |
+
|
| 491 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 492 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 493 |
+
|
| 494 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 495 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 496 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 497 |
+
|
| 498 |
+
attn_dropout = self.attention_dropout if self.training else 0.0
|
| 499 |
+
|
| 500 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
| 501 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
| 502 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
| 503 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
| 504 |
+
# in fp32.
|
| 505 |
+
|
| 506 |
+
if query_states.dtype == torch.float32:
|
| 507 |
+
if torch.is_autocast_enabled():
|
| 508 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
| 509 |
+
# Handle the case where the model is quantized
|
| 510 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
| 511 |
+
target_dtype = self.config._pre_quantization_dtype
|
| 512 |
+
else:
|
| 513 |
+
target_dtype = self.qkv_proj.weight.dtype
|
| 514 |
+
|
| 515 |
+
logger.warning_once(
|
| 516 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
| 517 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
| 518 |
+
f" {target_dtype}."
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
query_states = query_states.to(target_dtype)
|
| 522 |
+
key_states = key_states.to(target_dtype)
|
| 523 |
+
value_states = value_states.to(target_dtype)
|
| 524 |
+
|
| 525 |
+
# Reashape to the expected shape for Flash Attention
|
| 526 |
+
query_states = query_states.transpose(1, 2)
|
| 527 |
+
key_states = key_states.transpose(1, 2)
|
| 528 |
+
value_states = value_states.transpose(1, 2)
|
| 529 |
+
|
| 530 |
+
attn_output = self._flash_attention_forward(
|
| 531 |
+
query_states,
|
| 532 |
+
key_states,
|
| 533 |
+
value_states,
|
| 534 |
+
attention_mask,
|
| 535 |
+
q_len,
|
| 536 |
+
dropout=attn_dropout,
|
| 537 |
+
use_sliding_windows=use_sliding_windows,
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
| 541 |
+
attn_output = self.o_proj(attn_output)
|
| 542 |
+
|
| 543 |
+
if not output_attentions:
|
| 544 |
+
attn_weights = None
|
| 545 |
+
|
| 546 |
+
return attn_output, attn_weights, past_key_value
|
| 547 |
+
|
| 548 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._flash_attention_forward
|
| 549 |
+
def _flash_attention_forward(
|
| 550 |
+
self,
|
| 551 |
+
query_states,
|
| 552 |
+
key_states,
|
| 553 |
+
value_states,
|
| 554 |
+
attention_mask,
|
| 555 |
+
query_length,
|
| 556 |
+
dropout=0.0,
|
| 557 |
+
softmax_scale=None,
|
| 558 |
+
use_sliding_windows=False,
|
| 559 |
+
):
|
| 560 |
+
"""
|
| 561 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
| 562 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
| 563 |
+
|
| 564 |
+
Args:
|
| 565 |
+
query_states (`torch.Tensor`):
|
| 566 |
+
Input query states to be passed to Flash Attention API
|
| 567 |
+
key_states (`torch.Tensor`):
|
| 568 |
+
Input key states to be passed to Flash Attention API
|
| 569 |
+
value_states (`torch.Tensor`):
|
| 570 |
+
Input value states to be passed to Flash Attention API
|
| 571 |
+
attention_mask (`torch.Tensor`):
|
| 572 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
| 573 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
| 574 |
+
dropout (`float`):
|
| 575 |
+
Attention dropout
|
| 576 |
+
softmax_scale (`float`, *optional*):
|
| 577 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
| 578 |
+
use_sliding_windows (`bool`, *optional*):
|
| 579 |
+
Whether to activate sliding window attention.
|
| 580 |
+
"""
|
| 581 |
+
if not self._flash_attn_uses_top_left_mask:
|
| 582 |
+
causal = self.is_causal
|
| 583 |
+
else:
|
| 584 |
+
# 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__.
|
| 585 |
+
causal = self.is_causal and query_length != 1
|
| 586 |
+
|
| 587 |
+
# Contains at least one padding token in the sequence
|
| 588 |
+
if attention_mask is not None:
|
| 589 |
+
batch_size = query_states.shape[0]
|
| 590 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
| 591 |
+
query_states, key_states, value_states, attention_mask, query_length
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
| 595 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
| 596 |
+
|
| 597 |
+
if not use_sliding_windows:
|
| 598 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 599 |
+
query_states,
|
| 600 |
+
key_states,
|
| 601 |
+
value_states,
|
| 602 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 603 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 604 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 605 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 606 |
+
dropout_p=dropout,
|
| 607 |
+
softmax_scale=softmax_scale,
|
| 608 |
+
causal=causal,
|
| 609 |
+
)
|
| 610 |
+
else:
|
| 611 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 612 |
+
query_states,
|
| 613 |
+
key_states,
|
| 614 |
+
value_states,
|
| 615 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 616 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 617 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 618 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 619 |
+
dropout_p=dropout,
|
| 620 |
+
softmax_scale=softmax_scale,
|
| 621 |
+
causal=causal,
|
| 622 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 623 |
+
)
|
| 624 |
+
|
| 625 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
| 626 |
+
else:
|
| 627 |
+
if not use_sliding_windows:
|
| 628 |
+
attn_output = flash_attn_func(
|
| 629 |
+
query_states,
|
| 630 |
+
key_states,
|
| 631 |
+
value_states,
|
| 632 |
+
dropout,
|
| 633 |
+
softmax_scale=softmax_scale,
|
| 634 |
+
causal=causal,
|
| 635 |
+
)
|
| 636 |
+
else:
|
| 637 |
+
attn_output = flash_attn_func(
|
| 638 |
+
query_states,
|
| 639 |
+
key_states,
|
| 640 |
+
value_states,
|
| 641 |
+
dropout,
|
| 642 |
+
softmax_scale=softmax_scale,
|
| 643 |
+
causal=causal,
|
| 644 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
return attn_output
|
| 648 |
+
|
| 649 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
|
| 650 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
| 651 |
+
batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
|
| 652 |
+
|
| 653 |
+
# On the first iteration we need to properly re-create the padding mask
|
| 654 |
+
# by slicing it on the proper place
|
| 655 |
+
if kv_seq_len != attention_mask.shape[-1]:
|
| 656 |
+
attention_mask_num_tokens = attention_mask.shape[-1]
|
| 657 |
+
attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
|
| 658 |
+
|
| 659 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
| 660 |
+
|
| 661 |
+
key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 662 |
+
value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 663 |
+
|
| 664 |
+
if query_length == kv_seq_len:
|
| 665 |
+
query_layer = index_first_axis(
|
| 666 |
+
query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
|
| 667 |
+
)
|
| 668 |
+
cu_seqlens_q = cu_seqlens_k
|
| 669 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
| 670 |
+
indices_q = indices_k
|
| 671 |
+
elif query_length == 1:
|
| 672 |
+
max_seqlen_in_batch_q = 1
|
| 673 |
+
cu_seqlens_q = torch.arange(
|
| 674 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
| 675 |
+
) # There is a memcpy here, that is very bad.
|
| 676 |
+
indices_q = cu_seqlens_q[:-1]
|
| 677 |
+
query_layer = query_layer.squeeze(1)
|
| 678 |
+
else:
|
| 679 |
+
# The -q_len: slice assumes left padding.
|
| 680 |
+
attention_mask = attention_mask[:, -query_length:]
|
| 681 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
| 682 |
+
|
| 683 |
+
return (
|
| 684 |
+
query_layer,
|
| 685 |
+
key_layer,
|
| 686 |
+
value_layer,
|
| 687 |
+
indices_q,
|
| 688 |
+
(cu_seqlens_q, cu_seqlens_k),
|
| 689 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
| 690 |
+
)
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
# copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Phi3
|
| 694 |
+
# TODO @Arthur no longer copied from LLama after static cache
|
| 695 |
+
class Phi3SdpaAttention(Phi3Attention):
|
| 696 |
+
"""
|
| 697 |
+
Phi3 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
| 698 |
+
`Phi3Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
| 699 |
+
SDPA API.
|
| 700 |
+
"""
|
| 701 |
+
|
| 702 |
+
# Adapted from Phi3Attention.forward
|
| 703 |
+
def forward(
|
| 704 |
+
self,
|
| 705 |
+
hidden_states: torch.Tensor,
|
| 706 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 707 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 708 |
+
past_key_value: Optional[Cache] = None,
|
| 709 |
+
output_attentions: bool = False,
|
| 710 |
+
use_cache: bool = False,
|
| 711 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 712 |
+
if output_attentions:
|
| 713 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
| 714 |
+
logger.warning_once(
|
| 715 |
+
"Phi3Model is using Phi3SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
| 716 |
+
'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.'
|
| 717 |
+
)
|
| 718 |
+
return super().forward(
|
| 719 |
+
hidden_states=hidden_states,
|
| 720 |
+
attention_mask=attention_mask,
|
| 721 |
+
position_ids=position_ids,
|
| 722 |
+
past_key_value=past_key_value,
|
| 723 |
+
output_attentions=output_attentions,
|
| 724 |
+
use_cache=use_cache,
|
| 725 |
+
)
|
| 726 |
+
|
| 727 |
+
bsz, q_len, _ = hidden_states.size()
|
| 728 |
+
|
| 729 |
+
qkv = self.qkv_proj(hidden_states)
|
| 730 |
+
query_pos = self.num_heads * self.head_dim
|
| 731 |
+
query_states = qkv[..., :query_pos]
|
| 732 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 733 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 734 |
+
|
| 735 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 736 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 737 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 738 |
+
|
| 739 |
+
kv_seq_len = key_states.shape[-2]
|
| 740 |
+
if past_key_value is not None:
|
| 741 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 742 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 743 |
+
|
| 744 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 745 |
+
|
| 746 |
+
if past_key_value is not None:
|
| 747 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 748 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 749 |
+
|
| 750 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 751 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 752 |
+
|
| 753 |
+
if attention_mask is not None:
|
| 754 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 755 |
+
raise ValueError(
|
| 756 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 757 |
+
)
|
| 758 |
+
|
| 759 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
| 760 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
| 761 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
| 762 |
+
query_states = query_states.contiguous()
|
| 763 |
+
key_states = key_states.contiguous()
|
| 764 |
+
value_states = value_states.contiguous()
|
| 765 |
+
|
| 766 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
| 767 |
+
query_states,
|
| 768 |
+
key_states,
|
| 769 |
+
value_states,
|
| 770 |
+
attn_mask=attention_mask,
|
| 771 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
| 772 |
+
# 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.
|
| 773 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
| 774 |
+
)
|
| 775 |
+
|
| 776 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 777 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
| 778 |
+
|
| 779 |
+
attn_output = self.o_proj(attn_output)
|
| 780 |
+
|
| 781 |
+
return attn_output, None, past_key_value
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
PHI3_ATTENTION_CLASSES = {
|
| 785 |
+
"eager": Phi3Attention,
|
| 786 |
+
"flash_attention_2": Phi3FlashAttention2,
|
| 787 |
+
"sdpa": Phi3SdpaAttention,
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
class Phi3DecoderLayer(nn.Module):
|
| 792 |
+
def __init__(self, config: Phi3Config, layer_idx: int):
|
| 793 |
+
super().__init__()
|
| 794 |
+
|
| 795 |
+
self.config = config
|
| 796 |
+
self.self_attn = PHI3_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
|
| 797 |
+
|
| 798 |
+
self.mlp = Phi3MLP(config)
|
| 799 |
+
self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 800 |
+
|
| 801 |
+
self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
|
| 802 |
+
self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
|
| 803 |
+
self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 804 |
+
|
| 805 |
+
def forward(
|
| 806 |
+
self,
|
| 807 |
+
hidden_states: torch.Tensor,
|
| 808 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 809 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 810 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
| 811 |
+
output_attentions: Optional[bool] = False,
|
| 812 |
+
use_cache: Optional[bool] = False,
|
| 813 |
+
**kwargs,
|
| 814 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 815 |
+
if "padding_mask" in kwargs:
|
| 816 |
+
warnings.warn(
|
| 817 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 818 |
+
)
|
| 819 |
+
"""
|
| 820 |
+
Args:
|
| 821 |
+
hidden_states (`torch.FloatTensor`):
|
| 822 |
+
input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 823 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 824 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 825 |
+
position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
|
| 826 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
|
| 827 |
+
`[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
| 828 |
+
output_attentions (`bool`, *optional*):
|
| 829 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 830 |
+
returned tensors for more detail.
|
| 831 |
+
use_cache (`bool`, *optional*):
|
| 832 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 833 |
+
(see `past_key_values`).
|
| 834 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
| 835 |
+
"""
|
| 836 |
+
|
| 837 |
+
residual = hidden_states
|
| 838 |
+
|
| 839 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 840 |
+
|
| 841 |
+
# Self Attention
|
| 842 |
+
attn_outputs, self_attn_weights, present_key_value = self.self_attn(
|
| 843 |
+
hidden_states=hidden_states,
|
| 844 |
+
attention_mask=attention_mask,
|
| 845 |
+
position_ids=position_ids,
|
| 846 |
+
past_key_value=past_key_value,
|
| 847 |
+
output_attentions=output_attentions,
|
| 848 |
+
use_cache=use_cache,
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
hidden_states = residual + self.resid_attn_dropout(attn_outputs)
|
| 852 |
+
|
| 853 |
+
residual = hidden_states
|
| 854 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 855 |
+
hidden_states = self.mlp(hidden_states)
|
| 856 |
+
hidden_states = residual + self.resid_mlp_dropout(hidden_states)
|
| 857 |
+
|
| 858 |
+
outputs = (hidden_states,)
|
| 859 |
+
|
| 860 |
+
if output_attentions:
|
| 861 |
+
outputs += (self_attn_weights,)
|
| 862 |
+
|
| 863 |
+
if use_cache:
|
| 864 |
+
outputs += (present_key_value,)
|
| 865 |
+
|
| 866 |
+
return outputs
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
PHI3_START_DOCSTRING = r"""
|
| 870 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 871 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 872 |
+
etc.)
|
| 873 |
+
|
| 874 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 875 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 876 |
+
and behavior.
|
| 877 |
+
|
| 878 |
+
Parameters:
|
| 879 |
+
config ([`Phi3Config`]):
|
| 880 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 881 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 882 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 883 |
+
"""
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
@add_start_docstrings(
|
| 887 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 888 |
+
PHI3_START_DOCSTRING,
|
| 889 |
+
)
|
| 890 |
+
class Phi3PreTrainedModel(PreTrainedModel):
|
| 891 |
+
config_class = Phi3Config
|
| 892 |
+
base_model_prefix = "model"
|
| 893 |
+
supports_gradient_checkpointing = True
|
| 894 |
+
_no_split_modules = ["Phi3DecoderLayer"]
|
| 895 |
+
_skip_keys_device_placement = "past_key_values"
|
| 896 |
+
_supports_flash_attn_2 = True
|
| 897 |
+
_supports_sdpa = False
|
| 898 |
+
_supports_cache_class = True
|
| 899 |
+
|
| 900 |
+
_version = "0.0.5"
|
| 901 |
+
|
| 902 |
+
def _init_weights(self, module):
|
| 903 |
+
std = self.config.initializer_range
|
| 904 |
+
if isinstance(module, nn.Linear):
|
| 905 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 906 |
+
if module.bias is not None:
|
| 907 |
+
module.bias.data.zero_()
|
| 908 |
+
elif isinstance(module, nn.Embedding):
|
| 909 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 910 |
+
if module.padding_idx is not None:
|
| 911 |
+
module.weight.data[module.padding_idx].zero_()
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
PHI3_INPUTS_DOCSTRING = r"""
|
| 915 |
+
Args:
|
| 916 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 917 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 918 |
+
it.
|
| 919 |
+
|
| 920 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 921 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 922 |
+
|
| 923 |
+
[What are input IDs?](../glossary#input-ids)
|
| 924 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 925 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 926 |
+
|
| 927 |
+
- 1 for tokens that are **not masked**,
|
| 928 |
+
- 0 for tokens that are **masked**.
|
| 929 |
+
|
| 930 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 931 |
+
|
| 932 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 933 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 934 |
+
|
| 935 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
| 936 |
+
`past_key_values`).
|
| 937 |
+
|
| 938 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 939 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 940 |
+
information on the default strategy.
|
| 941 |
+
|
| 942 |
+
- 1 indicates the head is **not masked**,
|
| 943 |
+
- 0 indicates the head is **masked**.
|
| 944 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 945 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 946 |
+
config.n_positions - 1]`.
|
| 947 |
+
|
| 948 |
+
[What are position IDs?](../glossary#position-ids)
|
| 949 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 950 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 951 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 952 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 953 |
+
|
| 954 |
+
Two formats are allowed:
|
| 955 |
+
- a [`~cache_utils.Cache`] instance;
|
| 956 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 957 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 958 |
+
cache format.
|
| 959 |
+
|
| 960 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 961 |
+
legacy cache format will be returned.
|
| 962 |
+
|
| 963 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 964 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 965 |
+
of shape `(batch_size, sequence_length)`.
|
| 966 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 967 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 968 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 969 |
+
model's internal embedding lookup matrix.
|
| 970 |
+
use_cache (`bool`, *optional*):
|
| 971 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 972 |
+
`past_key_values`).
|
| 973 |
+
output_attentions (`bool`, *optional*):
|
| 974 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 975 |
+
tensors for more detail.
|
| 976 |
+
output_hidden_states (`bool`, *optional*):
|
| 977 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 978 |
+
more detail.
|
| 979 |
+
return_dict (`bool`, *optional*):
|
| 980 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 981 |
+
"""
|
| 982 |
+
|
| 983 |
+
|
| 984 |
+
@add_start_docstrings(
|
| 985 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 986 |
+
PHI3_START_DOCSTRING,
|
| 987 |
+
)
|
| 988 |
+
class Phi3Model(Phi3PreTrainedModel):
|
| 989 |
+
"""
|
| 990 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Phi3DecoderLayer`]
|
| 991 |
+
|
| 992 |
+
Args:
|
| 993 |
+
config: Phi3Config
|
| 994 |
+
"""
|
| 995 |
+
|
| 996 |
+
def __init__(self, config: Phi3Config):
|
| 997 |
+
super().__init__(config)
|
| 998 |
+
self.padding_idx = config.pad_token_id
|
| 999 |
+
self.vocab_size = config.vocab_size
|
| 1000 |
+
|
| 1001 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 1002 |
+
self.embed_dropout = nn.Dropout(config.embd_pdrop)
|
| 1003 |
+
self.layers = nn.ModuleList(
|
| 1004 |
+
[Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 1005 |
+
)
|
| 1006 |
+
self._attn_implementation = config._attn_implementation
|
| 1007 |
+
self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 1008 |
+
|
| 1009 |
+
self.gradient_checkpointing = False
|
| 1010 |
+
# Initialize weights and apply final processing
|
| 1011 |
+
self.post_init()
|
| 1012 |
+
|
| 1013 |
+
def get_input_embeddings(self):
|
| 1014 |
+
return self.embed_tokens
|
| 1015 |
+
|
| 1016 |
+
def set_input_embeddings(self, value):
|
| 1017 |
+
self.embed_tokens = value
|
| 1018 |
+
|
| 1019 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1020 |
+
def forward(
|
| 1021 |
+
self,
|
| 1022 |
+
input_ids: torch.LongTensor = None,
|
| 1023 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1024 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1025 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1026 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1027 |
+
use_cache: Optional[bool] = None,
|
| 1028 |
+
output_attentions: Optional[bool] = None,
|
| 1029 |
+
output_hidden_states: Optional[bool] = None,
|
| 1030 |
+
return_dict: Optional[bool] = None,
|
| 1031 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 1032 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1033 |
+
output_hidden_states = (
|
| 1034 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1035 |
+
)
|
| 1036 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1037 |
+
|
| 1038 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1039 |
+
|
| 1040 |
+
# retrieve input_ids and inputs_embeds
|
| 1041 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 1042 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
| 1043 |
+
elif input_ids is not None:
|
| 1044 |
+
batch_size, seq_length = input_ids.shape[:2]
|
| 1045 |
+
elif inputs_embeds is not None:
|
| 1046 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
| 1047 |
+
else:
|
| 1048 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
| 1049 |
+
|
| 1050 |
+
past_key_values_length = 0
|
| 1051 |
+
|
| 1052 |
+
if self.gradient_checkpointing and self.training:
|
| 1053 |
+
if use_cache:
|
| 1054 |
+
logger.warning_once(
|
| 1055 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
| 1056 |
+
)
|
| 1057 |
+
use_cache = False
|
| 1058 |
+
|
| 1059 |
+
if use_cache:
|
| 1060 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
| 1061 |
+
if use_legacy_cache:
|
| 1062 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
| 1063 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
| 1064 |
+
|
| 1065 |
+
if position_ids is None:
|
| 1066 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
| 1067 |
+
position_ids = torch.arange(
|
| 1068 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
| 1069 |
+
)
|
| 1070 |
+
position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
|
| 1071 |
+
else:
|
| 1072 |
+
position_ids = position_ids.view(-1, seq_length).long()
|
| 1073 |
+
|
| 1074 |
+
if inputs_embeds is None:
|
| 1075 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 1076 |
+
|
| 1077 |
+
if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
|
| 1078 |
+
is_padding_right = attention_mask[:, -1].sum().item() != batch_size
|
| 1079 |
+
if is_padding_right:
|
| 1080 |
+
raise ValueError(
|
| 1081 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 1082 |
+
" this may lead to unexpected behaviour for Flash Attention version of Phi3. Make sure to "
|
| 1083 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 1084 |
+
)
|
| 1085 |
+
|
| 1086 |
+
if self._attn_implementation == "flash_attention_2":
|
| 1087 |
+
# 2d mask is passed through the layers
|
| 1088 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
| 1089 |
+
else:
|
| 1090 |
+
# 4d mask is passed through the layers
|
| 1091 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
| 1092 |
+
attention_mask,
|
| 1093 |
+
(batch_size, seq_length),
|
| 1094 |
+
inputs_embeds,
|
| 1095 |
+
past_key_values_length,
|
| 1096 |
+
sliding_window=self.config.sliding_window,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
hidden_states = inputs_embeds
|
| 1100 |
+
|
| 1101 |
+
# decoder layers
|
| 1102 |
+
all_hidden_states = () if output_hidden_states else None
|
| 1103 |
+
all_self_attns = () if output_attentions else None
|
| 1104 |
+
next_decoder_cache = None
|
| 1105 |
+
|
| 1106 |
+
for decoder_layer in self.layers:
|
| 1107 |
+
if output_hidden_states:
|
| 1108 |
+
all_hidden_states += (hidden_states,)
|
| 1109 |
+
|
| 1110 |
+
if self.gradient_checkpointing and self.training:
|
| 1111 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 1112 |
+
decoder_layer.__call__,
|
| 1113 |
+
hidden_states,
|
| 1114 |
+
attention_mask,
|
| 1115 |
+
position_ids,
|
| 1116 |
+
past_key_values,
|
| 1117 |
+
output_attentions,
|
| 1118 |
+
use_cache,
|
| 1119 |
+
)
|
| 1120 |
+
else:
|
| 1121 |
+
layer_outputs = decoder_layer(
|
| 1122 |
+
hidden_states,
|
| 1123 |
+
attention_mask=attention_mask,
|
| 1124 |
+
position_ids=position_ids,
|
| 1125 |
+
past_key_value=past_key_values,
|
| 1126 |
+
output_attentions=output_attentions,
|
| 1127 |
+
use_cache=use_cache,
|
| 1128 |
+
)
|
| 1129 |
+
|
| 1130 |
+
hidden_states = layer_outputs[0]
|
| 1131 |
+
|
| 1132 |
+
if use_cache:
|
| 1133 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
| 1134 |
+
|
| 1135 |
+
if output_attentions:
|
| 1136 |
+
all_self_attns += (layer_outputs[1],)
|
| 1137 |
+
|
| 1138 |
+
hidden_states = self.norm(hidden_states)
|
| 1139 |
+
|
| 1140 |
+
# add hidden states from the last decoder layer
|
| 1141 |
+
if output_hidden_states:
|
| 1142 |
+
all_hidden_states += (hidden_states,)
|
| 1143 |
+
|
| 1144 |
+
next_cache = None
|
| 1145 |
+
if use_cache:
|
| 1146 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
| 1147 |
+
if not return_dict:
|
| 1148 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
| 1149 |
+
return BaseModelOutputWithPast(
|
| 1150 |
+
last_hidden_state=hidden_states,
|
| 1151 |
+
past_key_values=next_cache,
|
| 1152 |
+
hidden_states=all_hidden_states,
|
| 1153 |
+
attentions=all_self_attns,
|
| 1154 |
+
)
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
class Phi3ForCausalLM(Phi3PreTrainedModel):
|
| 1158 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 1159 |
+
|
| 1160 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi3
|
| 1161 |
+
def __init__(self, config):
|
| 1162 |
+
super().__init__(config)
|
| 1163 |
+
self.model = Phi3Model(config)
|
| 1164 |
+
self.vocab_size = config.vocab_size
|
| 1165 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1166 |
+
|
| 1167 |
+
# Initialize weights and apply final processing
|
| 1168 |
+
self.post_init()
|
| 1169 |
+
|
| 1170 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
|
| 1171 |
+
def get_input_embeddings(self):
|
| 1172 |
+
return self.model.embed_tokens
|
| 1173 |
+
|
| 1174 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
|
| 1175 |
+
def set_input_embeddings(self, value):
|
| 1176 |
+
self.model.embed_tokens = value
|
| 1177 |
+
|
| 1178 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
|
| 1179 |
+
def get_output_embeddings(self):
|
| 1180 |
+
return self.lm_head
|
| 1181 |
+
|
| 1182 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
|
| 1183 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1184 |
+
self.lm_head = new_embeddings
|
| 1185 |
+
|
| 1186 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
|
| 1187 |
+
def set_decoder(self, decoder):
|
| 1188 |
+
self.model = decoder
|
| 1189 |
+
|
| 1190 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
|
| 1191 |
+
def get_decoder(self):
|
| 1192 |
+
return self.model
|
| 1193 |
+
|
| 1194 |
+
# Ignore copy
|
| 1195 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1196 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
| 1197 |
+
def forward(
|
| 1198 |
+
self,
|
| 1199 |
+
input_ids: torch.LongTensor = None,
|
| 1200 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1201 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1202 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1203 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1204 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1205 |
+
use_cache: Optional[bool] = None,
|
| 1206 |
+
output_attentions: Optional[bool] = None,
|
| 1207 |
+
output_hidden_states: Optional[bool] = None,
|
| 1208 |
+
return_dict: Optional[bool] = None,
|
| 1209 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1210 |
+
r"""
|
| 1211 |
+
Args:
|
| 1212 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1213 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1214 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1215 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1216 |
+
|
| 1217 |
+
Returns:
|
| 1218 |
+
|
| 1219 |
+
Example:
|
| 1220 |
+
|
| 1221 |
+
```python
|
| 1222 |
+
>>> from transformers import AutoTokenizer, Phi3ForCausalLM
|
| 1223 |
+
|
| 1224 |
+
>>> model = Phi3ForCausalLM.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1225 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1226 |
+
|
| 1227 |
+
>>> prompt = "This is an example script ."
|
| 1228 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1229 |
+
|
| 1230 |
+
>>> # Generate
|
| 1231 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1232 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1233 |
+
'This is an example script .\n Certainly! Below is a sample script that demonstrates a simple task, such as calculating the sum'
|
| 1234 |
+
```"""
|
| 1235 |
+
|
| 1236 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1237 |
+
output_hidden_states = (
|
| 1238 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1239 |
+
)
|
| 1240 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1241 |
+
|
| 1242 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1243 |
+
outputs = self.model(
|
| 1244 |
+
input_ids=input_ids,
|
| 1245 |
+
attention_mask=attention_mask,
|
| 1246 |
+
position_ids=position_ids,
|
| 1247 |
+
past_key_values=past_key_values,
|
| 1248 |
+
inputs_embeds=inputs_embeds,
|
| 1249 |
+
use_cache=use_cache,
|
| 1250 |
+
output_attentions=output_attentions,
|
| 1251 |
+
output_hidden_states=output_hidden_states,
|
| 1252 |
+
return_dict=return_dict,
|
| 1253 |
+
)
|
| 1254 |
+
|
| 1255 |
+
hidden_states = outputs[0]
|
| 1256 |
+
logits = self.lm_head(hidden_states)
|
| 1257 |
+
logits = logits.float()
|
| 1258 |
+
|
| 1259 |
+
loss = None
|
| 1260 |
+
if labels is not None:
|
| 1261 |
+
# Shift so that tokens < n predict n
|
| 1262 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 1263 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 1264 |
+
# Flatten the tokens
|
| 1265 |
+
loss_fct = CrossEntropyLoss()
|
| 1266 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
| 1267 |
+
shift_labels = shift_labels.view(-1)
|
| 1268 |
+
# Enable model parallelism
|
| 1269 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 1270 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 1271 |
+
|
| 1272 |
+
if not return_dict:
|
| 1273 |
+
output = (logits,) + outputs[1:]
|
| 1274 |
+
return (loss,) + output if loss is not None else output
|
| 1275 |
+
|
| 1276 |
+
return CausalLMOutputWithPast(
|
| 1277 |
+
loss=loss,
|
| 1278 |
+
logits=logits,
|
| 1279 |
+
past_key_values=outputs.past_key_values,
|
| 1280 |
+
hidden_states=outputs.hidden_states,
|
| 1281 |
+
attentions=outputs.attentions,
|
| 1282 |
+
)
|
| 1283 |
+
|
| 1284 |
+
# Copied from transformers.models.persimmon.modeling_persimmon.PersimmonForCausalLM.prepare_inputs_for_generation
|
| 1285 |
+
def prepare_inputs_for_generation(
|
| 1286 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
|
| 1287 |
+
):
|
| 1288 |
+
if past_key_values is not None:
|
| 1289 |
+
if isinstance(past_key_values, Cache):
|
| 1290 |
+
cache_length = past_key_values.get_seq_length()
|
| 1291 |
+
past_length = past_key_values.seen_tokens
|
| 1292 |
+
max_cache_length = past_key_values.get_max_length()
|
| 1293 |
+
else:
|
| 1294 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
| 1295 |
+
max_cache_length = None
|
| 1296 |
+
|
| 1297 |
+
# Keep only the unprocessed tokens:
|
| 1298 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
| 1299 |
+
# some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
|
| 1300 |
+
# input)
|
| 1301 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
| 1302 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
| 1303 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
| 1304 |
+
# input_ids based on the past_length.
|
| 1305 |
+
elif past_length < input_ids.shape[1]:
|
| 1306 |
+
input_ids = input_ids[:, past_length:]
|
| 1307 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
| 1308 |
+
|
| 1309 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
| 1310 |
+
if (
|
| 1311 |
+
max_cache_length is not None
|
| 1312 |
+
and attention_mask is not None
|
| 1313 |
+
and cache_length + input_ids.shape[1] > max_cache_length
|
| 1314 |
+
):
|
| 1315 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
| 1316 |
+
|
| 1317 |
+
position_ids = kwargs.get("position_ids", None)
|
| 1318 |
+
if attention_mask is not None and position_ids is None:
|
| 1319 |
+
# create position_ids on the fly for batch generation
|
| 1320 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 1321 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 1322 |
+
if past_key_values:
|
| 1323 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
| 1324 |
+
|
| 1325 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
| 1326 |
+
if inputs_embeds is not None and past_key_values is None:
|
| 1327 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
| 1328 |
+
else:
|
| 1329 |
+
model_inputs = {"input_ids": input_ids}
|
| 1330 |
+
|
| 1331 |
+
model_inputs.update(
|
| 1332 |
+
{
|
| 1333 |
+
"position_ids": position_ids,
|
| 1334 |
+
"past_key_values": past_key_values,
|
| 1335 |
+
"use_cache": kwargs.get("use_cache"),
|
| 1336 |
+
"attention_mask": attention_mask,
|
| 1337 |
+
}
|
| 1338 |
+
)
|
| 1339 |
+
return model_inputs
|
| 1340 |
+
|
| 1341 |
+
@staticmethod
|
| 1342 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
|
| 1343 |
+
def _reorder_cache(past_key_values, beam_idx):
|
| 1344 |
+
reordered_past = ()
|
| 1345 |
+
for layer_past in past_key_values:
|
| 1346 |
+
reordered_past += (
|
| 1347 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
| 1348 |
+
)
|
| 1349 |
+
return reordered_past
|
| 1350 |
+
|
| 1351 |
+
|
| 1352 |
+
@add_start_docstrings(
|
| 1353 |
+
"""
|
| 1354 |
+
The [`Phi3Model`] with a sequence classification head on top (linear layer).
|
| 1355 |
+
|
| 1356 |
+
[`Phi3ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
| 1357 |
+
(e.g. GPT-2) do.
|
| 1358 |
+
|
| 1359 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
| 1360 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
| 1361 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
| 1362 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
| 1363 |
+
each row of the batch).
|
| 1364 |
+
""",
|
| 1365 |
+
PHI3_START_DOCSTRING,
|
| 1366 |
+
)
|
| 1367 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->Phi3, LLAMA->PHI3, self.transformer->self.model, transformer_outputs->model_outputs
|
| 1368 |
+
class Phi3ForSequenceClassification(Phi3PreTrainedModel):
|
| 1369 |
+
def __init__(self, config):
|
| 1370 |
+
super().__init__(config)
|
| 1371 |
+
self.num_labels = config.num_labels
|
| 1372 |
+
self.model = Phi3Model(config)
|
| 1373 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
| 1374 |
+
|
| 1375 |
+
# Initialize weights and apply final processing
|
| 1376 |
+
self.post_init()
|
| 1377 |
+
|
| 1378 |
+
def get_input_embeddings(self):
|
| 1379 |
+
return self.model.embed_tokens
|
| 1380 |
+
|
| 1381 |
+
def set_input_embeddings(self, value):
|
| 1382 |
+
self.model.embed_tokens = value
|
| 1383 |
+
|
| 1384 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1385 |
+
def forward(
|
| 1386 |
+
self,
|
| 1387 |
+
input_ids: torch.LongTensor = None,
|
| 1388 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1389 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1390 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1391 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1392 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1393 |
+
use_cache: Optional[bool] = None,
|
| 1394 |
+
output_attentions: Optional[bool] = None,
|
| 1395 |
+
output_hidden_states: Optional[bool] = None,
|
| 1396 |
+
return_dict: Optional[bool] = None,
|
| 1397 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
| 1398 |
+
r"""
|
| 1399 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1400 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1401 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1402 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1403 |
+
"""
|
| 1404 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1405 |
+
|
| 1406 |
+
model_outputs = self.model(
|
| 1407 |
+
input_ids,
|
| 1408 |
+
attention_mask=attention_mask,
|
| 1409 |
+
position_ids=position_ids,
|
| 1410 |
+
past_key_values=past_key_values,
|
| 1411 |
+
inputs_embeds=inputs_embeds,
|
| 1412 |
+
use_cache=use_cache,
|
| 1413 |
+
output_attentions=output_attentions,
|
| 1414 |
+
output_hidden_states=output_hidden_states,
|
| 1415 |
+
return_dict=return_dict,
|
| 1416 |
+
)
|
| 1417 |
+
hidden_states = model_outputs[0]
|
| 1418 |
+
logits = self.score(hidden_states)
|
| 1419 |
+
|
| 1420 |
+
if input_ids is not None:
|
| 1421 |
+
batch_size = input_ids.shape[0]
|
| 1422 |
+
else:
|
| 1423 |
+
batch_size = inputs_embeds.shape[0]
|
| 1424 |
+
|
| 1425 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
| 1426 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
| 1427 |
+
if self.config.pad_token_id is None:
|
| 1428 |
+
sequence_lengths = -1
|
| 1429 |
+
else:
|
| 1430 |
+
if input_ids is not None:
|
| 1431 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
| 1432 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
| 1433 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
| 1434 |
+
sequence_lengths = sequence_lengths.to(logits.device)
|
| 1435 |
+
else:
|
| 1436 |
+
sequence_lengths = -1
|
| 1437 |
+
|
| 1438 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
| 1439 |
+
|
| 1440 |
+
loss = None
|
| 1441 |
+
if labels is not None:
|
| 1442 |
+
labels = labels.to(logits.device)
|
| 1443 |
+
if self.config.problem_type is None:
|
| 1444 |
+
if self.num_labels == 1:
|
| 1445 |
+
self.config.problem_type = "regression"
|
| 1446 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 1447 |
+
self.config.problem_type = "single_label_classification"
|
| 1448 |
+
else:
|
| 1449 |
+
self.config.problem_type = "multi_label_classification"
|
| 1450 |
+
|
| 1451 |
+
if self.config.problem_type == "regression":
|
| 1452 |
+
loss_fct = MSELoss()
|
| 1453 |
+
if self.num_labels == 1:
|
| 1454 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
| 1455 |
+
else:
|
| 1456 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1457 |
+
elif self.config.problem_type == "single_label_classification":
|
| 1458 |
+
loss_fct = CrossEntropyLoss()
|
| 1459 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
| 1460 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 1461 |
+
loss_fct = BCEWithLogitsLoss()
|
| 1462 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1463 |
+
if not return_dict:
|
| 1464 |
+
output = (pooled_logits,) + model_outputs[1:]
|
| 1465 |
+
return ((loss,) + output) if loss is not None else output
|
| 1466 |
+
|
| 1467 |
+
return SequenceClassifierOutputWithPast(
|
| 1468 |
+
loss=loss,
|
| 1469 |
+
logits=pooled_logits,
|
| 1470 |
+
past_key_values=model_outputs.past_key_values,
|
| 1471 |
+
hidden_states=model_outputs.hidden_states,
|
| 1472 |
+
attentions=model_outputs.attentions,
|
| 1473 |
+
)
|
| 1474 |
+
|
| 1475 |
+
|
| 1476 |
+
@add_start_docstrings(
|
| 1477 |
+
"""
|
| 1478 |
+
[`Phi3Model`] with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
|
| 1479 |
+
Named-Entity-Recognition (NER) tasks.
|
| 1480 |
+
""",
|
| 1481 |
+
PHI3_START_DOCSTRING,
|
| 1482 |
+
)
|
| 1483 |
+
# Copied from transformers.models.mpt.modeling_mpt.MptForTokenClassification with Mpt->Phi3,MPT->PHI3,self.transformer->self.model,transformer_outputs->model_outputs
|
| 1484 |
+
class Phi3ForTokenClassification(Phi3PreTrainedModel):
|
| 1485 |
+
def __init__(self, config: Phi3Config):
|
| 1486 |
+
super().__init__(config)
|
| 1487 |
+
self.num_labels = config.num_labels
|
| 1488 |
+
|
| 1489 |
+
self.model = Phi3Model(config)
|
| 1490 |
+
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
|
| 1491 |
+
classifier_dropout = config.classifier_dropout
|
| 1492 |
+
elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
|
| 1493 |
+
classifier_dropout = config.hidden_dropout
|
| 1494 |
+
else:
|
| 1495 |
+
classifier_dropout = 0.1
|
| 1496 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
| 1497 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
| 1498 |
+
|
| 1499 |
+
# Initialize weights and apply final processing
|
| 1500 |
+
self.post_init()
|
| 1501 |
+
|
| 1502 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1503 |
+
@add_code_sample_docstrings(
|
| 1504 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 1505 |
+
output_type=TokenClassifierOutput,
|
| 1506 |
+
config_class=_CONFIG_FOR_DOC,
|
| 1507 |
+
)
|
| 1508 |
+
def forward(
|
| 1509 |
+
self,
|
| 1510 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1511 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
| 1512 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1513 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1514 |
+
labels: Optional[torch.Tensor] = None,
|
| 1515 |
+
use_cache: Optional[bool] = None,
|
| 1516 |
+
output_attentions: Optional[bool] = None,
|
| 1517 |
+
output_hidden_states: Optional[bool] = None,
|
| 1518 |
+
return_dict: Optional[bool] = None,
|
| 1519 |
+
**deprecated_arguments,
|
| 1520 |
+
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
| 1521 |
+
r"""
|
| 1522 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1523 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1524 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1525 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1526 |
+
"""
|
| 1527 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1528 |
+
|
| 1529 |
+
model_outputs = self.model(
|
| 1530 |
+
input_ids,
|
| 1531 |
+
past_key_values=past_key_values,
|
| 1532 |
+
attention_mask=attention_mask,
|
| 1533 |
+
inputs_embeds=inputs_embeds,
|
| 1534 |
+
use_cache=use_cache,
|
| 1535 |
+
output_attentions=output_attentions,
|
| 1536 |
+
output_hidden_states=output_hidden_states,
|
| 1537 |
+
return_dict=return_dict,
|
| 1538 |
+
)
|
| 1539 |
+
|
| 1540 |
+
hidden_states = model_outputs[0]
|
| 1541 |
+
hidden_states = self.dropout(hidden_states)
|
| 1542 |
+
logits = self.classifier(hidden_states)
|
| 1543 |
+
|
| 1544 |
+
loss = None
|
| 1545 |
+
if labels is not None:
|
| 1546 |
+
# move labels to correct device to enable model parallelism
|
| 1547 |
+
labels = labels.to(logits.device)
|
| 1548 |
+
batch_size, seq_length = labels.shape
|
| 1549 |
+
loss_fct = CrossEntropyLoss()
|
| 1550 |
+
loss = loss_fct(
|
| 1551 |
+
logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length)
|
| 1552 |
+
)
|
| 1553 |
+
|
| 1554 |
+
if not return_dict:
|
| 1555 |
+
output = (logits,) + model_outputs[2:]
|
| 1556 |
+
return ((loss,) + output) if loss is not None else output
|
| 1557 |
+
|
| 1558 |
+
return TokenClassifierOutput(
|
| 1559 |
+
loss=loss,
|
| 1560 |
+
logits=logits,
|
| 1561 |
+
hidden_states=model_outputs.hidden_states,
|
| 1562 |
+
attentions=model_outputs.attentions,
|
| 1563 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|endoftext|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|endoftext|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "<unk>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/tokenizer_config.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": null,
|
| 5 |
+
"added_tokens_decoder": {
|
| 6 |
+
"0": {
|
| 7 |
+
"content": "<unk>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false,
|
| 12 |
+
"special": true
|
| 13 |
+
},
|
| 14 |
+
"1": {
|
| 15 |
+
"content": "<s>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": false,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false,
|
| 20 |
+
"special": true
|
| 21 |
+
},
|
| 22 |
+
"2": {
|
| 23 |
+
"content": "</s>",
|
| 24 |
+
"lstrip": false,
|
| 25 |
+
"normalized": false,
|
| 26 |
+
"rstrip": true,
|
| 27 |
+
"single_word": false,
|
| 28 |
+
"special": false
|
| 29 |
+
},
|
| 30 |
+
"32000": {
|
| 31 |
+
"content": "<|endoftext|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false,
|
| 36 |
+
"special": true
|
| 37 |
+
},
|
| 38 |
+
"32001": {
|
| 39 |
+
"content": "<|assistant|>",
|
| 40 |
+
"lstrip": false,
|
| 41 |
+
"normalized": false,
|
| 42 |
+
"rstrip": true,
|
| 43 |
+
"single_word": false,
|
| 44 |
+
"special": true
|
| 45 |
+
},
|
| 46 |
+
"32002": {
|
| 47 |
+
"content": "<|placeholder1|>",
|
| 48 |
+
"lstrip": false,
|
| 49 |
+
"normalized": false,
|
| 50 |
+
"rstrip": true,
|
| 51 |
+
"single_word": false,
|
| 52 |
+
"special": true
|
| 53 |
+
},
|
| 54 |
+
"32003": {
|
| 55 |
+
"content": "<|placeholder2|>",
|
| 56 |
+
"lstrip": false,
|
| 57 |
+
"normalized": false,
|
| 58 |
+
"rstrip": true,
|
| 59 |
+
"single_word": false,
|
| 60 |
+
"special": true
|
| 61 |
+
},
|
| 62 |
+
"32004": {
|
| 63 |
+
"content": "<|placeholder3|>",
|
| 64 |
+
"lstrip": false,
|
| 65 |
+
"normalized": false,
|
| 66 |
+
"rstrip": true,
|
| 67 |
+
"single_word": false,
|
| 68 |
+
"special": true
|
| 69 |
+
},
|
| 70 |
+
"32005": {
|
| 71 |
+
"content": "<|placeholder4|>",
|
| 72 |
+
"lstrip": false,
|
| 73 |
+
"normalized": false,
|
| 74 |
+
"rstrip": true,
|
| 75 |
+
"single_word": false,
|
| 76 |
+
"special": true
|
| 77 |
+
},
|
| 78 |
+
"32006": {
|
| 79 |
+
"content": "<|system|>",
|
| 80 |
+
"lstrip": false,
|
| 81 |
+
"normalized": false,
|
| 82 |
+
"rstrip": true,
|
| 83 |
+
"single_word": false,
|
| 84 |
+
"special": true
|
| 85 |
+
},
|
| 86 |
+
"32007": {
|
| 87 |
+
"content": "<|end|>",
|
| 88 |
+
"lstrip": false,
|
| 89 |
+
"normalized": false,
|
| 90 |
+
"rstrip": true,
|
| 91 |
+
"single_word": false,
|
| 92 |
+
"special": true
|
| 93 |
+
},
|
| 94 |
+
"32008": {
|
| 95 |
+
"content": "<|placeholder5|>",
|
| 96 |
+
"lstrip": false,
|
| 97 |
+
"normalized": false,
|
| 98 |
+
"rstrip": true,
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"special": true
|
| 101 |
+
},
|
| 102 |
+
"32009": {
|
| 103 |
+
"content": "<|placeholder6|>",
|
| 104 |
+
"lstrip": false,
|
| 105 |
+
"normalized": false,
|
| 106 |
+
"rstrip": true,
|
| 107 |
+
"single_word": false,
|
| 108 |
+
"special": true
|
| 109 |
+
},
|
| 110 |
+
"32010": {
|
| 111 |
+
"content": "<|user|>",
|
| 112 |
+
"lstrip": false,
|
| 113 |
+
"normalized": false,
|
| 114 |
+
"rstrip": true,
|
| 115 |
+
"single_word": false,
|
| 116 |
+
"special": true
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
"bos_token": "<s>",
|
| 120 |
+
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
|
| 121 |
+
"clean_up_tokenization_spaces": false,
|
| 122 |
+
"eos_token": "<|endoftext|>",
|
| 123 |
+
"legacy": false,
|
| 124 |
+
"model_max_length": 4096,
|
| 125 |
+
"pad_token": "<|endoftext|>",
|
| 126 |
+
"padding_side": "left",
|
| 127 |
+
"sp_model_kwargs": {},
|
| 128 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 129 |
+
"unk_token": "<unk>",
|
| 130 |
+
"use_default_system_prompt": false
|
| 131 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/train_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9969120977149523,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 1546.3839571108376,
|
| 5 |
+
"train_runtime": 17027.6856,
|
| 6 |
+
"train_samples": 29145,
|
| 7 |
+
"train_samples_per_second": 1.712,
|
| 8 |
+
"train_steps_per_second": 0.013
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/trainer_state.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk1_epoch3/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b5e649c97adc4e013ab5eb212637cd33755652a973870ba8f262c8571d489ad
|
| 3 |
+
size 7352
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
base_model: /home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct
|
| 4 |
+
tags:
|
| 5 |
+
- alignment-handbook
|
| 6 |
+
- generated_from_trainer
|
| 7 |
+
datasets:
|
| 8 |
+
- /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math
|
| 9 |
+
model-index:
|
| 10 |
+
- name: '2'
|
| 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 |
+
# 2
|
| 18 |
+
|
| 19 |
+
This model is a fine-tuned version of [/home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct](https://huggingface.co//home/v-liuzichuan/huggingface/Phi-3-mini-4k-instruct) on the /home/v-liuzichuan/huggingface/princeton-nlp/llama3-math dataset.
|
| 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: 5e-07
|
| 39 |
+
- train_batch_size: 2
|
| 40 |
+
- eval_batch_size: 4
|
| 41 |
+
- seed: 42
|
| 42 |
+
- distributed_type: multi-GPU
|
| 43 |
+
- gradient_accumulation_steps: 64
|
| 44 |
+
- total_train_batch_size: 128
|
| 45 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
| 46 |
+
- lr_scheduler_type: cosine
|
| 47 |
+
- lr_scheduler_warmup_ratio: 0.1
|
| 48 |
+
- num_epochs: 1
|
| 49 |
+
|
| 50 |
+
### Training results
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
### Framework versions
|
| 55 |
+
|
| 56 |
+
- Transformers 4.45.2
|
| 57 |
+
- Pytorch 2.5.1+cu121
|
| 58 |
+
- Datasets 3.5.0
|
| 59 |
+
- Tokenizers 0.20.3
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/added_tokens.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<|assistant|>": 32001,
|
| 3 |
+
"<|endoftext|>": 32000,
|
| 4 |
+
"<|end|>": 32007,
|
| 5 |
+
"<|placeholder1|>": 32002,
|
| 6 |
+
"<|placeholder2|>": 32003,
|
| 7 |
+
"<|placeholder3|>": 32004,
|
| 8 |
+
"<|placeholder4|>": 32005,
|
| 9 |
+
"<|placeholder5|>": 32008,
|
| 10 |
+
"<|placeholder6|>": 32009,
|
| 11 |
+
"<|system|>": 32006,
|
| 12 |
+
"<|user|>": 32010
|
| 13 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/all_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9880609304240429,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 1230.5828483072917,
|
| 5 |
+
"train_runtime": 5273.3776,
|
| 6 |
+
"train_samples": 9715,
|
| 7 |
+
"train_samples_per_second": 1.842,
|
| 8 |
+
"train_steps_per_second": 0.014
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/home/v-liuzichuan/dpo/outputs_ipo_phi//temp_path",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Phi3ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"attention_bias": false,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "configuration_phi3.Phi3Config",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 1,
|
| 13 |
+
"embd_pdrop": 0.0,
|
| 14 |
+
"eos_token_id": 32000,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 3072,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 8192,
|
| 19 |
+
"max_position_embeddings": 4096,
|
| 20 |
+
"model_type": "phi3",
|
| 21 |
+
"num_attention_heads": 32,
|
| 22 |
+
"num_hidden_layers": 32,
|
| 23 |
+
"num_key_value_heads": 32,
|
| 24 |
+
"original_max_position_embeddings": 4096,
|
| 25 |
+
"pad_token_id": 32000,
|
| 26 |
+
"resid_pdrop": 0.0,
|
| 27 |
+
"rms_norm_eps": 1e-05,
|
| 28 |
+
"rope_scaling": null,
|
| 29 |
+
"rope_theta": 10000.0,
|
| 30 |
+
"sliding_window": 2047,
|
| 31 |
+
"tie_word_embeddings": false,
|
| 32 |
+
"torch_dtype": "bfloat16",
|
| 33 |
+
"transformers_version": "4.45.2",
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32064
|
| 36 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/configu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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" Phi-3 model configuration"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 20 |
+
from transformers.utils import logging
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
logger = logging.get_logger(__name__)
|
| 24 |
+
|
| 25 |
+
PHI3_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
| 26 |
+
"microsoft/Phi-3-mini-4k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/resolve/main/config.json",
|
| 27 |
+
"microsoft/Phi-3-mini-128k-instruct": "https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/resolve/main/config.json",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Phi3Config(PretrainedConfig):
|
| 32 |
+
r"""
|
| 33 |
+
This is the configuration class to store the configuration of a [`Phi3Model`]. It is used to instantiate a Phi-3
|
| 34 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 35 |
+
defaults will yield a similar configuration to that of the
|
| 36 |
+
[microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
|
| 37 |
+
|
| 38 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 39 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
vocab_size (`int`, *optional*, defaults to 32064):
|
| 43 |
+
Vocabulary size of the Phi-3 model. Defines the number of different tokens that can be represented by the
|
| 44 |
+
`inputs_ids` passed when calling [`Phi3Model`].
|
| 45 |
+
hidden_size (`int`, *optional*, defaults to 3072):
|
| 46 |
+
Dimension of the hidden representations.
|
| 47 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
| 48 |
+
Dimension of the MLP representations.
|
| 49 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 50 |
+
Number of hidden layers in the Transformer decoder.
|
| 51 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 52 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 53 |
+
num_key_value_heads (`int`, *optional*):
|
| 54 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 55 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 56 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 57 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 58 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 59 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 60 |
+
`num_attention_heads`.
|
| 61 |
+
resid_pdrop (`float`, *optional*, defaults to 0.0):
|
| 62 |
+
Dropout probability for mlp outputs.
|
| 63 |
+
embd_pdrop (`int`, *optional*, defaults to 0.0):
|
| 64 |
+
The dropout ratio for the embeddings.
|
| 65 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 66 |
+
The dropout ratio after computing the attention scores.
|
| 67 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 68 |
+
The non-linear activation function (function or string) in the decoder.
|
| 69 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 70 |
+
The maximum sequence length that this model might ever be used with.
|
| 71 |
+
original_max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 72 |
+
The maximum sequence length that this model was trained with. This is used to determine the size of the
|
| 73 |
+
original RoPE embeddings when using long scaling.
|
| 74 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 75 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 76 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 77 |
+
The epsilon value used for the RMSNorm.
|
| 78 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 79 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 80 |
+
relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
|
| 81 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 82 |
+
Whether to tie weight embeddings
|
| 83 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 84 |
+
The base period of the RoPE embeddings.
|
| 85 |
+
rope_scaling (`dict`, *optional*):
|
| 86 |
+
The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
|
| 87 |
+
contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be `longrope` and
|
| 88 |
+
the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
|
| 89 |
+
divided by the number of attention heads divided by 2.
|
| 90 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 91 |
+
The id of the "beginning-of-sequence" token.
|
| 92 |
+
eos_token_id (`int`, *optional*, defaults to 32000):
|
| 93 |
+
The id of the "end-of-sequence" token.
|
| 94 |
+
pad_token_id (`int`, *optional*, defaults to 32000):
|
| 95 |
+
The id of the padding token.
|
| 96 |
+
sliding_window (`int`, *optional*):
|
| 97 |
+
Sliding window attention window size. If `None`, no sliding window is applied.
|
| 98 |
+
|
| 99 |
+
Example:
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
>>> from transformers import Phi3Model, Phi3Config
|
| 103 |
+
|
| 104 |
+
>>> # Initializing a Phi-3 style configuration
|
| 105 |
+
>>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 106 |
+
|
| 107 |
+
>>> # Initializing a model from the configuration
|
| 108 |
+
>>> model = Phi3Model(configuration)
|
| 109 |
+
|
| 110 |
+
>>> # Accessing the model configuration
|
| 111 |
+
>>> configuration = model.config
|
| 112 |
+
```"""
|
| 113 |
+
|
| 114 |
+
model_type = "phi3"
|
| 115 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
+
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
vocab_size=32064,
|
| 120 |
+
hidden_size=3072,
|
| 121 |
+
intermediate_size=8192,
|
| 122 |
+
num_hidden_layers=32,
|
| 123 |
+
num_attention_heads=32,
|
| 124 |
+
num_key_value_heads=None,
|
| 125 |
+
resid_pdrop=0.0,
|
| 126 |
+
embd_pdrop=0.0,
|
| 127 |
+
attention_dropout=0.0,
|
| 128 |
+
hidden_act="silu",
|
| 129 |
+
max_position_embeddings=4096,
|
| 130 |
+
original_max_position_embeddings=4096,
|
| 131 |
+
initializer_range=0.02,
|
| 132 |
+
rms_norm_eps=1e-5,
|
| 133 |
+
use_cache=True,
|
| 134 |
+
tie_word_embeddings=False,
|
| 135 |
+
rope_theta=10000.0,
|
| 136 |
+
rope_scaling=None,
|
| 137 |
+
bos_token_id=1,
|
| 138 |
+
eos_token_id=32000,
|
| 139 |
+
pad_token_id=32000,
|
| 140 |
+
sliding_window=None,
|
| 141 |
+
**kwargs,
|
| 142 |
+
):
|
| 143 |
+
self.vocab_size = vocab_size
|
| 144 |
+
self.hidden_size = hidden_size
|
| 145 |
+
self.intermediate_size = intermediate_size
|
| 146 |
+
self.num_hidden_layers = num_hidden_layers
|
| 147 |
+
self.num_attention_heads = num_attention_heads
|
| 148 |
+
|
| 149 |
+
if num_key_value_heads is None:
|
| 150 |
+
num_key_value_heads = num_attention_heads
|
| 151 |
+
|
| 152 |
+
self.num_key_value_heads = num_key_value_heads
|
| 153 |
+
self.resid_pdrop = resid_pdrop
|
| 154 |
+
self.embd_pdrop = embd_pdrop
|
| 155 |
+
self.attention_dropout = attention_dropout
|
| 156 |
+
self.hidden_act = hidden_act
|
| 157 |
+
self.max_position_embeddings = max_position_embeddings
|
| 158 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
| 159 |
+
self.initializer_range = initializer_range
|
| 160 |
+
self.rms_norm_eps = rms_norm_eps
|
| 161 |
+
self.use_cache = use_cache
|
| 162 |
+
self.rope_theta = rope_theta
|
| 163 |
+
self.rope_scaling = rope_scaling
|
| 164 |
+
self._rope_scaling_adjustment()
|
| 165 |
+
self._rope_scaling_validation()
|
| 166 |
+
self.sliding_window = sliding_window
|
| 167 |
+
|
| 168 |
+
super().__init__(
|
| 169 |
+
bos_token_id=bos_token_id,
|
| 170 |
+
eos_token_id=eos_token_id,
|
| 171 |
+
pad_token_id=pad_token_id,
|
| 172 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 173 |
+
**kwargs,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
def _rope_scaling_adjustment(self):
|
| 177 |
+
"""
|
| 178 |
+
Adjust the `type` of the `rope_scaling` configuration for backward compatibility.
|
| 179 |
+
"""
|
| 180 |
+
if self.rope_scaling is None:
|
| 181 |
+
return
|
| 182 |
+
|
| 183 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 184 |
+
|
| 185 |
+
# For backward compatibility if previous version used "su" or "yarn"
|
| 186 |
+
if rope_scaling_type is not None and rope_scaling_type in ["su", "yarn"]:
|
| 187 |
+
self.rope_scaling["type"] = "longrope"
|
| 188 |
+
|
| 189 |
+
def _rope_scaling_validation(self):
|
| 190 |
+
"""
|
| 191 |
+
Validate the `rope_scaling` configuration.
|
| 192 |
+
"""
|
| 193 |
+
if self.rope_scaling is None:
|
| 194 |
+
return
|
| 195 |
+
|
| 196 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
|
| 197 |
+
raise ValueError(
|
| 198 |
+
"`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
|
| 199 |
+
f"got {self.rope_scaling}"
|
| 200 |
+
)
|
| 201 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 202 |
+
rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
|
| 203 |
+
rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
|
| 204 |
+
if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
|
| 205 |
+
raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
|
| 206 |
+
if not (
|
| 207 |
+
isinstance(rope_scaling_short_factor, list)
|
| 208 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
|
| 209 |
+
):
|
| 210 |
+
raise ValueError(
|
| 211 |
+
f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
|
| 212 |
+
)
|
| 213 |
+
if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 214 |
+
raise ValueError(
|
| 215 |
+
f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
|
| 216 |
+
)
|
| 217 |
+
if not (
|
| 218 |
+
isinstance(rope_scaling_long_factor, list)
|
| 219 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
|
| 220 |
+
):
|
| 221 |
+
raise ValueError(
|
| 222 |
+
f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
|
| 223 |
+
)
|
| 224 |
+
if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
|
| 225 |
+
raise ValueError(
|
| 226 |
+
f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
|
| 227 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
32000,
|
| 6 |
+
32001,
|
| 7 |
+
32007
|
| 8 |
+
],
|
| 9 |
+
"pad_token_id": 32000,
|
| 10 |
+
"transformers_version": "4.45.2"
|
| 11 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1025ddd29036a9ebfbef81af409d957268a68d5f72435936017b1a0d586302f4
|
| 3 |
+
size 4972489328
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 7642159104
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 7 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 8 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.10.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.10.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.11.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.11.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.12.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.12.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.13.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.13.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.14.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.14.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.15.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.15.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.16.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.16.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.17.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.17.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.18.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 73 |
+
"model.layers.18.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 75 |
+
"model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 76 |
+
"model.layers.19.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 77 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.19.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.20.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.20.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 93 |
+
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 94 |
+
"model.layers.21.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 95 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 96 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.21.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 98 |
+
"model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 99 |
+
"model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 100 |
+
"model.layers.22.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 101 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 102 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 103 |
+
"model.layers.22.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 104 |
+
"model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 105 |
+
"model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 106 |
+
"model.layers.23.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 107 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 108 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 109 |
+
"model.layers.23.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 110 |
+
"model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 111 |
+
"model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 112 |
+
"model.layers.24.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 113 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 114 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 115 |
+
"model.layers.24.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 116 |
+
"model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 117 |
+
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 118 |
+
"model.layers.25.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 119 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 120 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 121 |
+
"model.layers.25.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 122 |
+
"model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 123 |
+
"model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 124 |
+
"model.layers.26.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 125 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 126 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 127 |
+
"model.layers.26.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 128 |
+
"model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 129 |
+
"model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 130 |
+
"model.layers.27.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 131 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 132 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 133 |
+
"model.layers.27.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 134 |
+
"model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 135 |
+
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 136 |
+
"model.layers.28.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 137 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 138 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 139 |
+
"model.layers.28.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 140 |
+
"model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 141 |
+
"model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 142 |
+
"model.layers.29.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 143 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 144 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 145 |
+
"model.layers.29.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 146 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 152 |
+
"model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 153 |
+
"model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 154 |
+
"model.layers.30.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 155 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 156 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 157 |
+
"model.layers.30.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 158 |
+
"model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 159 |
+
"model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 160 |
+
"model.layers.31.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
| 161 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 162 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
| 163 |
+
"model.layers.31.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
| 164 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 165 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 166 |
+
"model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 167 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 168 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 169 |
+
"model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 170 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 171 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 172 |
+
"model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 173 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 174 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 175 |
+
"model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 176 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 177 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 178 |
+
"model.layers.6.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 179 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 180 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 181 |
+
"model.layers.6.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 182 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 183 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 184 |
+
"model.layers.7.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 185 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 186 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 187 |
+
"model.layers.7.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 188 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 189 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 190 |
+
"model.layers.8.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 191 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 192 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 193 |
+
"model.layers.8.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 194 |
+
"model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 195 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 196 |
+
"model.layers.9.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
| 197 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 198 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 199 |
+
"model.layers.9.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
| 200 |
+
"model.norm.weight": "model-00002-of-00002.safetensors"
|
| 201 |
+
}
|
| 202 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/modeling_phi3.py
ADDED
|
@@ -0,0 +1,1563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 Microsoft 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 |
+
|
| 16 |
+
""" PyTorch Phi-3 model."""
|
| 17 |
+
|
| 18 |
+
import inspect
|
| 19 |
+
import math
|
| 20 |
+
import warnings
|
| 21 |
+
from typing import List, Optional, Tuple, Union
|
| 22 |
+
|
| 23 |
+
import torch
|
| 24 |
+
import torch.nn.functional as F
|
| 25 |
+
import torch.utils.checkpoint
|
| 26 |
+
from torch import nn
|
| 27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
| 28 |
+
|
| 29 |
+
from transformers.activations import ACT2FN
|
| 30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
|
| 32 |
+
from transformers.modeling_outputs import (
|
| 33 |
+
BaseModelOutputWithPast,
|
| 34 |
+
CausalLMOutputWithPast,
|
| 35 |
+
SequenceClassifierOutputWithPast,
|
| 36 |
+
TokenClassifierOutput,
|
| 37 |
+
)
|
| 38 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 39 |
+
from transformers.utils import (
|
| 40 |
+
add_code_sample_docstrings,
|
| 41 |
+
add_start_docstrings,
|
| 42 |
+
add_start_docstrings_to_model_forward,
|
| 43 |
+
is_flash_attn_2_available,
|
| 44 |
+
is_flash_attn_greater_or_equal_2_10,
|
| 45 |
+
logging,
|
| 46 |
+
replace_return_docstrings,
|
| 47 |
+
)
|
| 48 |
+
from .configuration_phi3 import Phi3Config
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
logger = logging.get_logger(__name__)
|
| 52 |
+
|
| 53 |
+
# Transformers scans dependencies in the modeling file, causing issues on conditional loading. The regex only ignores try/catch blocks, but not if statements
|
| 54 |
+
# if is_flash_attn_2_available():
|
| 55 |
+
_flash_supports_window_size = False
|
| 56 |
+
try:
|
| 57 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 58 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 59 |
+
|
| 60 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 61 |
+
except ImportError as error:
|
| 62 |
+
logger.warning(
|
| 63 |
+
f"`flash-attention` package not found, consider installing for better performance: {error}."
|
| 64 |
+
)
|
| 65 |
+
if not _flash_supports_window_size:
|
| 66 |
+
logger.warning(
|
| 67 |
+
"Current `flash-attention` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`."
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
_CHECKPOINT_FOR_DOC = "microsoft/Phi-3-mini-4k-instruct"
|
| 71 |
+
_CONFIG_FOR_DOC = "Phi3Config"
|
| 72 |
+
|
| 73 |
+
PHI3_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
| 74 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
| 75 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 76 |
+
# See all Phi-3 models at https://huggingface.co/models?filter=Phi-3
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Phi3
|
| 81 |
+
class Phi3RMSNorm(nn.Module):
|
| 82 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 83 |
+
"""
|
| 84 |
+
Phi3RMSNorm is equivalent to T5LayerNorm
|
| 85 |
+
"""
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 88 |
+
self.variance_epsilon = eps
|
| 89 |
+
|
| 90 |
+
def forward(self, hidden_states):
|
| 91 |
+
input_dtype = hidden_states.dtype
|
| 92 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 93 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 94 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 95 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
| 99 |
+
def _get_unpad_data(attention_mask):
|
| 100 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
| 101 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
| 102 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
| 103 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
| 104 |
+
return (
|
| 105 |
+
indices,
|
| 106 |
+
cu_seqlens,
|
| 107 |
+
max_seqlen_in_batch,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# Copied from transformers.models.gemma.modeling_gemma.GemmaRotaryEmbedding with gemma->phi3, Gemma->Phi3
|
| 112 |
+
class Phi3RotaryEmbedding(nn.Module):
|
| 113 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
| 114 |
+
super().__init__()
|
| 115 |
+
|
| 116 |
+
self.dim = dim
|
| 117 |
+
self.max_position_embeddings = max_position_embeddings
|
| 118 |
+
self.base = base
|
| 119 |
+
self.register_buffer("inv_freq", None, persistent=False)
|
| 120 |
+
|
| 121 |
+
@torch.no_grad()
|
| 122 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 123 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
| 124 |
+
if self.inv_freq is None:
|
| 125 |
+
self.inv_freq = 1.0 / (
|
| 126 |
+
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
|
| 127 |
+
)
|
| 128 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 129 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 130 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 131 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 132 |
+
device_type = x.device.type
|
| 133 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 134 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 135 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 136 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 137 |
+
cos = emb.cos()
|
| 138 |
+
sin = emb.sin()
|
| 139 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class Phi3LongRoPEScaledRotaryEmbedding(Phi3RotaryEmbedding):
|
| 143 |
+
def __init__(self, dim, config, device=None):
|
| 144 |
+
super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
|
| 145 |
+
|
| 146 |
+
self.short_factor = config.rope_scaling["short_factor"]
|
| 147 |
+
self.long_factor = config.rope_scaling["long_factor"]
|
| 148 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 149 |
+
|
| 150 |
+
@torch.no_grad()
|
| 151 |
+
def forward(self, x, position_ids, seq_len=None):
|
| 152 |
+
seq_len = torch.max(position_ids) + 1
|
| 153 |
+
if seq_len > self.original_max_position_embeddings:
|
| 154 |
+
ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
|
| 155 |
+
else:
|
| 156 |
+
ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
|
| 157 |
+
|
| 158 |
+
inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
|
| 159 |
+
self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
|
| 160 |
+
|
| 161 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 162 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 163 |
+
|
| 164 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
| 165 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
| 166 |
+
device_type = x.device.type
|
| 167 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 168 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 169 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 170 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 171 |
+
|
| 172 |
+
scale = self.max_position_embeddings / self.original_max_position_embeddings
|
| 173 |
+
if scale <= 1.0:
|
| 174 |
+
scaling_factor = 1.0
|
| 175 |
+
else:
|
| 176 |
+
scaling_factor = math.sqrt(1 + math.log(scale) / math.log(self.original_max_position_embeddings))
|
| 177 |
+
|
| 178 |
+
cos = emb.cos() * scaling_factor
|
| 179 |
+
sin = emb.sin() * scaling_factor
|
| 180 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
| 184 |
+
def rotate_half(x):
|
| 185 |
+
"""Rotates half the hidden dims of the input."""
|
| 186 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 187 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 188 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
|
| 192 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 193 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 194 |
+
|
| 195 |
+
Args:
|
| 196 |
+
q (`torch.Tensor`): The query tensor.
|
| 197 |
+
k (`torch.Tensor`): The key tensor.
|
| 198 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 199 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 200 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 201 |
+
Deprecated and unused.
|
| 202 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 203 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 204 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 205 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 206 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 207 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 208 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 209 |
+
Returns:
|
| 210 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 211 |
+
"""
|
| 212 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 213 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 214 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 215 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 216 |
+
return q_embed, k_embed
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class Phi3MLP(nn.Module):
|
| 220 |
+
def __init__(self, config):
|
| 221 |
+
super().__init__()
|
| 222 |
+
|
| 223 |
+
self.config = config
|
| 224 |
+
self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
|
| 225 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 226 |
+
|
| 227 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
| 228 |
+
|
| 229 |
+
def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
|
| 230 |
+
up_states = self.gate_up_proj(hidden_states)
|
| 231 |
+
|
| 232 |
+
gate, up_states = up_states.chunk(2, dim=-1)
|
| 233 |
+
up_states = up_states * self.activation_fn(gate)
|
| 234 |
+
|
| 235 |
+
return self.down_proj(up_states)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
|
| 239 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 240 |
+
"""
|
| 241 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 242 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 243 |
+
"""
|
| 244 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 245 |
+
if n_rep == 1:
|
| 246 |
+
return hidden_states
|
| 247 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 248 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class Phi3Attention(nn.Module):
|
| 252 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 253 |
+
|
| 254 |
+
def __init__(self, config: Phi3Config, layer_idx: Optional[int] = None):
|
| 255 |
+
super().__init__()
|
| 256 |
+
self.config = config
|
| 257 |
+
self.layer_idx = layer_idx
|
| 258 |
+
if layer_idx is None:
|
| 259 |
+
logger.warning_once(
|
| 260 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
| 261 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
| 262 |
+
"when creating this class."
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
self.attention_dropout = config.attention_dropout
|
| 266 |
+
self.hidden_size = config.hidden_size
|
| 267 |
+
self.num_heads = config.num_attention_heads
|
| 268 |
+
self.head_dim = self.hidden_size // self.num_heads
|
| 269 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 270 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
| 271 |
+
self.max_position_embeddings = config.max_position_embeddings
|
| 272 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
| 273 |
+
self.rope_theta = config.rope_theta
|
| 274 |
+
self.rope_scaling = config.rope_scaling
|
| 275 |
+
self.is_causal = True
|
| 276 |
+
|
| 277 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
| 278 |
+
raise ValueError(
|
| 279 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
| 280 |
+
f" and `num_heads`: {self.num_heads})."
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
op_size = self.num_heads * self.head_dim + 2 * (self.num_key_value_heads * self.head_dim)
|
| 284 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
| 285 |
+
self.qkv_proj = nn.Linear(self.hidden_size, op_size, bias=False)
|
| 286 |
+
self._init_rope()
|
| 287 |
+
|
| 288 |
+
def _init_rope(self):
|
| 289 |
+
if self.rope_scaling is None:
|
| 290 |
+
self.rotary_emb = Phi3RotaryEmbedding(
|
| 291 |
+
self.head_dim,
|
| 292 |
+
max_position_embeddings=self.max_position_embeddings,
|
| 293 |
+
base=self.rope_theta,
|
| 294 |
+
)
|
| 295 |
+
else:
|
| 296 |
+
scaling_type = self.config.rope_scaling["type"]
|
| 297 |
+
if scaling_type == "longrope":
|
| 298 |
+
self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
|
| 299 |
+
else:
|
| 300 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
| 301 |
+
|
| 302 |
+
def forward(
|
| 303 |
+
self,
|
| 304 |
+
hidden_states: torch.Tensor,
|
| 305 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 306 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 307 |
+
past_key_value: Optional[Cache] = None,
|
| 308 |
+
output_attentions: bool = False,
|
| 309 |
+
use_cache: bool = False,
|
| 310 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 311 |
+
logger.warning_once("You are not running the flash-attention implementation, expect numerical differences.")
|
| 312 |
+
|
| 313 |
+
bsz, q_len, _ = hidden_states.size()
|
| 314 |
+
|
| 315 |
+
qkv = self.qkv_proj(hidden_states)
|
| 316 |
+
query_pos = self.num_heads * self.head_dim
|
| 317 |
+
query_states = qkv[..., :query_pos]
|
| 318 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 319 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 320 |
+
|
| 321 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 322 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 323 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 324 |
+
|
| 325 |
+
kv_seq_len = key_states.shape[-2]
|
| 326 |
+
if past_key_value is not None:
|
| 327 |
+
if self.layer_idx is None:
|
| 328 |
+
raise ValueError(
|
| 329 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 330 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 331 |
+
"with a layer index."
|
| 332 |
+
)
|
| 333 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 334 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 335 |
+
|
| 336 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 337 |
+
|
| 338 |
+
if past_key_value is not None:
|
| 339 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 340 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 341 |
+
|
| 342 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 343 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 344 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 345 |
+
|
| 346 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
| 347 |
+
|
| 348 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
| 349 |
+
raise ValueError(
|
| 350 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
| 351 |
+
f" {attn_weights.size()}"
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
if attention_mask is not None:
|
| 355 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 356 |
+
raise ValueError(
|
| 357 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 358 |
+
)
|
| 359 |
+
attn_weights = attn_weights + attention_mask
|
| 360 |
+
|
| 361 |
+
# upcast attention to fp32
|
| 362 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
|
| 363 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
| 364 |
+
|
| 365 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 366 |
+
|
| 367 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
| 368 |
+
raise ValueError(
|
| 369 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
| 370 |
+
f" {attn_output.size()}"
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 374 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
| 375 |
+
|
| 376 |
+
attn_output = self.o_proj(attn_output)
|
| 377 |
+
|
| 378 |
+
if not output_attentions:
|
| 379 |
+
attn_weights = None
|
| 380 |
+
|
| 381 |
+
return attn_output, attn_weights, past_key_value
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class Phi3FlashAttention2(Phi3Attention):
|
| 385 |
+
"""
|
| 386 |
+
Phi-3 flash attention module. This module inherits from `Phi3Attention` as the weights of the module stays
|
| 387 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
| 388 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
| 389 |
+
"""
|
| 390 |
+
|
| 391 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
|
| 392 |
+
def __init__(self, *args, **kwargs):
|
| 393 |
+
super().__init__(*args, **kwargs)
|
| 394 |
+
|
| 395 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
| 396 |
+
# 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.
|
| 397 |
+
# 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).
|
| 398 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
| 399 |
+
|
| 400 |
+
def forward(
|
| 401 |
+
self,
|
| 402 |
+
hidden_states: torch.Tensor,
|
| 403 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 404 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 405 |
+
past_key_value: Optional[Cache] = None,
|
| 406 |
+
output_attentions: bool = False,
|
| 407 |
+
use_cache: bool = False,
|
| 408 |
+
**kwargs,
|
| 409 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 410 |
+
# Phi3FlashAttention2 attention does not support output_attentions
|
| 411 |
+
|
| 412 |
+
if not _flash_supports_window_size:
|
| 413 |
+
logger.warning_once(
|
| 414 |
+
"The current flash attention version does not support sliding window attention. Please use `attn_implementation='eager'` or upgrade flash-attn library."
|
| 415 |
+
)
|
| 416 |
+
raise ValueError("The current flash attention version does not support sliding window attention.")
|
| 417 |
+
|
| 418 |
+
output_attentions = False
|
| 419 |
+
|
| 420 |
+
if "padding_mask" in kwargs:
|
| 421 |
+
warnings.warn(
|
| 422 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
# overwrite attention_mask with padding_mask
|
| 426 |
+
attention_mask = kwargs.pop("padding_mask")
|
| 427 |
+
|
| 428 |
+
bsz, q_len, _ = hidden_states.size()
|
| 429 |
+
|
| 430 |
+
qkv = self.qkv_proj(hidden_states)
|
| 431 |
+
query_pos = self.num_heads * self.head_dim
|
| 432 |
+
query_states = qkv[..., :query_pos]
|
| 433 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 434 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 435 |
+
|
| 436 |
+
# Flash attention requires the input to have the shape
|
| 437 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
| 438 |
+
# therefore we just need to keep the original shape
|
| 439 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 440 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 441 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 442 |
+
|
| 443 |
+
kv_seq_len = key_states.shape[-2]
|
| 444 |
+
if past_key_value is not None:
|
| 445 |
+
if self.layer_idx is None:
|
| 446 |
+
raise ValueError(
|
| 447 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
| 448 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
| 449 |
+
"with a layer index."
|
| 450 |
+
)
|
| 451 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 452 |
+
|
| 453 |
+
# Because the input can be padded, the absolute sequence length depends on the max position id.
|
| 454 |
+
rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
|
| 455 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=rotary_seq_len)
|
| 456 |
+
|
| 457 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 458 |
+
|
| 459 |
+
use_sliding_windows = (
|
| 460 |
+
_flash_supports_window_size
|
| 461 |
+
and getattr(self.config, "sliding_window", None) is not None
|
| 462 |
+
and kv_seq_len > self.config.sliding_window
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
if past_key_value is not None:
|
| 466 |
+
# Activate slicing cache only if the config has a value `sliding_windows` attribute
|
| 467 |
+
cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
|
| 468 |
+
if (
|
| 469 |
+
getattr(self.config, "sliding_window", None) is not None
|
| 470 |
+
and kv_seq_len > self.config.sliding_window
|
| 471 |
+
and cache_has_contents
|
| 472 |
+
):
|
| 473 |
+
slicing_tokens = 1 - self.config.sliding_window
|
| 474 |
+
|
| 475 |
+
past_key = past_key_value[self.layer_idx][0]
|
| 476 |
+
past_value = past_key_value[self.layer_idx][1]
|
| 477 |
+
|
| 478 |
+
past_key = past_key[:, :, slicing_tokens:, :].contiguous()
|
| 479 |
+
past_value = past_value[:, :, slicing_tokens:, :].contiguous()
|
| 480 |
+
|
| 481 |
+
if past_key.shape[-2] != self.config.sliding_window - 1:
|
| 482 |
+
raise ValueError(
|
| 483 |
+
f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
|
| 484 |
+
f" {past_key.shape}"
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
if attention_mask is not None:
|
| 488 |
+
attention_mask = attention_mask[:, slicing_tokens:]
|
| 489 |
+
attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
|
| 490 |
+
|
| 491 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 492 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 493 |
+
|
| 494 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
| 495 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 496 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 497 |
+
|
| 498 |
+
attn_dropout = self.attention_dropout if self.training else 0.0
|
| 499 |
+
|
| 500 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
| 501 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
| 502 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
| 503 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
| 504 |
+
# in fp32.
|
| 505 |
+
|
| 506 |
+
if query_states.dtype == torch.float32:
|
| 507 |
+
if torch.is_autocast_enabled():
|
| 508 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
| 509 |
+
# Handle the case where the model is quantized
|
| 510 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
| 511 |
+
target_dtype = self.config._pre_quantization_dtype
|
| 512 |
+
else:
|
| 513 |
+
target_dtype = self.qkv_proj.weight.dtype
|
| 514 |
+
|
| 515 |
+
logger.warning_once(
|
| 516 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
| 517 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
| 518 |
+
f" {target_dtype}."
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
query_states = query_states.to(target_dtype)
|
| 522 |
+
key_states = key_states.to(target_dtype)
|
| 523 |
+
value_states = value_states.to(target_dtype)
|
| 524 |
+
|
| 525 |
+
# Reashape to the expected shape for Flash Attention
|
| 526 |
+
query_states = query_states.transpose(1, 2)
|
| 527 |
+
key_states = key_states.transpose(1, 2)
|
| 528 |
+
value_states = value_states.transpose(1, 2)
|
| 529 |
+
|
| 530 |
+
attn_output = self._flash_attention_forward(
|
| 531 |
+
query_states,
|
| 532 |
+
key_states,
|
| 533 |
+
value_states,
|
| 534 |
+
attention_mask,
|
| 535 |
+
q_len,
|
| 536 |
+
dropout=attn_dropout,
|
| 537 |
+
use_sliding_windows=use_sliding_windows,
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
| 541 |
+
attn_output = self.o_proj(attn_output)
|
| 542 |
+
|
| 543 |
+
if not output_attentions:
|
| 544 |
+
attn_weights = None
|
| 545 |
+
|
| 546 |
+
return attn_output, attn_weights, past_key_value
|
| 547 |
+
|
| 548 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._flash_attention_forward
|
| 549 |
+
def _flash_attention_forward(
|
| 550 |
+
self,
|
| 551 |
+
query_states,
|
| 552 |
+
key_states,
|
| 553 |
+
value_states,
|
| 554 |
+
attention_mask,
|
| 555 |
+
query_length,
|
| 556 |
+
dropout=0.0,
|
| 557 |
+
softmax_scale=None,
|
| 558 |
+
use_sliding_windows=False,
|
| 559 |
+
):
|
| 560 |
+
"""
|
| 561 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
| 562 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
| 563 |
+
|
| 564 |
+
Args:
|
| 565 |
+
query_states (`torch.Tensor`):
|
| 566 |
+
Input query states to be passed to Flash Attention API
|
| 567 |
+
key_states (`torch.Tensor`):
|
| 568 |
+
Input key states to be passed to Flash Attention API
|
| 569 |
+
value_states (`torch.Tensor`):
|
| 570 |
+
Input value states to be passed to Flash Attention API
|
| 571 |
+
attention_mask (`torch.Tensor`):
|
| 572 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
| 573 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
| 574 |
+
dropout (`float`):
|
| 575 |
+
Attention dropout
|
| 576 |
+
softmax_scale (`float`, *optional*):
|
| 577 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
| 578 |
+
use_sliding_windows (`bool`, *optional*):
|
| 579 |
+
Whether to activate sliding window attention.
|
| 580 |
+
"""
|
| 581 |
+
if not self._flash_attn_uses_top_left_mask:
|
| 582 |
+
causal = self.is_causal
|
| 583 |
+
else:
|
| 584 |
+
# 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__.
|
| 585 |
+
causal = self.is_causal and query_length != 1
|
| 586 |
+
|
| 587 |
+
# Contains at least one padding token in the sequence
|
| 588 |
+
if attention_mask is not None:
|
| 589 |
+
batch_size = query_states.shape[0]
|
| 590 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
| 591 |
+
query_states, key_states, value_states, attention_mask, query_length
|
| 592 |
+
)
|
| 593 |
+
|
| 594 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
| 595 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
| 596 |
+
|
| 597 |
+
if not use_sliding_windows:
|
| 598 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 599 |
+
query_states,
|
| 600 |
+
key_states,
|
| 601 |
+
value_states,
|
| 602 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 603 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 604 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 605 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 606 |
+
dropout_p=dropout,
|
| 607 |
+
softmax_scale=softmax_scale,
|
| 608 |
+
causal=causal,
|
| 609 |
+
)
|
| 610 |
+
else:
|
| 611 |
+
attn_output_unpad = flash_attn_varlen_func(
|
| 612 |
+
query_states,
|
| 613 |
+
key_states,
|
| 614 |
+
value_states,
|
| 615 |
+
cu_seqlens_q=cu_seqlens_q,
|
| 616 |
+
cu_seqlens_k=cu_seqlens_k,
|
| 617 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
| 618 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
| 619 |
+
dropout_p=dropout,
|
| 620 |
+
softmax_scale=softmax_scale,
|
| 621 |
+
causal=causal,
|
| 622 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 623 |
+
)
|
| 624 |
+
|
| 625 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
| 626 |
+
else:
|
| 627 |
+
if not use_sliding_windows:
|
| 628 |
+
attn_output = flash_attn_func(
|
| 629 |
+
query_states,
|
| 630 |
+
key_states,
|
| 631 |
+
value_states,
|
| 632 |
+
dropout,
|
| 633 |
+
softmax_scale=softmax_scale,
|
| 634 |
+
causal=causal,
|
| 635 |
+
)
|
| 636 |
+
else:
|
| 637 |
+
attn_output = flash_attn_func(
|
| 638 |
+
query_states,
|
| 639 |
+
key_states,
|
| 640 |
+
value_states,
|
| 641 |
+
dropout,
|
| 642 |
+
softmax_scale=softmax_scale,
|
| 643 |
+
causal=causal,
|
| 644 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
return attn_output
|
| 648 |
+
|
| 649 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
|
| 650 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
| 651 |
+
batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
|
| 652 |
+
|
| 653 |
+
# On the first iteration we need to properly re-create the padding mask
|
| 654 |
+
# by slicing it on the proper place
|
| 655 |
+
if kv_seq_len != attention_mask.shape[-1]:
|
| 656 |
+
attention_mask_num_tokens = attention_mask.shape[-1]
|
| 657 |
+
attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
|
| 658 |
+
|
| 659 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
| 660 |
+
|
| 661 |
+
key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 662 |
+
value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
| 663 |
+
|
| 664 |
+
if query_length == kv_seq_len:
|
| 665 |
+
query_layer = index_first_axis(
|
| 666 |
+
query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
|
| 667 |
+
)
|
| 668 |
+
cu_seqlens_q = cu_seqlens_k
|
| 669 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
| 670 |
+
indices_q = indices_k
|
| 671 |
+
elif query_length == 1:
|
| 672 |
+
max_seqlen_in_batch_q = 1
|
| 673 |
+
cu_seqlens_q = torch.arange(
|
| 674 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
| 675 |
+
) # There is a memcpy here, that is very bad.
|
| 676 |
+
indices_q = cu_seqlens_q[:-1]
|
| 677 |
+
query_layer = query_layer.squeeze(1)
|
| 678 |
+
else:
|
| 679 |
+
# The -q_len: slice assumes left padding.
|
| 680 |
+
attention_mask = attention_mask[:, -query_length:]
|
| 681 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
| 682 |
+
|
| 683 |
+
return (
|
| 684 |
+
query_layer,
|
| 685 |
+
key_layer,
|
| 686 |
+
value_layer,
|
| 687 |
+
indices_q,
|
| 688 |
+
(cu_seqlens_q, cu_seqlens_k),
|
| 689 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
| 690 |
+
)
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
# copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Phi3
|
| 694 |
+
# TODO @Arthur no longer copied from LLama after static cache
|
| 695 |
+
class Phi3SdpaAttention(Phi3Attention):
|
| 696 |
+
"""
|
| 697 |
+
Phi3 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
| 698 |
+
`Phi3Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
| 699 |
+
SDPA API.
|
| 700 |
+
"""
|
| 701 |
+
|
| 702 |
+
# Adapted from Phi3Attention.forward
|
| 703 |
+
def forward(
|
| 704 |
+
self,
|
| 705 |
+
hidden_states: torch.Tensor,
|
| 706 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 707 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 708 |
+
past_key_value: Optional[Cache] = None,
|
| 709 |
+
output_attentions: bool = False,
|
| 710 |
+
use_cache: bool = False,
|
| 711 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 712 |
+
if output_attentions:
|
| 713 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
| 714 |
+
logger.warning_once(
|
| 715 |
+
"Phi3Model is using Phi3SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
| 716 |
+
'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.'
|
| 717 |
+
)
|
| 718 |
+
return super().forward(
|
| 719 |
+
hidden_states=hidden_states,
|
| 720 |
+
attention_mask=attention_mask,
|
| 721 |
+
position_ids=position_ids,
|
| 722 |
+
past_key_value=past_key_value,
|
| 723 |
+
output_attentions=output_attentions,
|
| 724 |
+
use_cache=use_cache,
|
| 725 |
+
)
|
| 726 |
+
|
| 727 |
+
bsz, q_len, _ = hidden_states.size()
|
| 728 |
+
|
| 729 |
+
qkv = self.qkv_proj(hidden_states)
|
| 730 |
+
query_pos = self.num_heads * self.head_dim
|
| 731 |
+
query_states = qkv[..., :query_pos]
|
| 732 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 733 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 734 |
+
|
| 735 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 736 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 737 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 738 |
+
|
| 739 |
+
kv_seq_len = key_states.shape[-2]
|
| 740 |
+
if past_key_value is not None:
|
| 741 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
| 742 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
| 743 |
+
|
| 744 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 745 |
+
|
| 746 |
+
if past_key_value is not None:
|
| 747 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
| 748 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 749 |
+
|
| 750 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 751 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 752 |
+
|
| 753 |
+
if attention_mask is not None:
|
| 754 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
| 755 |
+
raise ValueError(
|
| 756 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
| 757 |
+
)
|
| 758 |
+
|
| 759 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
| 760 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
| 761 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
| 762 |
+
query_states = query_states.contiguous()
|
| 763 |
+
key_states = key_states.contiguous()
|
| 764 |
+
value_states = value_states.contiguous()
|
| 765 |
+
|
| 766 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
| 767 |
+
query_states,
|
| 768 |
+
key_states,
|
| 769 |
+
value_states,
|
| 770 |
+
attn_mask=attention_mask,
|
| 771 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
| 772 |
+
# 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.
|
| 773 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
| 774 |
+
)
|
| 775 |
+
|
| 776 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 777 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
| 778 |
+
|
| 779 |
+
attn_output = self.o_proj(attn_output)
|
| 780 |
+
|
| 781 |
+
return attn_output, None, past_key_value
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
PHI3_ATTENTION_CLASSES = {
|
| 785 |
+
"eager": Phi3Attention,
|
| 786 |
+
"flash_attention_2": Phi3FlashAttention2,
|
| 787 |
+
"sdpa": Phi3SdpaAttention,
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
class Phi3DecoderLayer(nn.Module):
|
| 792 |
+
def __init__(self, config: Phi3Config, layer_idx: int):
|
| 793 |
+
super().__init__()
|
| 794 |
+
|
| 795 |
+
self.config = config
|
| 796 |
+
self.self_attn = PHI3_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
|
| 797 |
+
|
| 798 |
+
self.mlp = Phi3MLP(config)
|
| 799 |
+
self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 800 |
+
|
| 801 |
+
self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
|
| 802 |
+
self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
|
| 803 |
+
self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 804 |
+
|
| 805 |
+
def forward(
|
| 806 |
+
self,
|
| 807 |
+
hidden_states: torch.Tensor,
|
| 808 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 809 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 810 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
| 811 |
+
output_attentions: Optional[bool] = False,
|
| 812 |
+
use_cache: Optional[bool] = False,
|
| 813 |
+
**kwargs,
|
| 814 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 815 |
+
if "padding_mask" in kwargs:
|
| 816 |
+
warnings.warn(
|
| 817 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
| 818 |
+
)
|
| 819 |
+
"""
|
| 820 |
+
Args:
|
| 821 |
+
hidden_states (`torch.FloatTensor`):
|
| 822 |
+
input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 823 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 824 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 825 |
+
position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
|
| 826 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
|
| 827 |
+
`[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
| 828 |
+
output_attentions (`bool`, *optional*):
|
| 829 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 830 |
+
returned tensors for more detail.
|
| 831 |
+
use_cache (`bool`, *optional*):
|
| 832 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 833 |
+
(see `past_key_values`).
|
| 834 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
| 835 |
+
"""
|
| 836 |
+
|
| 837 |
+
residual = hidden_states
|
| 838 |
+
|
| 839 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 840 |
+
|
| 841 |
+
# Self Attention
|
| 842 |
+
attn_outputs, self_attn_weights, present_key_value = self.self_attn(
|
| 843 |
+
hidden_states=hidden_states,
|
| 844 |
+
attention_mask=attention_mask,
|
| 845 |
+
position_ids=position_ids,
|
| 846 |
+
past_key_value=past_key_value,
|
| 847 |
+
output_attentions=output_attentions,
|
| 848 |
+
use_cache=use_cache,
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
hidden_states = residual + self.resid_attn_dropout(attn_outputs)
|
| 852 |
+
|
| 853 |
+
residual = hidden_states
|
| 854 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 855 |
+
hidden_states = self.mlp(hidden_states)
|
| 856 |
+
hidden_states = residual + self.resid_mlp_dropout(hidden_states)
|
| 857 |
+
|
| 858 |
+
outputs = (hidden_states,)
|
| 859 |
+
|
| 860 |
+
if output_attentions:
|
| 861 |
+
outputs += (self_attn_weights,)
|
| 862 |
+
|
| 863 |
+
if use_cache:
|
| 864 |
+
outputs += (present_key_value,)
|
| 865 |
+
|
| 866 |
+
return outputs
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
PHI3_START_DOCSTRING = r"""
|
| 870 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 871 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 872 |
+
etc.)
|
| 873 |
+
|
| 874 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 875 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 876 |
+
and behavior.
|
| 877 |
+
|
| 878 |
+
Parameters:
|
| 879 |
+
config ([`Phi3Config`]):
|
| 880 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 881 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 882 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 883 |
+
"""
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
@add_start_docstrings(
|
| 887 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 888 |
+
PHI3_START_DOCSTRING,
|
| 889 |
+
)
|
| 890 |
+
class Phi3PreTrainedModel(PreTrainedModel):
|
| 891 |
+
config_class = Phi3Config
|
| 892 |
+
base_model_prefix = "model"
|
| 893 |
+
supports_gradient_checkpointing = True
|
| 894 |
+
_no_split_modules = ["Phi3DecoderLayer"]
|
| 895 |
+
_skip_keys_device_placement = "past_key_values"
|
| 896 |
+
_supports_flash_attn_2 = True
|
| 897 |
+
_supports_sdpa = False
|
| 898 |
+
_supports_cache_class = True
|
| 899 |
+
|
| 900 |
+
_version = "0.0.5"
|
| 901 |
+
|
| 902 |
+
def _init_weights(self, module):
|
| 903 |
+
std = self.config.initializer_range
|
| 904 |
+
if isinstance(module, nn.Linear):
|
| 905 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 906 |
+
if module.bias is not None:
|
| 907 |
+
module.bias.data.zero_()
|
| 908 |
+
elif isinstance(module, nn.Embedding):
|
| 909 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 910 |
+
if module.padding_idx is not None:
|
| 911 |
+
module.weight.data[module.padding_idx].zero_()
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
PHI3_INPUTS_DOCSTRING = r"""
|
| 915 |
+
Args:
|
| 916 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 917 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 918 |
+
it.
|
| 919 |
+
|
| 920 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 921 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 922 |
+
|
| 923 |
+
[What are input IDs?](../glossary#input-ids)
|
| 924 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 925 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 926 |
+
|
| 927 |
+
- 1 for tokens that are **not masked**,
|
| 928 |
+
- 0 for tokens that are **masked**.
|
| 929 |
+
|
| 930 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 931 |
+
|
| 932 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 933 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 934 |
+
|
| 935 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
| 936 |
+
`past_key_values`).
|
| 937 |
+
|
| 938 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 939 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 940 |
+
information on the default strategy.
|
| 941 |
+
|
| 942 |
+
- 1 indicates the head is **not masked**,
|
| 943 |
+
- 0 indicates the head is **masked**.
|
| 944 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 945 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 946 |
+
config.n_positions - 1]`.
|
| 947 |
+
|
| 948 |
+
[What are position IDs?](../glossary#position-ids)
|
| 949 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 950 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 951 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 952 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 953 |
+
|
| 954 |
+
Two formats are allowed:
|
| 955 |
+
- a [`~cache_utils.Cache`] instance;
|
| 956 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 957 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 958 |
+
cache format.
|
| 959 |
+
|
| 960 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 961 |
+
legacy cache format will be returned.
|
| 962 |
+
|
| 963 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 964 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 965 |
+
of shape `(batch_size, sequence_length)`.
|
| 966 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 967 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 968 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 969 |
+
model's internal embedding lookup matrix.
|
| 970 |
+
use_cache (`bool`, *optional*):
|
| 971 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 972 |
+
`past_key_values`).
|
| 973 |
+
output_attentions (`bool`, *optional*):
|
| 974 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 975 |
+
tensors for more detail.
|
| 976 |
+
output_hidden_states (`bool`, *optional*):
|
| 977 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 978 |
+
more detail.
|
| 979 |
+
return_dict (`bool`, *optional*):
|
| 980 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 981 |
+
"""
|
| 982 |
+
|
| 983 |
+
|
| 984 |
+
@add_start_docstrings(
|
| 985 |
+
"The bare Phi-3 model outputting raw hidden-states without any specific head on top.",
|
| 986 |
+
PHI3_START_DOCSTRING,
|
| 987 |
+
)
|
| 988 |
+
class Phi3Model(Phi3PreTrainedModel):
|
| 989 |
+
"""
|
| 990 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Phi3DecoderLayer`]
|
| 991 |
+
|
| 992 |
+
Args:
|
| 993 |
+
config: Phi3Config
|
| 994 |
+
"""
|
| 995 |
+
|
| 996 |
+
def __init__(self, config: Phi3Config):
|
| 997 |
+
super().__init__(config)
|
| 998 |
+
self.padding_idx = config.pad_token_id
|
| 999 |
+
self.vocab_size = config.vocab_size
|
| 1000 |
+
|
| 1001 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 1002 |
+
self.embed_dropout = nn.Dropout(config.embd_pdrop)
|
| 1003 |
+
self.layers = nn.ModuleList(
|
| 1004 |
+
[Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 1005 |
+
)
|
| 1006 |
+
self._attn_implementation = config._attn_implementation
|
| 1007 |
+
self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 1008 |
+
|
| 1009 |
+
self.gradient_checkpointing = False
|
| 1010 |
+
# Initialize weights and apply final processing
|
| 1011 |
+
self.post_init()
|
| 1012 |
+
|
| 1013 |
+
def get_input_embeddings(self):
|
| 1014 |
+
return self.embed_tokens
|
| 1015 |
+
|
| 1016 |
+
def set_input_embeddings(self, value):
|
| 1017 |
+
self.embed_tokens = value
|
| 1018 |
+
|
| 1019 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1020 |
+
def forward(
|
| 1021 |
+
self,
|
| 1022 |
+
input_ids: torch.LongTensor = None,
|
| 1023 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1024 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1025 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1026 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1027 |
+
use_cache: Optional[bool] = None,
|
| 1028 |
+
output_attentions: Optional[bool] = None,
|
| 1029 |
+
output_hidden_states: Optional[bool] = None,
|
| 1030 |
+
return_dict: Optional[bool] = None,
|
| 1031 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 1032 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1033 |
+
output_hidden_states = (
|
| 1034 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1035 |
+
)
|
| 1036 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1037 |
+
|
| 1038 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1039 |
+
|
| 1040 |
+
# retrieve input_ids and inputs_embeds
|
| 1041 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 1042 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
| 1043 |
+
elif input_ids is not None:
|
| 1044 |
+
batch_size, seq_length = input_ids.shape[:2]
|
| 1045 |
+
elif inputs_embeds is not None:
|
| 1046 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
| 1047 |
+
else:
|
| 1048 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
| 1049 |
+
|
| 1050 |
+
past_key_values_length = 0
|
| 1051 |
+
|
| 1052 |
+
if self.gradient_checkpointing and self.training:
|
| 1053 |
+
if use_cache:
|
| 1054 |
+
logger.warning_once(
|
| 1055 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
| 1056 |
+
)
|
| 1057 |
+
use_cache = False
|
| 1058 |
+
|
| 1059 |
+
if use_cache:
|
| 1060 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
| 1061 |
+
if use_legacy_cache:
|
| 1062 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
| 1063 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
| 1064 |
+
|
| 1065 |
+
if position_ids is None:
|
| 1066 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
| 1067 |
+
position_ids = torch.arange(
|
| 1068 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
| 1069 |
+
)
|
| 1070 |
+
position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
|
| 1071 |
+
else:
|
| 1072 |
+
position_ids = position_ids.view(-1, seq_length).long()
|
| 1073 |
+
|
| 1074 |
+
if inputs_embeds is None:
|
| 1075 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 1076 |
+
|
| 1077 |
+
if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
|
| 1078 |
+
is_padding_right = attention_mask[:, -1].sum().item() != batch_size
|
| 1079 |
+
if is_padding_right:
|
| 1080 |
+
raise ValueError(
|
| 1081 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 1082 |
+
" this may lead to unexpected behaviour for Flash Attention version of Phi3. Make sure to "
|
| 1083 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 1084 |
+
)
|
| 1085 |
+
|
| 1086 |
+
if self._attn_implementation == "flash_attention_2":
|
| 1087 |
+
# 2d mask is passed through the layers
|
| 1088 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
| 1089 |
+
else:
|
| 1090 |
+
# 4d mask is passed through the layers
|
| 1091 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
| 1092 |
+
attention_mask,
|
| 1093 |
+
(batch_size, seq_length),
|
| 1094 |
+
inputs_embeds,
|
| 1095 |
+
past_key_values_length,
|
| 1096 |
+
sliding_window=self.config.sliding_window,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
hidden_states = inputs_embeds
|
| 1100 |
+
|
| 1101 |
+
# decoder layers
|
| 1102 |
+
all_hidden_states = () if output_hidden_states else None
|
| 1103 |
+
all_self_attns = () if output_attentions else None
|
| 1104 |
+
next_decoder_cache = None
|
| 1105 |
+
|
| 1106 |
+
for decoder_layer in self.layers:
|
| 1107 |
+
if output_hidden_states:
|
| 1108 |
+
all_hidden_states += (hidden_states,)
|
| 1109 |
+
|
| 1110 |
+
if self.gradient_checkpointing and self.training:
|
| 1111 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 1112 |
+
decoder_layer.__call__,
|
| 1113 |
+
hidden_states,
|
| 1114 |
+
attention_mask,
|
| 1115 |
+
position_ids,
|
| 1116 |
+
past_key_values,
|
| 1117 |
+
output_attentions,
|
| 1118 |
+
use_cache,
|
| 1119 |
+
)
|
| 1120 |
+
else:
|
| 1121 |
+
layer_outputs = decoder_layer(
|
| 1122 |
+
hidden_states,
|
| 1123 |
+
attention_mask=attention_mask,
|
| 1124 |
+
position_ids=position_ids,
|
| 1125 |
+
past_key_value=past_key_values,
|
| 1126 |
+
output_attentions=output_attentions,
|
| 1127 |
+
use_cache=use_cache,
|
| 1128 |
+
)
|
| 1129 |
+
|
| 1130 |
+
hidden_states = layer_outputs[0]
|
| 1131 |
+
|
| 1132 |
+
if use_cache:
|
| 1133 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
| 1134 |
+
|
| 1135 |
+
if output_attentions:
|
| 1136 |
+
all_self_attns += (layer_outputs[1],)
|
| 1137 |
+
|
| 1138 |
+
hidden_states = self.norm(hidden_states)
|
| 1139 |
+
|
| 1140 |
+
# add hidden states from the last decoder layer
|
| 1141 |
+
if output_hidden_states:
|
| 1142 |
+
all_hidden_states += (hidden_states,)
|
| 1143 |
+
|
| 1144 |
+
next_cache = None
|
| 1145 |
+
if use_cache:
|
| 1146 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
| 1147 |
+
if not return_dict:
|
| 1148 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
| 1149 |
+
return BaseModelOutputWithPast(
|
| 1150 |
+
last_hidden_state=hidden_states,
|
| 1151 |
+
past_key_values=next_cache,
|
| 1152 |
+
hidden_states=all_hidden_states,
|
| 1153 |
+
attentions=all_self_attns,
|
| 1154 |
+
)
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
class Phi3ForCausalLM(Phi3PreTrainedModel):
|
| 1158 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 1159 |
+
|
| 1160 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi3
|
| 1161 |
+
def __init__(self, config):
|
| 1162 |
+
super().__init__(config)
|
| 1163 |
+
self.model = Phi3Model(config)
|
| 1164 |
+
self.vocab_size = config.vocab_size
|
| 1165 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1166 |
+
|
| 1167 |
+
# Initialize weights and apply final processing
|
| 1168 |
+
self.post_init()
|
| 1169 |
+
|
| 1170 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
|
| 1171 |
+
def get_input_embeddings(self):
|
| 1172 |
+
return self.model.embed_tokens
|
| 1173 |
+
|
| 1174 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
|
| 1175 |
+
def set_input_embeddings(self, value):
|
| 1176 |
+
self.model.embed_tokens = value
|
| 1177 |
+
|
| 1178 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
|
| 1179 |
+
def get_output_embeddings(self):
|
| 1180 |
+
return self.lm_head
|
| 1181 |
+
|
| 1182 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
|
| 1183 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1184 |
+
self.lm_head = new_embeddings
|
| 1185 |
+
|
| 1186 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
|
| 1187 |
+
def set_decoder(self, decoder):
|
| 1188 |
+
self.model = decoder
|
| 1189 |
+
|
| 1190 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
|
| 1191 |
+
def get_decoder(self):
|
| 1192 |
+
return self.model
|
| 1193 |
+
|
| 1194 |
+
# Ignore copy
|
| 1195 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1196 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
| 1197 |
+
def forward(
|
| 1198 |
+
self,
|
| 1199 |
+
input_ids: torch.LongTensor = None,
|
| 1200 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1201 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1202 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1203 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1204 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1205 |
+
use_cache: Optional[bool] = None,
|
| 1206 |
+
output_attentions: Optional[bool] = None,
|
| 1207 |
+
output_hidden_states: Optional[bool] = None,
|
| 1208 |
+
return_dict: Optional[bool] = None,
|
| 1209 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1210 |
+
r"""
|
| 1211 |
+
Args:
|
| 1212 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1213 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1214 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1215 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1216 |
+
|
| 1217 |
+
Returns:
|
| 1218 |
+
|
| 1219 |
+
Example:
|
| 1220 |
+
|
| 1221 |
+
```python
|
| 1222 |
+
>>> from transformers import AutoTokenizer, Phi3ForCausalLM
|
| 1223 |
+
|
| 1224 |
+
>>> model = Phi3ForCausalLM.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1225 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
| 1226 |
+
|
| 1227 |
+
>>> prompt = "This is an example script ."
|
| 1228 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 1229 |
+
|
| 1230 |
+
>>> # Generate
|
| 1231 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 1232 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1233 |
+
'This is an example script .\n Certainly! Below is a sample script that demonstrates a simple task, such as calculating the sum'
|
| 1234 |
+
```"""
|
| 1235 |
+
|
| 1236 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1237 |
+
output_hidden_states = (
|
| 1238 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1239 |
+
)
|
| 1240 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1241 |
+
|
| 1242 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1243 |
+
outputs = self.model(
|
| 1244 |
+
input_ids=input_ids,
|
| 1245 |
+
attention_mask=attention_mask,
|
| 1246 |
+
position_ids=position_ids,
|
| 1247 |
+
past_key_values=past_key_values,
|
| 1248 |
+
inputs_embeds=inputs_embeds,
|
| 1249 |
+
use_cache=use_cache,
|
| 1250 |
+
output_attentions=output_attentions,
|
| 1251 |
+
output_hidden_states=output_hidden_states,
|
| 1252 |
+
return_dict=return_dict,
|
| 1253 |
+
)
|
| 1254 |
+
|
| 1255 |
+
hidden_states = outputs[0]
|
| 1256 |
+
logits = self.lm_head(hidden_states)
|
| 1257 |
+
logits = logits.float()
|
| 1258 |
+
|
| 1259 |
+
loss = None
|
| 1260 |
+
if labels is not None:
|
| 1261 |
+
# Shift so that tokens < n predict n
|
| 1262 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 1263 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 1264 |
+
# Flatten the tokens
|
| 1265 |
+
loss_fct = CrossEntropyLoss()
|
| 1266 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
| 1267 |
+
shift_labels = shift_labels.view(-1)
|
| 1268 |
+
# Enable model parallelism
|
| 1269 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
| 1270 |
+
loss = loss_fct(shift_logits, shift_labels)
|
| 1271 |
+
|
| 1272 |
+
if not return_dict:
|
| 1273 |
+
output = (logits,) + outputs[1:]
|
| 1274 |
+
return (loss,) + output if loss is not None else output
|
| 1275 |
+
|
| 1276 |
+
return CausalLMOutputWithPast(
|
| 1277 |
+
loss=loss,
|
| 1278 |
+
logits=logits,
|
| 1279 |
+
past_key_values=outputs.past_key_values,
|
| 1280 |
+
hidden_states=outputs.hidden_states,
|
| 1281 |
+
attentions=outputs.attentions,
|
| 1282 |
+
)
|
| 1283 |
+
|
| 1284 |
+
# Copied from transformers.models.persimmon.modeling_persimmon.PersimmonForCausalLM.prepare_inputs_for_generation
|
| 1285 |
+
def prepare_inputs_for_generation(
|
| 1286 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
|
| 1287 |
+
):
|
| 1288 |
+
if past_key_values is not None:
|
| 1289 |
+
if isinstance(past_key_values, Cache):
|
| 1290 |
+
cache_length = past_key_values.get_seq_length()
|
| 1291 |
+
past_length = past_key_values.seen_tokens
|
| 1292 |
+
max_cache_length = past_key_values.get_max_length()
|
| 1293 |
+
else:
|
| 1294 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
| 1295 |
+
max_cache_length = None
|
| 1296 |
+
|
| 1297 |
+
# Keep only the unprocessed tokens:
|
| 1298 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
| 1299 |
+
# some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
|
| 1300 |
+
# input)
|
| 1301 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
| 1302 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
| 1303 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
| 1304 |
+
# input_ids based on the past_length.
|
| 1305 |
+
elif past_length < input_ids.shape[1]:
|
| 1306 |
+
input_ids = input_ids[:, past_length:]
|
| 1307 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
| 1308 |
+
|
| 1309 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
| 1310 |
+
if (
|
| 1311 |
+
max_cache_length is not None
|
| 1312 |
+
and attention_mask is not None
|
| 1313 |
+
and cache_length + input_ids.shape[1] > max_cache_length
|
| 1314 |
+
):
|
| 1315 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
| 1316 |
+
|
| 1317 |
+
position_ids = kwargs.get("position_ids", None)
|
| 1318 |
+
if attention_mask is not None and position_ids is None:
|
| 1319 |
+
# create position_ids on the fly for batch generation
|
| 1320 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 1321 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 1322 |
+
if past_key_values:
|
| 1323 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
| 1324 |
+
|
| 1325 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
| 1326 |
+
if inputs_embeds is not None and past_key_values is None:
|
| 1327 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
| 1328 |
+
else:
|
| 1329 |
+
model_inputs = {"input_ids": input_ids}
|
| 1330 |
+
|
| 1331 |
+
model_inputs.update(
|
| 1332 |
+
{
|
| 1333 |
+
"position_ids": position_ids,
|
| 1334 |
+
"past_key_values": past_key_values,
|
| 1335 |
+
"use_cache": kwargs.get("use_cache"),
|
| 1336 |
+
"attention_mask": attention_mask,
|
| 1337 |
+
}
|
| 1338 |
+
)
|
| 1339 |
+
return model_inputs
|
| 1340 |
+
|
| 1341 |
+
@staticmethod
|
| 1342 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
|
| 1343 |
+
def _reorder_cache(past_key_values, beam_idx):
|
| 1344 |
+
reordered_past = ()
|
| 1345 |
+
for layer_past in past_key_values:
|
| 1346 |
+
reordered_past += (
|
| 1347 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
| 1348 |
+
)
|
| 1349 |
+
return reordered_past
|
| 1350 |
+
|
| 1351 |
+
|
| 1352 |
+
@add_start_docstrings(
|
| 1353 |
+
"""
|
| 1354 |
+
The [`Phi3Model`] with a sequence classification head on top (linear layer).
|
| 1355 |
+
|
| 1356 |
+
[`Phi3ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
| 1357 |
+
(e.g. GPT-2) do.
|
| 1358 |
+
|
| 1359 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
| 1360 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
| 1361 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
| 1362 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
| 1363 |
+
each row of the batch).
|
| 1364 |
+
""",
|
| 1365 |
+
PHI3_START_DOCSTRING,
|
| 1366 |
+
)
|
| 1367 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->Phi3, LLAMA->PHI3, self.transformer->self.model, transformer_outputs->model_outputs
|
| 1368 |
+
class Phi3ForSequenceClassification(Phi3PreTrainedModel):
|
| 1369 |
+
def __init__(self, config):
|
| 1370 |
+
super().__init__(config)
|
| 1371 |
+
self.num_labels = config.num_labels
|
| 1372 |
+
self.model = Phi3Model(config)
|
| 1373 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
| 1374 |
+
|
| 1375 |
+
# Initialize weights and apply final processing
|
| 1376 |
+
self.post_init()
|
| 1377 |
+
|
| 1378 |
+
def get_input_embeddings(self):
|
| 1379 |
+
return self.model.embed_tokens
|
| 1380 |
+
|
| 1381 |
+
def set_input_embeddings(self, value):
|
| 1382 |
+
self.model.embed_tokens = value
|
| 1383 |
+
|
| 1384 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1385 |
+
def forward(
|
| 1386 |
+
self,
|
| 1387 |
+
input_ids: torch.LongTensor = None,
|
| 1388 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1389 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1390 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1391 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1392 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1393 |
+
use_cache: Optional[bool] = None,
|
| 1394 |
+
output_attentions: Optional[bool] = None,
|
| 1395 |
+
output_hidden_states: Optional[bool] = None,
|
| 1396 |
+
return_dict: Optional[bool] = None,
|
| 1397 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
| 1398 |
+
r"""
|
| 1399 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1400 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1401 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1402 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1403 |
+
"""
|
| 1404 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1405 |
+
|
| 1406 |
+
model_outputs = self.model(
|
| 1407 |
+
input_ids,
|
| 1408 |
+
attention_mask=attention_mask,
|
| 1409 |
+
position_ids=position_ids,
|
| 1410 |
+
past_key_values=past_key_values,
|
| 1411 |
+
inputs_embeds=inputs_embeds,
|
| 1412 |
+
use_cache=use_cache,
|
| 1413 |
+
output_attentions=output_attentions,
|
| 1414 |
+
output_hidden_states=output_hidden_states,
|
| 1415 |
+
return_dict=return_dict,
|
| 1416 |
+
)
|
| 1417 |
+
hidden_states = model_outputs[0]
|
| 1418 |
+
logits = self.score(hidden_states)
|
| 1419 |
+
|
| 1420 |
+
if input_ids is not None:
|
| 1421 |
+
batch_size = input_ids.shape[0]
|
| 1422 |
+
else:
|
| 1423 |
+
batch_size = inputs_embeds.shape[0]
|
| 1424 |
+
|
| 1425 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
| 1426 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
| 1427 |
+
if self.config.pad_token_id is None:
|
| 1428 |
+
sequence_lengths = -1
|
| 1429 |
+
else:
|
| 1430 |
+
if input_ids is not None:
|
| 1431 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
| 1432 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
| 1433 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
| 1434 |
+
sequence_lengths = sequence_lengths.to(logits.device)
|
| 1435 |
+
else:
|
| 1436 |
+
sequence_lengths = -1
|
| 1437 |
+
|
| 1438 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
| 1439 |
+
|
| 1440 |
+
loss = None
|
| 1441 |
+
if labels is not None:
|
| 1442 |
+
labels = labels.to(logits.device)
|
| 1443 |
+
if self.config.problem_type is None:
|
| 1444 |
+
if self.num_labels == 1:
|
| 1445 |
+
self.config.problem_type = "regression"
|
| 1446 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 1447 |
+
self.config.problem_type = "single_label_classification"
|
| 1448 |
+
else:
|
| 1449 |
+
self.config.problem_type = "multi_label_classification"
|
| 1450 |
+
|
| 1451 |
+
if self.config.problem_type == "regression":
|
| 1452 |
+
loss_fct = MSELoss()
|
| 1453 |
+
if self.num_labels == 1:
|
| 1454 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
| 1455 |
+
else:
|
| 1456 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1457 |
+
elif self.config.problem_type == "single_label_classification":
|
| 1458 |
+
loss_fct = CrossEntropyLoss()
|
| 1459 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
| 1460 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 1461 |
+
loss_fct = BCEWithLogitsLoss()
|
| 1462 |
+
loss = loss_fct(pooled_logits, labels)
|
| 1463 |
+
if not return_dict:
|
| 1464 |
+
output = (pooled_logits,) + model_outputs[1:]
|
| 1465 |
+
return ((loss,) + output) if loss is not None else output
|
| 1466 |
+
|
| 1467 |
+
return SequenceClassifierOutputWithPast(
|
| 1468 |
+
loss=loss,
|
| 1469 |
+
logits=pooled_logits,
|
| 1470 |
+
past_key_values=model_outputs.past_key_values,
|
| 1471 |
+
hidden_states=model_outputs.hidden_states,
|
| 1472 |
+
attentions=model_outputs.attentions,
|
| 1473 |
+
)
|
| 1474 |
+
|
| 1475 |
+
|
| 1476 |
+
@add_start_docstrings(
|
| 1477 |
+
"""
|
| 1478 |
+
[`Phi3Model`] with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
|
| 1479 |
+
Named-Entity-Recognition (NER) tasks.
|
| 1480 |
+
""",
|
| 1481 |
+
PHI3_START_DOCSTRING,
|
| 1482 |
+
)
|
| 1483 |
+
# Copied from transformers.models.mpt.modeling_mpt.MptForTokenClassification with Mpt->Phi3,MPT->PHI3,self.transformer->self.model,transformer_outputs->model_outputs
|
| 1484 |
+
class Phi3ForTokenClassification(Phi3PreTrainedModel):
|
| 1485 |
+
def __init__(self, config: Phi3Config):
|
| 1486 |
+
super().__init__(config)
|
| 1487 |
+
self.num_labels = config.num_labels
|
| 1488 |
+
|
| 1489 |
+
self.model = Phi3Model(config)
|
| 1490 |
+
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
|
| 1491 |
+
classifier_dropout = config.classifier_dropout
|
| 1492 |
+
elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
|
| 1493 |
+
classifier_dropout = config.hidden_dropout
|
| 1494 |
+
else:
|
| 1495 |
+
classifier_dropout = 0.1
|
| 1496 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
| 1497 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
| 1498 |
+
|
| 1499 |
+
# Initialize weights and apply final processing
|
| 1500 |
+
self.post_init()
|
| 1501 |
+
|
| 1502 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1503 |
+
@add_code_sample_docstrings(
|
| 1504 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 1505 |
+
output_type=TokenClassifierOutput,
|
| 1506 |
+
config_class=_CONFIG_FOR_DOC,
|
| 1507 |
+
)
|
| 1508 |
+
def forward(
|
| 1509 |
+
self,
|
| 1510 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1511 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
| 1512 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1513 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 1514 |
+
labels: Optional[torch.Tensor] = None,
|
| 1515 |
+
use_cache: Optional[bool] = None,
|
| 1516 |
+
output_attentions: Optional[bool] = None,
|
| 1517 |
+
output_hidden_states: Optional[bool] = None,
|
| 1518 |
+
return_dict: Optional[bool] = None,
|
| 1519 |
+
**deprecated_arguments,
|
| 1520 |
+
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
| 1521 |
+
r"""
|
| 1522 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1523 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1524 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1525 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1526 |
+
"""
|
| 1527 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1528 |
+
|
| 1529 |
+
model_outputs = self.model(
|
| 1530 |
+
input_ids,
|
| 1531 |
+
past_key_values=past_key_values,
|
| 1532 |
+
attention_mask=attention_mask,
|
| 1533 |
+
inputs_embeds=inputs_embeds,
|
| 1534 |
+
use_cache=use_cache,
|
| 1535 |
+
output_attentions=output_attentions,
|
| 1536 |
+
output_hidden_states=output_hidden_states,
|
| 1537 |
+
return_dict=return_dict,
|
| 1538 |
+
)
|
| 1539 |
+
|
| 1540 |
+
hidden_states = model_outputs[0]
|
| 1541 |
+
hidden_states = self.dropout(hidden_states)
|
| 1542 |
+
logits = self.classifier(hidden_states)
|
| 1543 |
+
|
| 1544 |
+
loss = None
|
| 1545 |
+
if labels is not None:
|
| 1546 |
+
# move labels to correct device to enable model parallelism
|
| 1547 |
+
labels = labels.to(logits.device)
|
| 1548 |
+
batch_size, seq_length = labels.shape
|
| 1549 |
+
loss_fct = CrossEntropyLoss()
|
| 1550 |
+
loss = loss_fct(
|
| 1551 |
+
logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length)
|
| 1552 |
+
)
|
| 1553 |
+
|
| 1554 |
+
if not return_dict:
|
| 1555 |
+
output = (logits,) + model_outputs[2:]
|
| 1556 |
+
return ((loss,) + output) if loss is not None else output
|
| 1557 |
+
|
| 1558 |
+
return TokenClassifierOutput(
|
| 1559 |
+
loss=loss,
|
| 1560 |
+
logits=logits,
|
| 1561 |
+
hidden_states=model_outputs.hidden_states,
|
| 1562 |
+
attentions=model_outputs.attentions,
|
| 1563 |
+
)
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/raw_datasets.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a4cc2a439adc3f4f47d2ee804824bffe82a76e092955fec5939dabab4892362
|
| 3 |
+
size 12934939
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|endoftext|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|endoftext|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "<unk>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/tokenizer_config.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": null,
|
| 5 |
+
"added_tokens_decoder": {
|
| 6 |
+
"0": {
|
| 7 |
+
"content": "<unk>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false,
|
| 12 |
+
"special": true
|
| 13 |
+
},
|
| 14 |
+
"1": {
|
| 15 |
+
"content": "<s>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": false,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false,
|
| 20 |
+
"special": true
|
| 21 |
+
},
|
| 22 |
+
"2": {
|
| 23 |
+
"content": "</s>",
|
| 24 |
+
"lstrip": false,
|
| 25 |
+
"normalized": false,
|
| 26 |
+
"rstrip": true,
|
| 27 |
+
"single_word": false,
|
| 28 |
+
"special": false
|
| 29 |
+
},
|
| 30 |
+
"32000": {
|
| 31 |
+
"content": "<|endoftext|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false,
|
| 36 |
+
"special": true
|
| 37 |
+
},
|
| 38 |
+
"32001": {
|
| 39 |
+
"content": "<|assistant|>",
|
| 40 |
+
"lstrip": false,
|
| 41 |
+
"normalized": false,
|
| 42 |
+
"rstrip": true,
|
| 43 |
+
"single_word": false,
|
| 44 |
+
"special": true
|
| 45 |
+
},
|
| 46 |
+
"32002": {
|
| 47 |
+
"content": "<|placeholder1|>",
|
| 48 |
+
"lstrip": false,
|
| 49 |
+
"normalized": false,
|
| 50 |
+
"rstrip": true,
|
| 51 |
+
"single_word": false,
|
| 52 |
+
"special": true
|
| 53 |
+
},
|
| 54 |
+
"32003": {
|
| 55 |
+
"content": "<|placeholder2|>",
|
| 56 |
+
"lstrip": false,
|
| 57 |
+
"normalized": false,
|
| 58 |
+
"rstrip": true,
|
| 59 |
+
"single_word": false,
|
| 60 |
+
"special": true
|
| 61 |
+
},
|
| 62 |
+
"32004": {
|
| 63 |
+
"content": "<|placeholder3|>",
|
| 64 |
+
"lstrip": false,
|
| 65 |
+
"normalized": false,
|
| 66 |
+
"rstrip": true,
|
| 67 |
+
"single_word": false,
|
| 68 |
+
"special": true
|
| 69 |
+
},
|
| 70 |
+
"32005": {
|
| 71 |
+
"content": "<|placeholder4|>",
|
| 72 |
+
"lstrip": false,
|
| 73 |
+
"normalized": false,
|
| 74 |
+
"rstrip": true,
|
| 75 |
+
"single_word": false,
|
| 76 |
+
"special": true
|
| 77 |
+
},
|
| 78 |
+
"32006": {
|
| 79 |
+
"content": "<|system|>",
|
| 80 |
+
"lstrip": false,
|
| 81 |
+
"normalized": false,
|
| 82 |
+
"rstrip": true,
|
| 83 |
+
"single_word": false,
|
| 84 |
+
"special": true
|
| 85 |
+
},
|
| 86 |
+
"32007": {
|
| 87 |
+
"content": "<|end|>",
|
| 88 |
+
"lstrip": false,
|
| 89 |
+
"normalized": false,
|
| 90 |
+
"rstrip": true,
|
| 91 |
+
"single_word": false,
|
| 92 |
+
"special": true
|
| 93 |
+
},
|
| 94 |
+
"32008": {
|
| 95 |
+
"content": "<|placeholder5|>",
|
| 96 |
+
"lstrip": false,
|
| 97 |
+
"normalized": false,
|
| 98 |
+
"rstrip": true,
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"special": true
|
| 101 |
+
},
|
| 102 |
+
"32009": {
|
| 103 |
+
"content": "<|placeholder6|>",
|
| 104 |
+
"lstrip": false,
|
| 105 |
+
"normalized": false,
|
| 106 |
+
"rstrip": true,
|
| 107 |
+
"single_word": false,
|
| 108 |
+
"special": true
|
| 109 |
+
},
|
| 110 |
+
"32010": {
|
| 111 |
+
"content": "<|user|>",
|
| 112 |
+
"lstrip": false,
|
| 113 |
+
"normalized": false,
|
| 114 |
+
"rstrip": true,
|
| 115 |
+
"single_word": false,
|
| 116 |
+
"special": true
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
"bos_token": "<s>",
|
| 120 |
+
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
|
| 121 |
+
"clean_up_tokenization_spaces": false,
|
| 122 |
+
"eos_token": "<|endoftext|>",
|
| 123 |
+
"legacy": false,
|
| 124 |
+
"model_max_length": 4096,
|
| 125 |
+
"pad_token": "<|endoftext|>",
|
| 126 |
+
"padding_side": "left",
|
| 127 |
+
"sp_model_kwargs": {},
|
| 128 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 129 |
+
"unk_token": "<unk>",
|
| 130 |
+
"use_default_system_prompt": false
|
| 131 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/train_results.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epoch": 0.9880609304240429,
|
| 3 |
+
"total_flos": 0.0,
|
| 4 |
+
"train_loss": 1230.5828483072917,
|
| 5 |
+
"train_runtime": 5273.3776,
|
| 6 |
+
"train_samples": 9715,
|
| 7 |
+
"train_samples_per_second": 1.842,
|
| 8 |
+
"train_steps_per_second": 0.014
|
| 9 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/trainer_state.json
ADDED
|
@@ -0,0 +1,1392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"best_metric": null,
|
| 3 |
+
"best_model_checkpoint": null,
|
| 4 |
+
"epoch": 0.9880609304240429,
|
| 5 |
+
"eval_steps": 500,
|
| 6 |
+
"global_step": 75,
|
| 7 |
+
"is_hyper_param_search": false,
|
| 8 |
+
"is_local_process_zero": true,
|
| 9 |
+
"is_world_process_zero": true,
|
| 10 |
+
"log_history": [
|
| 11 |
+
{
|
| 12 |
+
"epoch": 0.013174145738987238,
|
| 13 |
+
"grad_norm": 11939.8896484375,
|
| 14 |
+
"learning_rate": 6.25e-08,
|
| 15 |
+
"logits/chosen": 9.27954387664795,
|
| 16 |
+
"logits/rejected": 10.301474571228027,
|
| 17 |
+
"logps/chosen": -161.34732055664062,
|
| 18 |
+
"logps/ref_chosen": -161.52735900878906,
|
| 19 |
+
"logps/ref_rejected": -190.59146118164062,
|
| 20 |
+
"logps/rejected": -190.26283264160156,
|
| 21 |
+
"loss": 1259.9509,
|
| 22 |
+
"rewards/accuracies": 0.4609375,
|
| 23 |
+
"rewards/chosen": 0.0018004311714321375,
|
| 24 |
+
"rewards/margins": -0.0014860763913020492,
|
| 25 |
+
"rewards/rejected": 0.003286507213488221,
|
| 26 |
+
"sft_loss": 0.6015501618385315,
|
| 27 |
+
"step": 1
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"epoch": 0.026348291477974475,
|
| 31 |
+
"grad_norm": 20344.087890625,
|
| 32 |
+
"learning_rate": 1.25e-07,
|
| 33 |
+
"logits/chosen": 9.765436172485352,
|
| 34 |
+
"logits/rejected": 10.689525604248047,
|
| 35 |
+
"logps/chosen": -164.2713165283203,
|
| 36 |
+
"logps/ref_chosen": -164.53343200683594,
|
| 37 |
+
"logps/ref_rejected": -188.484130859375,
|
| 38 |
+
"logps/rejected": -188.30909729003906,
|
| 39 |
+
"loss": 1248.7765,
|
| 40 |
+
"rewards/accuracies": 0.5234375,
|
| 41 |
+
"rewards/chosen": 0.00262093055061996,
|
| 42 |
+
"rewards/margins": 0.0008707434753887355,
|
| 43 |
+
"rewards/rejected": 0.0017501871334388852,
|
| 44 |
+
"sft_loss": 0.5960816144943237,
|
| 45 |
+
"step": 2
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"epoch": 0.03952243721696171,
|
| 49 |
+
"grad_norm": 6221.47119140625,
|
| 50 |
+
"learning_rate": 1.875e-07,
|
| 51 |
+
"logits/chosen": 8.722786903381348,
|
| 52 |
+
"logits/rejected": 9.743849754333496,
|
| 53 |
+
"logps/chosen": -162.63465881347656,
|
| 54 |
+
"logps/ref_chosen": -163.49111938476562,
|
| 55 |
+
"logps/ref_rejected": -183.71487426757812,
|
| 56 |
+
"logps/rejected": -183.04043579101562,
|
| 57 |
+
"loss": 1243.4164,
|
| 58 |
+
"rewards/accuracies": 0.53125,
|
| 59 |
+
"rewards/chosen": 0.00856476929038763,
|
| 60 |
+
"rewards/margins": 0.0018203993095085025,
|
| 61 |
+
"rewards/rejected": 0.006744369864463806,
|
| 62 |
+
"sft_loss": 0.642219066619873,
|
| 63 |
+
"step": 3
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"epoch": 0.05269658295594895,
|
| 67 |
+
"grad_norm": 7613.75634765625,
|
| 68 |
+
"learning_rate": 2.5e-07,
|
| 69 |
+
"logits/chosen": 9.025806427001953,
|
| 70 |
+
"logits/rejected": 9.838699340820312,
|
| 71 |
+
"logps/chosen": -162.43136596679688,
|
| 72 |
+
"logps/ref_chosen": -163.0717315673828,
|
| 73 |
+
"logps/ref_rejected": -189.73365783691406,
|
| 74 |
+
"logps/rejected": -189.1153106689453,
|
| 75 |
+
"loss": 1251.6774,
|
| 76 |
+
"rewards/accuracies": 0.46875,
|
| 77 |
+
"rewards/chosen": 0.006403667386621237,
|
| 78 |
+
"rewards/margins": 0.0002202361501986161,
|
| 79 |
+
"rewards/rejected": 0.006183430552482605,
|
| 80 |
+
"sft_loss": 0.6199619770050049,
|
| 81 |
+
"step": 4
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"epoch": 0.06587072869493618,
|
| 85 |
+
"grad_norm": 10397.734375,
|
| 86 |
+
"learning_rate": 3.1249999999999997e-07,
|
| 87 |
+
"logits/chosen": 8.854580879211426,
|
| 88 |
+
"logits/rejected": 9.520020484924316,
|
| 89 |
+
"logps/chosen": -166.08847045898438,
|
| 90 |
+
"logps/ref_chosen": -166.2326202392578,
|
| 91 |
+
"logps/ref_rejected": -182.56619262695312,
|
| 92 |
+
"logps/rejected": -182.27041625976562,
|
| 93 |
+
"loss": 1260.8861,
|
| 94 |
+
"rewards/accuracies": 0.515625,
|
| 95 |
+
"rewards/chosen": 0.0014414649922400713,
|
| 96 |
+
"rewards/margins": -0.001516252988949418,
|
| 97 |
+
"rewards/rejected": 0.0029577179811894894,
|
| 98 |
+
"sft_loss": 0.6663774847984314,
|
| 99 |
+
"step": 5
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"epoch": 0.07904487443392343,
|
| 103 |
+
"grad_norm": 8530.9384765625,
|
| 104 |
+
"learning_rate": 3.75e-07,
|
| 105 |
+
"logits/chosen": 9.753662109375,
|
| 106 |
+
"logits/rejected": 10.468301773071289,
|
| 107 |
+
"logps/chosen": -157.6840057373047,
|
| 108 |
+
"logps/ref_chosen": -158.3181610107422,
|
| 109 |
+
"logps/ref_rejected": -185.65223693847656,
|
| 110 |
+
"logps/rejected": -184.92295837402344,
|
| 111 |
+
"loss": 1257.1482,
|
| 112 |
+
"rewards/accuracies": 0.484375,
|
| 113 |
+
"rewards/chosen": 0.006341630592942238,
|
| 114 |
+
"rewards/margins": -0.0009508662624284625,
|
| 115 |
+
"rewards/rejected": 0.007292496040463448,
|
| 116 |
+
"sft_loss": 0.5698487758636475,
|
| 117 |
+
"step": 6
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
"epoch": 0.09221902017291066,
|
| 121 |
+
"grad_norm": 9378.39453125,
|
| 122 |
+
"learning_rate": 4.375e-07,
|
| 123 |
+
"logits/chosen": 9.470847129821777,
|
| 124 |
+
"logits/rejected": 10.44430160522461,
|
| 125 |
+
"logps/chosen": -160.36924743652344,
|
| 126 |
+
"logps/ref_chosen": -160.5563507080078,
|
| 127 |
+
"logps/ref_rejected": -185.69711303710938,
|
| 128 |
+
"logps/rejected": -185.29351806640625,
|
| 129 |
+
"loss": 1264.8387,
|
| 130 |
+
"rewards/accuracies": 0.4375,
|
| 131 |
+
"rewards/chosen": 0.0018710402073338628,
|
| 132 |
+
"rewards/margins": -0.0021651287097483873,
|
| 133 |
+
"rewards/rejected": 0.004036169499158859,
|
| 134 |
+
"sft_loss": 0.631588876247406,
|
| 135 |
+
"step": 7
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"epoch": 0.1053931659118979,
|
| 139 |
+
"grad_norm": 9694.0546875,
|
| 140 |
+
"learning_rate": 5e-07,
|
| 141 |
+
"logits/chosen": 9.460095405578613,
|
| 142 |
+
"logits/rejected": 10.253154754638672,
|
| 143 |
+
"logps/chosen": -161.80702209472656,
|
| 144 |
+
"logps/ref_chosen": -162.4405975341797,
|
| 145 |
+
"logps/ref_rejected": -181.48187255859375,
|
| 146 |
+
"logps/rejected": -180.77980041503906,
|
| 147 |
+
"loss": 1256.3765,
|
| 148 |
+
"rewards/accuracies": 0.5,
|
| 149 |
+
"rewards/chosen": 0.006335556041449308,
|
| 150 |
+
"rewards/margins": -0.0006850429344922304,
|
| 151 |
+
"rewards/rejected": 0.007020598277449608,
|
| 152 |
+
"sft_loss": 0.614635705947876,
|
| 153 |
+
"step": 8
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"epoch": 0.11856731165088513,
|
| 157 |
+
"grad_norm": 8749.8173828125,
|
| 158 |
+
"learning_rate": 4.997252228714278e-07,
|
| 159 |
+
"logits/chosen": 9.16610336303711,
|
| 160 |
+
"logits/rejected": 10.042960166931152,
|
| 161 |
+
"logps/chosen": -165.7333526611328,
|
| 162 |
+
"logps/ref_chosen": -165.9727325439453,
|
| 163 |
+
"logps/ref_rejected": -187.9524383544922,
|
| 164 |
+
"logps/rejected": -187.82272338867188,
|
| 165 |
+
"loss": 1247.1034,
|
| 166 |
+
"rewards/accuracies": 0.5078125,
|
| 167 |
+
"rewards/chosen": 0.0023937043733894825,
|
| 168 |
+
"rewards/margins": 0.0010966688860207796,
|
| 169 |
+
"rewards/rejected": 0.0012970359530299902,
|
| 170 |
+
"sft_loss": 0.6524200439453125,
|
| 171 |
+
"step": 9
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"epoch": 0.13174145738987236,
|
| 175 |
+
"grad_norm": 11097.1748046875,
|
| 176 |
+
"learning_rate": 4.989014955054745e-07,
|
| 177 |
+
"logits/chosen": 9.420584678649902,
|
| 178 |
+
"logits/rejected": 10.417539596557617,
|
| 179 |
+
"logps/chosen": -161.01123046875,
|
| 180 |
+
"logps/ref_chosen": -161.3177947998047,
|
| 181 |
+
"logps/ref_rejected": -181.80029296875,
|
| 182 |
+
"logps/rejected": -181.364013671875,
|
| 183 |
+
"loss": 1260.5314,
|
| 184 |
+
"rewards/accuracies": 0.46875,
|
| 185 |
+
"rewards/chosen": 0.0030655961018055677,
|
| 186 |
+
"rewards/margins": -0.0012973196571692824,
|
| 187 |
+
"rewards/rejected": 0.004362916108220816,
|
| 188 |
+
"sft_loss": 0.6595594882965088,
|
| 189 |
+
"step": 10
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"epoch": 0.14491560312885962,
|
| 193 |
+
"grad_norm": 7027.30029296875,
|
| 194 |
+
"learning_rate": 4.975306286336627e-07,
|
| 195 |
+
"logits/chosen": 9.721382141113281,
|
| 196 |
+
"logits/rejected": 10.780956268310547,
|
| 197 |
+
"logps/chosen": -159.7593231201172,
|
| 198 |
+
"logps/ref_chosen": -159.81565856933594,
|
| 199 |
+
"logps/ref_rejected": -189.1248016357422,
|
| 200 |
+
"logps/rejected": -188.8058624267578,
|
| 201 |
+
"loss": 1266.6455,
|
| 202 |
+
"rewards/accuracies": 0.4765625,
|
| 203 |
+
"rewards/chosen": 0.0005634452099911869,
|
| 204 |
+
"rewards/margins": -0.0026260039303451777,
|
| 205 |
+
"rewards/rejected": 0.0031894489657133818,
|
| 206 |
+
"sft_loss": 0.6141334176063538,
|
| 207 |
+
"step": 11
|
| 208 |
+
},
|
| 209 |
+
{
|
| 210 |
+
"epoch": 0.15808974886784685,
|
| 211 |
+
"grad_norm": 22993.36328125,
|
| 212 |
+
"learning_rate": 4.956156357188939e-07,
|
| 213 |
+
"logits/chosen": 9.151805877685547,
|
| 214 |
+
"logits/rejected": 9.882065773010254,
|
| 215 |
+
"logps/chosen": -159.84539794921875,
|
| 216 |
+
"logps/ref_chosen": -160.15347290039062,
|
| 217 |
+
"logps/ref_rejected": -191.22238159179688,
|
| 218 |
+
"logps/rejected": -191.2176055908203,
|
| 219 |
+
"loss": 1238.6112,
|
| 220 |
+
"rewards/accuracies": 0.5546875,
|
| 221 |
+
"rewards/chosen": 0.0030807997100055218,
|
| 222 |
+
"rewards/margins": 0.0030331455636769533,
|
| 223 |
+
"rewards/rejected": 4.765485937241465e-05,
|
| 224 |
+
"sft_loss": 0.6379200220108032,
|
| 225 |
+
"step": 12
|
| 226 |
+
},
|
| 227 |
+
{
|
| 228 |
+
"epoch": 0.17126389460683408,
|
| 229 |
+
"grad_norm": 10643.3564453125,
|
| 230 |
+
"learning_rate": 4.931607263312032e-07,
|
| 231 |
+
"logits/chosen": 9.09386157989502,
|
| 232 |
+
"logits/rejected": 9.785795211791992,
|
| 233 |
+
"logps/chosen": -165.81480407714844,
|
| 234 |
+
"logps/ref_chosen": -165.79559326171875,
|
| 235 |
+
"logps/ref_rejected": -185.6336669921875,
|
| 236 |
+
"logps/rejected": -185.7548370361328,
|
| 237 |
+
"loss": 1248.0265,
|
| 238 |
+
"rewards/accuracies": 0.5234375,
|
| 239 |
+
"rewards/chosen": -0.0001921286020660773,
|
| 240 |
+
"rewards/margins": 0.0010195113718509674,
|
| 241 |
+
"rewards/rejected": -0.0012116394937038422,
|
| 242 |
+
"sft_loss": 0.6628710031509399,
|
| 243 |
+
"step": 13
|
| 244 |
+
},
|
| 245 |
+
{
|
| 246 |
+
"epoch": 0.1844380403458213,
|
| 247 |
+
"grad_norm": 11797.5498046875,
|
| 248 |
+
"learning_rate": 4.9017129689421e-07,
|
| 249 |
+
"logits/chosen": 9.531899452209473,
|
| 250 |
+
"logits/rejected": 10.222368240356445,
|
| 251 |
+
"logps/chosen": -159.93820190429688,
|
| 252 |
+
"logps/ref_chosen": -159.34759521484375,
|
| 253 |
+
"logps/ref_rejected": -186.56344604492188,
|
| 254 |
+
"logps/rejected": -187.07980346679688,
|
| 255 |
+
"loss": 1256.9276,
|
| 256 |
+
"rewards/accuracies": 0.4921875,
|
| 257 |
+
"rewards/chosen": -0.0059059178456664085,
|
| 258 |
+
"rewards/margins": -0.0007423177594318986,
|
| 259 |
+
"rewards/rejected": -0.005163600668311119,
|
| 260 |
+
"sft_loss": 0.6098232269287109,
|
| 261 |
+
"step": 14
|
| 262 |
+
},
|
| 263 |
+
{
|
| 264 |
+
"epoch": 0.19761218608480857,
|
| 265 |
+
"grad_norm": 21703.580078125,
|
| 266 |
+
"learning_rate": 4.866539188226085e-07,
|
| 267 |
+
"logits/chosen": 9.498268127441406,
|
| 268 |
+
"logits/rejected": 10.17479133605957,
|
| 269 |
+
"logps/chosen": -157.2238311767578,
|
| 270 |
+
"logps/ref_chosen": -156.9163818359375,
|
| 271 |
+
"logps/ref_rejected": -180.94204711914062,
|
| 272 |
+
"logps/rejected": -181.5419158935547,
|
| 273 |
+
"loss": 1238.6174,
|
| 274 |
+
"rewards/accuracies": 0.546875,
|
| 275 |
+
"rewards/chosen": -0.0030744271352887154,
|
| 276 |
+
"rewards/margins": 0.0029243535827845335,
|
| 277 |
+
"rewards/rejected": -0.005998780485242605,
|
| 278 |
+
"sft_loss": 0.6005505323410034,
|
| 279 |
+
"step": 15
|
| 280 |
+
},
|
| 281 |
+
{
|
| 282 |
+
"epoch": 0.2107863318237958,
|
| 283 |
+
"grad_norm": 14315.80859375,
|
| 284 |
+
"learning_rate": 4.826163240767716e-07,
|
| 285 |
+
"logits/chosen": 9.243983268737793,
|
| 286 |
+
"logits/rejected": 10.31888484954834,
|
| 287 |
+
"logps/chosen": -160.37767028808594,
|
| 288 |
+
"logps/ref_chosen": -160.31900024414062,
|
| 289 |
+
"logps/ref_rejected": -185.30758666992188,
|
| 290 |
+
"logps/rejected": -185.46327209472656,
|
| 291 |
+
"loss": 1248.0226,
|
| 292 |
+
"rewards/accuracies": 0.5078125,
|
| 293 |
+
"rewards/chosen": -0.0005864841514267027,
|
| 294 |
+
"rewards/margins": 0.0009703537216410041,
|
| 295 |
+
"rewards/rejected": -0.0015568381641060114,
|
| 296 |
+
"sft_loss": 0.6171885132789612,
|
| 297 |
+
"step": 16
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"epoch": 0.22396047756278303,
|
| 301 |
+
"grad_norm": 13537.552734375,
|
| 302 |
+
"learning_rate": 4.780673881662242e-07,
|
| 303 |
+
"logits/chosen": 9.278010368347168,
|
| 304 |
+
"logits/rejected": 10.344183921813965,
|
| 305 |
+
"logps/chosen": -157.81365966796875,
|
| 306 |
+
"logps/ref_chosen": -157.49974060058594,
|
| 307 |
+
"logps/ref_rejected": -182.99058532714844,
|
| 308 |
+
"logps/rejected": -183.23016357421875,
|
| 309 |
+
"loss": 1256.5798,
|
| 310 |
+
"rewards/accuracies": 0.453125,
|
| 311 |
+
"rewards/chosen": -0.0031392467208206654,
|
| 312 |
+
"rewards/margins": -0.0007435214356519282,
|
| 313 |
+
"rewards/rejected": -0.002395725343376398,
|
| 314 |
+
"sft_loss": 0.5762492418289185,
|
| 315 |
+
"step": 17
|
| 316 |
+
},
|
| 317 |
+
{
|
| 318 |
+
"epoch": 0.23713462330177026,
|
| 319 |
+
"grad_norm": 13017.095703125,
|
| 320 |
+
"learning_rate": 4.730171106393466e-07,
|
| 321 |
+
"logits/chosen": 9.133981704711914,
|
| 322 |
+
"logits/rejected": 9.824861526489258,
|
| 323 |
+
"logps/chosen": -153.6888885498047,
|
| 324 |
+
"logps/ref_chosen": -153.23312377929688,
|
| 325 |
+
"logps/ref_rejected": -183.12954711914062,
|
| 326 |
+
"logps/rejected": -183.21145629882812,
|
| 327 |
+
"loss": 1273.2631,
|
| 328 |
+
"rewards/accuracies": 0.4765625,
|
| 329 |
+
"rewards/chosen": -0.004557757638394833,
|
| 330 |
+
"rewards/margins": -0.00373845174908638,
|
| 331 |
+
"rewards/rejected": -0.0008193061221390963,
|
| 332 |
+
"sft_loss": 0.5850743055343628,
|
| 333 |
+
"step": 18
|
| 334 |
+
},
|
| 335 |
+
{
|
| 336 |
+
"epoch": 0.2503087690407575,
|
| 337 |
+
"grad_norm": 17268.939453125,
|
| 338 |
+
"learning_rate": 4.6747659310219757e-07,
|
| 339 |
+
"logits/chosen": 9.301076889038086,
|
| 340 |
+
"logits/rejected": 10.111696243286133,
|
| 341 |
+
"logps/chosen": -171.1327362060547,
|
| 342 |
+
"logps/ref_chosen": -170.62677001953125,
|
| 343 |
+
"logps/ref_rejected": -198.92384338378906,
|
| 344 |
+
"logps/rejected": -199.73281860351562,
|
| 345 |
+
"loss": 1238.2084,
|
| 346 |
+
"rewards/accuracies": 0.53125,
|
| 347 |
+
"rewards/chosen": -0.005059816408902407,
|
| 348 |
+
"rewards/margins": 0.0030298822093755007,
|
| 349 |
+
"rewards/rejected": -0.008089697919785976,
|
| 350 |
+
"sft_loss": 0.624207615852356,
|
| 351 |
+
"step": 19
|
| 352 |
+
},
|
| 353 |
+
{
|
| 354 |
+
"epoch": 0.2634829147797447,
|
| 355 |
+
"grad_norm": 12483.8447265625,
|
| 356 |
+
"learning_rate": 4.6145801481477433e-07,
|
| 357 |
+
"logits/chosen": 9.14182186126709,
|
| 358 |
+
"logits/rejected": 9.897723197937012,
|
| 359 |
+
"logps/chosen": -152.49996948242188,
|
| 360 |
+
"logps/ref_chosen": -151.864013671875,
|
| 361 |
+
"logps/ref_rejected": -175.61083984375,
|
| 362 |
+
"logps/rejected": -176.18045043945312,
|
| 363 |
+
"loss": 1257.0282,
|
| 364 |
+
"rewards/accuracies": 0.5,
|
| 365 |
+
"rewards/chosen": -0.006359598599374294,
|
| 366 |
+
"rewards/margins": -0.0006636814214289188,
|
| 367 |
+
"rewards/rejected": -0.005695916712284088,
|
| 368 |
+
"sft_loss": 0.5699771046638489,
|
| 369 |
+
"step": 20
|
| 370 |
+
},
|
| 371 |
+
{
|
| 372 |
+
"epoch": 0.276657060518732,
|
| 373 |
+
"grad_norm": 12172.302734375,
|
| 374 |
+
"learning_rate": 4.549746059183561e-07,
|
| 375 |
+
"logits/chosen": 9.389370918273926,
|
| 376 |
+
"logits/rejected": 10.136149406433105,
|
| 377 |
+
"logps/chosen": -160.95376586914062,
|
| 378 |
+
"logps/ref_chosen": -160.38229370117188,
|
| 379 |
+
"logps/ref_rejected": -185.16732788085938,
|
| 380 |
+
"logps/rejected": -185.6207275390625,
|
| 381 |
+
"loss": 1259.6079,
|
| 382 |
+
"rewards/accuracies": 0.4375,
|
| 383 |
+
"rewards/chosen": -0.00571476062759757,
|
| 384 |
+
"rewards/margins": -0.0011807349510490894,
|
| 385 |
+
"rewards/rejected": -0.004534025676548481,
|
| 386 |
+
"sft_loss": 0.6106109619140625,
|
| 387 |
+
"step": 21
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"epoch": 0.28983120625771924,
|
| 391 |
+
"grad_norm": 14392.4365234375,
|
| 392 |
+
"learning_rate": 4.480406183527823e-07,
|
| 393 |
+
"logits/chosen": 9.726140975952148,
|
| 394 |
+
"logits/rejected": 10.511590957641602,
|
| 395 |
+
"logps/chosen": -167.51393127441406,
|
| 396 |
+
"logps/ref_chosen": -166.97335815429688,
|
| 397 |
+
"logps/ref_rejected": -193.65878295898438,
|
| 398 |
+
"logps/rejected": -194.24249267578125,
|
| 399 |
+
"loss": 1250.8685,
|
| 400 |
+
"rewards/accuracies": 0.515625,
|
| 401 |
+
"rewards/chosen": -0.005405717995017767,
|
| 402 |
+
"rewards/margins": 0.00043158838525414467,
|
| 403 |
+
"rewards/rejected": -0.005837306380271912,
|
| 404 |
+
"sft_loss": 0.6629478931427002,
|
| 405 |
+
"step": 22
|
| 406 |
+
},
|
| 407 |
+
{
|
| 408 |
+
"epoch": 0.3030053519967065,
|
| 409 |
+
"grad_norm": 17345.865234375,
|
| 410 |
+
"learning_rate": 4.4067129452759546e-07,
|
| 411 |
+
"logits/chosen": 9.734469413757324,
|
| 412 |
+
"logits/rejected": 10.142983436584473,
|
| 413 |
+
"logps/chosen": -158.3580322265625,
|
| 414 |
+
"logps/ref_chosen": -157.59666442871094,
|
| 415 |
+
"logps/ref_rejected": -178.59503173828125,
|
| 416 |
+
"logps/rejected": -179.44894409179688,
|
| 417 |
+
"loss": 1250.2837,
|
| 418 |
+
"rewards/accuracies": 0.46875,
|
| 419 |
+
"rewards/chosen": -0.007613427005708218,
|
| 420 |
+
"rewards/margins": 0.0009257960482500494,
|
| 421 |
+
"rewards/rejected": -0.008539222180843353,
|
| 422 |
+
"sft_loss": 0.6249986290931702,
|
| 423 |
+
"step": 23
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"epoch": 0.3161794977356937,
|
| 427 |
+
"grad_norm": 13860.54296875,
|
| 428 |
+
"learning_rate": 4.3288283381591725e-07,
|
| 429 |
+
"logits/chosen": 9.957910537719727,
|
| 430 |
+
"logits/rejected": 10.54185962677002,
|
| 431 |
+
"logps/chosen": -158.1103515625,
|
| 432 |
+
"logps/ref_chosen": -157.57530212402344,
|
| 433 |
+
"logps/ref_rejected": -182.6050262451172,
|
| 434 |
+
"logps/rejected": -183.3163299560547,
|
| 435 |
+
"loss": 1245.6425,
|
| 436 |
+
"rewards/accuracies": 0.53125,
|
| 437 |
+
"rewards/chosen": -0.005350313615053892,
|
| 438 |
+
"rewards/margins": 0.0017627429915592074,
|
| 439 |
+
"rewards/rejected": -0.007113056257367134,
|
| 440 |
+
"sft_loss": 0.6099339723587036,
|
| 441 |
+
"step": 24
|
| 442 |
+
},
|
| 443 |
+
{
|
| 444 |
+
"epoch": 0.32935364347468093,
|
| 445 |
+
"grad_norm": 12080.79296875,
|
| 446 |
+
"learning_rate": 4.246923569447104e-07,
|
| 447 |
+
"logits/chosen": 9.259940147399902,
|
| 448 |
+
"logits/rejected": 9.521827697753906,
|
| 449 |
+
"logps/chosen": -161.6366729736328,
|
| 450 |
+
"logps/ref_chosen": -160.58885192871094,
|
| 451 |
+
"logps/ref_rejected": -179.36691284179688,
|
| 452 |
+
"logps/rejected": -180.2943115234375,
|
| 453 |
+
"loss": 1260.0498,
|
| 454 |
+
"rewards/accuracies": 0.484375,
|
| 455 |
+
"rewards/chosen": -0.010478039272129536,
|
| 456 |
+
"rewards/margins": -0.0012040096335113049,
|
| 457 |
+
"rewards/rejected": -0.009274028241634369,
|
| 458 |
+
"sft_loss": 0.5966856479644775,
|
| 459 |
+
"step": 25
|
| 460 |
+
},
|
| 461 |
+
{
|
| 462 |
+
"epoch": 0.34252778921366817,
|
| 463 |
+
"grad_norm": 16514.513671875,
|
| 464 |
+
"learning_rate": 4.161178683597054e-07,
|
| 465 |
+
"logits/chosen": 9.041370391845703,
|
| 466 |
+
"logits/rejected": 9.758182525634766,
|
| 467 |
+
"logps/chosen": -153.77325439453125,
|
| 468 |
+
"logps/ref_chosen": -153.10540771484375,
|
| 469 |
+
"logps/ref_rejected": -175.8419647216797,
|
| 470 |
+
"logps/rejected": -176.5286102294922,
|
| 471 |
+
"loss": 1255.1703,
|
| 472 |
+
"rewards/accuracies": 0.5234375,
|
| 473 |
+
"rewards/chosen": -0.006678662728518248,
|
| 474 |
+
"rewards/margins": 0.00018779397942125797,
|
| 475 |
+
"rewards/rejected": -0.006866456940770149,
|
| 476 |
+
"sft_loss": 0.5549582242965698,
|
| 477 |
+
"step": 26
|
| 478 |
+
},
|
| 479 |
+
{
|
| 480 |
+
"epoch": 0.3557019349526554,
|
| 481 |
+
"grad_norm": 10625.310546875,
|
| 482 |
+
"learning_rate": 4.0717821664772124e-07,
|
| 483 |
+
"logits/chosen": 9.682290077209473,
|
| 484 |
+
"logits/rejected": 10.400200843811035,
|
| 485 |
+
"logps/chosen": -159.7697296142578,
|
| 486 |
+
"logps/ref_chosen": -158.69822692871094,
|
| 487 |
+
"logps/ref_rejected": -183.51446533203125,
|
| 488 |
+
"logps/rejected": -184.31439208984375,
|
| 489 |
+
"loss": 1268.7787,
|
| 490 |
+
"rewards/accuracies": 0.484375,
|
| 491 |
+
"rewards/chosen": -0.010714937001466751,
|
| 492 |
+
"rewards/margins": -0.0027154507115483284,
|
| 493 |
+
"rewards/rejected": -0.007999487221240997,
|
| 494 |
+
"sft_loss": 0.6249597072601318,
|
| 495 |
+
"step": 27
|
| 496 |
+
},
|
| 497 |
+
{
|
| 498 |
+
"epoch": 0.3688760806916426,
|
| 499 |
+
"grad_norm": 9945.3095703125,
|
| 500 |
+
"learning_rate": 3.978930531033806e-07,
|
| 501 |
+
"logits/chosen": 9.550697326660156,
|
| 502 |
+
"logits/rejected": 10.053712844848633,
|
| 503 |
+
"logps/chosen": -163.859619140625,
|
| 504 |
+
"logps/ref_chosen": -162.5417938232422,
|
| 505 |
+
"logps/ref_rejected": -185.78501892089844,
|
| 506 |
+
"logps/rejected": -187.59771728515625,
|
| 507 |
+
"loss": 1229.7642,
|
| 508 |
+
"rewards/accuracies": 0.5703125,
|
| 509 |
+
"rewards/chosen": -0.013178303837776184,
|
| 510 |
+
"rewards/margins": 0.004948761314153671,
|
| 511 |
+
"rewards/rejected": -0.018127065151929855,
|
| 512 |
+
"sft_loss": 0.6032208204269409,
|
| 513 |
+
"step": 28
|
| 514 |
+
},
|
| 515 |
+
{
|
| 516 |
+
"epoch": 0.3820502264306299,
|
| 517 |
+
"grad_norm": 12917.7509765625,
|
| 518 |
+
"learning_rate": 3.882827885312998e-07,
|
| 519 |
+
"logits/chosen": 9.513901710510254,
|
| 520 |
+
"logits/rejected": 10.564835548400879,
|
| 521 |
+
"logps/chosen": -154.92822265625,
|
| 522 |
+
"logps/ref_chosen": -153.61734008789062,
|
| 523 |
+
"logps/ref_rejected": -180.33628845214844,
|
| 524 |
+
"logps/rejected": -181.90066528320312,
|
| 525 |
+
"loss": 1242.5314,
|
| 526 |
+
"rewards/accuracies": 0.5703125,
|
| 527 |
+
"rewards/chosen": -0.013108888640999794,
|
| 528 |
+
"rewards/margins": 0.0025351184885948896,
|
| 529 |
+
"rewards/rejected": -0.015644006431102753,
|
| 530 |
+
"sft_loss": 0.6150007247924805,
|
| 531 |
+
"step": 29
|
| 532 |
+
},
|
| 533 |
+
{
|
| 534 |
+
"epoch": 0.39522437216961714,
|
| 535 |
+
"grad_norm": 19974.970703125,
|
| 536 |
+
"learning_rate": 3.7836854837871044e-07,
|
| 537 |
+
"logits/chosen": 9.282366752624512,
|
| 538 |
+
"logits/rejected": 9.916593551635742,
|
| 539 |
+
"logps/chosen": -158.56307983398438,
|
| 540 |
+
"logps/ref_chosen": -156.3722381591797,
|
| 541 |
+
"logps/ref_rejected": -177.78054809570312,
|
| 542 |
+
"logps/rejected": -179.95504760742188,
|
| 543 |
+
"loss": 1256.7991,
|
| 544 |
+
"rewards/accuracies": 0.5,
|
| 545 |
+
"rewards/chosen": -0.021908462047576904,
|
| 546 |
+
"rewards/margins": -0.00016373780090361834,
|
| 547 |
+
"rewards/rejected": -0.02174472250044346,
|
| 548 |
+
"sft_loss": 0.6054026484489441,
|
| 549 |
+
"step": 30
|
| 550 |
+
},
|
| 551 |
+
{
|
| 552 |
+
"epoch": 0.4083985179086044,
|
| 553 |
+
"grad_norm": 13933.48046875,
|
| 554 |
+
"learning_rate": 3.681721262971413e-07,
|
| 555 |
+
"logits/chosen": 9.050049781799316,
|
| 556 |
+
"logits/rejected": 9.892395973205566,
|
| 557 |
+
"logps/chosen": -159.972900390625,
|
| 558 |
+
"logps/ref_chosen": -157.671142578125,
|
| 559 |
+
"logps/ref_rejected": -180.26620483398438,
|
| 560 |
+
"logps/rejected": -182.66835021972656,
|
| 561 |
+
"loss": 1251.105,
|
| 562 |
+
"rewards/accuracies": 0.546875,
|
| 563 |
+
"rewards/chosen": -0.02301747538149357,
|
| 564 |
+
"rewards/margins": 0.0010038618929684162,
|
| 565 |
+
"rewards/rejected": -0.024021338671445847,
|
| 566 |
+
"sft_loss": 0.6480209231376648,
|
| 567 |
+
"step": 31
|
| 568 |
+
},
|
| 569 |
+
{
|
| 570 |
+
"epoch": 0.4215726636475916,
|
| 571 |
+
"grad_norm": 7404.970703125,
|
| 572 |
+
"learning_rate": 3.577159362352426e-07,
|
| 573 |
+
"logits/chosen": 9.216365814208984,
|
| 574 |
+
"logits/rejected": 10.082130432128906,
|
| 575 |
+
"logps/chosen": -165.99183654785156,
|
| 576 |
+
"logps/ref_chosen": -163.79681396484375,
|
| 577 |
+
"logps/ref_rejected": -183.711669921875,
|
| 578 |
+
"logps/rejected": -186.2124786376953,
|
| 579 |
+
"loss": 1239.9076,
|
| 580 |
+
"rewards/accuracies": 0.4921875,
|
| 581 |
+
"rewards/chosen": -0.021950121968984604,
|
| 582 |
+
"rewards/margins": 0.0030580349266529083,
|
| 583 |
+
"rewards/rejected": -0.02500815875828266,
|
| 584 |
+
"sft_loss": 0.6180049777030945,
|
| 585 |
+
"step": 32
|
| 586 |
+
},
|
| 587 |
+
{
|
| 588 |
+
"epoch": 0.43474680938657884,
|
| 589 |
+
"grad_norm": 18238.853515625,
|
| 590 |
+
"learning_rate": 3.470229631680624e-07,
|
| 591 |
+
"logits/chosen": 9.584964752197266,
|
| 592 |
+
"logits/rejected": 10.290851593017578,
|
| 593 |
+
"logps/chosen": -167.27029418945312,
|
| 594 |
+
"logps/ref_chosen": -164.63424682617188,
|
| 595 |
+
"logps/ref_rejected": -189.80027770996094,
|
| 596 |
+
"logps/rejected": -193.31954956054688,
|
| 597 |
+
"loss": 1213.4335,
|
| 598 |
+
"rewards/accuracies": 0.5859375,
|
| 599 |
+
"rewards/chosen": -0.02636047825217247,
|
| 600 |
+
"rewards/margins": 0.008832287043333054,
|
| 601 |
+
"rewards/rejected": -0.035192765295505524,
|
| 602 |
+
"sft_loss": 0.6433315277099609,
|
| 603 |
+
"step": 33
|
| 604 |
+
},
|
| 605 |
+
{
|
| 606 |
+
"epoch": 0.44792095512556607,
|
| 607 |
+
"grad_norm": 9458.361328125,
|
| 608 |
+
"learning_rate": 3.361167125710832e-07,
|
| 609 |
+
"logits/chosen": 9.156022071838379,
|
| 610 |
+
"logits/rejected": 9.985147476196289,
|
| 611 |
+
"logps/chosen": -164.09222412109375,
|
| 612 |
+
"logps/ref_chosen": -160.8765106201172,
|
| 613 |
+
"logps/ref_rejected": -189.85293579101562,
|
| 614 |
+
"logps/rejected": -193.40052795410156,
|
| 615 |
+
"loss": 1238.2539,
|
| 616 |
+
"rewards/accuracies": 0.515625,
|
| 617 |
+
"rewards/chosen": -0.032157331705093384,
|
| 618 |
+
"rewards/margins": 0.0033184667117893696,
|
| 619 |
+
"rewards/rejected": -0.03547579422593117,
|
| 620 |
+
"sft_loss": 0.5980746746063232,
|
| 621 |
+
"step": 34
|
| 622 |
+
},
|
| 623 |
+
{
|
| 624 |
+
"epoch": 0.4610951008645533,
|
| 625 |
+
"grad_norm": 9198.1455078125,
|
| 626 |
+
"learning_rate": 3.2502115875008516e-07,
|
| 627 |
+
"logits/chosen": 9.222213745117188,
|
| 628 |
+
"logits/rejected": 10.091606140136719,
|
| 629 |
+
"logps/chosen": -156.9556884765625,
|
| 630 |
+
"logps/ref_chosen": -153.65065002441406,
|
| 631 |
+
"logps/ref_rejected": -173.1910858154297,
|
| 632 |
+
"logps/rejected": -176.89773559570312,
|
| 633 |
+
"loss": 1237.6106,
|
| 634 |
+
"rewards/accuracies": 0.515625,
|
| 635 |
+
"rewards/chosen": -0.03305072337388992,
|
| 636 |
+
"rewards/margins": 0.004015911836177111,
|
| 637 |
+
"rewards/rejected": -0.037066638469696045,
|
| 638 |
+
"sft_loss": 0.5936375260353088,
|
| 639 |
+
"step": 35
|
| 640 |
+
},
|
| 641 |
+
{
|
| 642 |
+
"epoch": 0.47426924660354053,
|
| 643 |
+
"grad_norm": 11787.2255859375,
|
| 644 |
+
"learning_rate": 3.137606921404191e-07,
|
| 645 |
+
"logits/chosen": 9.194281578063965,
|
| 646 |
+
"logits/rejected": 10.14846420288086,
|
| 647 |
+
"logps/chosen": -157.76119995117188,
|
| 648 |
+
"logps/ref_chosen": -154.292236328125,
|
| 649 |
+
"logps/ref_rejected": -182.9899444580078,
|
| 650 |
+
"logps/rejected": -186.9964141845703,
|
| 651 |
+
"loss": 1230.7896,
|
| 652 |
+
"rewards/accuracies": 0.5234375,
|
| 653 |
+
"rewards/chosen": -0.03468959778547287,
|
| 654 |
+
"rewards/margins": 0.005375337786972523,
|
| 655 |
+
"rewards/rejected": -0.040064938366413116,
|
| 656 |
+
"sft_loss": 0.5638672113418579,
|
| 657 |
+
"step": 36
|
| 658 |
+
},
|
| 659 |
+
{
|
| 660 |
+
"epoch": 0.4874433923425278,
|
| 661 |
+
"grad_norm": 15921.7119140625,
|
| 662 |
+
"learning_rate": 3.0236006569153616e-07,
|
| 663 |
+
"logits/chosen": 9.018372535705566,
|
| 664 |
+
"logits/rejected": 9.938417434692383,
|
| 665 |
+
"logps/chosen": -171.6051483154297,
|
| 666 |
+
"logps/ref_chosen": -167.0302734375,
|
| 667 |
+
"logps/ref_rejected": -183.39315795898438,
|
| 668 |
+
"logps/rejected": -188.37820434570312,
|
| 669 |
+
"loss": 1234.4768,
|
| 670 |
+
"rewards/accuracies": 0.578125,
|
| 671 |
+
"rewards/chosen": -0.04574912413954735,
|
| 672 |
+
"rewards/margins": 0.004101306200027466,
|
| 673 |
+
"rewards/rejected": -0.049850430339574814,
|
| 674 |
+
"sft_loss": 0.7016611695289612,
|
| 675 |
+
"step": 37
|
| 676 |
+
},
|
| 677 |
+
{
|
| 678 |
+
"epoch": 0.500617538081515,
|
| 679 |
+
"grad_norm": 21936.44921875,
|
| 680 |
+
"learning_rate": 2.9084434045463254e-07,
|
| 681 |
+
"logits/chosen": 8.89705753326416,
|
| 682 |
+
"logits/rejected": 9.755127906799316,
|
| 683 |
+
"logps/chosen": -166.19654846191406,
|
| 684 |
+
"logps/ref_chosen": -161.3832244873047,
|
| 685 |
+
"logps/ref_rejected": -189.0400848388672,
|
| 686 |
+
"logps/rejected": -194.20907592773438,
|
| 687 |
+
"loss": 1237.9401,
|
| 688 |
+
"rewards/accuracies": 0.5546875,
|
| 689 |
+
"rewards/chosen": -0.048133231699466705,
|
| 690 |
+
"rewards/margins": 0.003556809388101101,
|
| 691 |
+
"rewards/rejected": -0.05169004201889038,
|
| 692 |
+
"sft_loss": 0.6404697895050049,
|
| 693 |
+
"step": 38
|
| 694 |
+
},
|
| 695 |
+
{
|
| 696 |
+
"epoch": 0.5137916838205022,
|
| 697 |
+
"grad_norm": 9377.791015625,
|
| 698 |
+
"learning_rate": 2.7923883049302066e-07,
|
| 699 |
+
"logits/chosen": 9.001154899597168,
|
| 700 |
+
"logits/rejected": 9.67138957977295,
|
| 701 |
+
"logps/chosen": -174.31785583496094,
|
| 702 |
+
"logps/ref_chosen": -169.62771606445312,
|
| 703 |
+
"logps/ref_rejected": -180.49684143066406,
|
| 704 |
+
"logps/rejected": -185.55691528320312,
|
| 705 |
+
"loss": 1237.9995,
|
| 706 |
+
"rewards/accuracies": 0.59375,
|
| 707 |
+
"rewards/chosen": -0.046901434659957886,
|
| 708 |
+
"rewards/margins": 0.0036992321256548166,
|
| 709 |
+
"rewards/rejected": -0.05060066282749176,
|
| 710 |
+
"sft_loss": 0.7168856859207153,
|
| 711 |
+
"step": 39
|
| 712 |
+
},
|
| 713 |
+
{
|
| 714 |
+
"epoch": 0.5269658295594895,
|
| 715 |
+
"grad_norm": 13965.9765625,
|
| 716 |
+
"learning_rate": 2.6756904723632324e-07,
|
| 717 |
+
"logits/chosen": 9.309320449829102,
|
| 718 |
+
"logits/rejected": 10.061290740966797,
|
| 719 |
+
"logps/chosen": -166.63397216796875,
|
| 720 |
+
"logps/ref_chosen": -162.01229858398438,
|
| 721 |
+
"logps/ref_rejected": -192.04664611816406,
|
| 722 |
+
"logps/rejected": -197.60873413085938,
|
| 723 |
+
"loss": 1209.7291,
|
| 724 |
+
"rewards/accuracies": 0.59375,
|
| 725 |
+
"rewards/chosen": -0.04621662572026253,
|
| 726 |
+
"rewards/margins": 0.009404572658240795,
|
| 727 |
+
"rewards/rejected": -0.0556211993098259,
|
| 728 |
+
"sft_loss": 0.6640117168426514,
|
| 729 |
+
"step": 40
|
| 730 |
+
},
|
| 731 |
+
{
|
| 732 |
+
"epoch": 0.5401399752984768,
|
| 733 |
+
"grad_norm": 14028.34375,
|
| 734 |
+
"learning_rate": 2.5586064340081516e-07,
|
| 735 |
+
"logits/chosen": 8.996285438537598,
|
| 736 |
+
"logits/rejected": 9.741279602050781,
|
| 737 |
+
"logps/chosen": -162.12594604492188,
|
| 738 |
+
"logps/ref_chosen": -157.49209594726562,
|
| 739 |
+
"logps/ref_rejected": -180.7811737060547,
|
| 740 |
+
"logps/rejected": -185.91555786132812,
|
| 741 |
+
"loss": 1232.3243,
|
| 742 |
+
"rewards/accuracies": 0.5390625,
|
| 743 |
+
"rewards/chosen": -0.046338487416505814,
|
| 744 |
+
"rewards/margins": 0.005005090031772852,
|
| 745 |
+
"rewards/rejected": -0.05134357884526253,
|
| 746 |
+
"sft_loss": 0.5569693446159363,
|
| 747 |
+
"step": 41
|
| 748 |
+
},
|
| 749 |
+
{
|
| 750 |
+
"epoch": 0.553314121037464,
|
| 751 |
+
"grad_norm": 13723.873046875,
|
| 752 |
+
"learning_rate": 2.4413935659918487e-07,
|
| 753 |
+
"logits/chosen": 8.688225746154785,
|
| 754 |
+
"logits/rejected": 9.09719467163086,
|
| 755 |
+
"logps/chosen": -161.71905517578125,
|
| 756 |
+
"logps/ref_chosen": -156.5626220703125,
|
| 757 |
+
"logps/ref_rejected": -186.57859802246094,
|
| 758 |
+
"logps/rejected": -192.47845458984375,
|
| 759 |
+
"loss": 1220.2029,
|
| 760 |
+
"rewards/accuracies": 0.640625,
|
| 761 |
+
"rewards/chosen": -0.051564302295446396,
|
| 762 |
+
"rewards/margins": 0.007434366270899773,
|
| 763 |
+
"rewards/rejected": -0.058998674154281616,
|
| 764 |
+
"sft_loss": 0.5949156284332275,
|
| 765 |
+
"step": 42
|
| 766 |
+
},
|
| 767 |
+
{
|
| 768 |
+
"epoch": 0.5664882667764513,
|
| 769 |
+
"grad_norm": 13328.6953125,
|
| 770 |
+
"learning_rate": 2.3243095276367684e-07,
|
| 771 |
+
"logits/chosen": 9.328302383422852,
|
| 772 |
+
"logits/rejected": 10.22354793548584,
|
| 773 |
+
"logps/chosen": -161.45523071289062,
|
| 774 |
+
"logps/ref_chosen": -156.5490264892578,
|
| 775 |
+
"logps/ref_rejected": -196.44403076171875,
|
| 776 |
+
"logps/rejected": -203.0041046142578,
|
| 777 |
+
"loss": 1177.267,
|
| 778 |
+
"rewards/accuracies": 0.640625,
|
| 779 |
+
"rewards/chosen": -0.04906204715371132,
|
| 780 |
+
"rewards/margins": 0.016538970172405243,
|
| 781 |
+
"rewards/rejected": -0.06560102105140686,
|
| 782 |
+
"sft_loss": 0.6034477949142456,
|
| 783 |
+
"step": 43
|
| 784 |
+
},
|
| 785 |
+
{
|
| 786 |
+
"epoch": 0.5796624125154385,
|
| 787 |
+
"grad_norm": 13357.529296875,
|
| 788 |
+
"learning_rate": 2.2076116950697937e-07,
|
| 789 |
+
"logits/chosen": 8.887812614440918,
|
| 790 |
+
"logits/rejected": 9.68736457824707,
|
| 791 |
+
"logps/chosen": -166.97500610351562,
|
| 792 |
+
"logps/ref_chosen": -161.502197265625,
|
| 793 |
+
"logps/ref_rejected": -190.9272918701172,
|
| 794 |
+
"logps/rejected": -197.3382568359375,
|
| 795 |
+
"loss": 1212.3368,
|
| 796 |
+
"rewards/accuracies": 0.6015625,
|
| 797 |
+
"rewards/chosen": -0.05472808703780174,
|
| 798 |
+
"rewards/margins": 0.009381452575325966,
|
| 799 |
+
"rewards/rejected": -0.06410954147577286,
|
| 800 |
+
"sft_loss": 0.649421215057373,
|
| 801 |
+
"step": 44
|
| 802 |
+
},
|
| 803 |
+
{
|
| 804 |
+
"epoch": 0.5928365582544257,
|
| 805 |
+
"grad_norm": 11449.1826171875,
|
| 806 |
+
"learning_rate": 2.091556595453674e-07,
|
| 807 |
+
"logits/chosen": 9.309349060058594,
|
| 808 |
+
"logits/rejected": 9.978551864624023,
|
| 809 |
+
"logps/chosen": -170.24081420898438,
|
| 810 |
+
"logps/ref_chosen": -164.62631225585938,
|
| 811 |
+
"logps/ref_rejected": -184.19137573242188,
|
| 812 |
+
"logps/rejected": -190.29238891601562,
|
| 813 |
+
"loss": 1233.8071,
|
| 814 |
+
"rewards/accuracies": 0.5234375,
|
| 815 |
+
"rewards/chosen": -0.05614509806036949,
|
| 816 |
+
"rewards/margins": 0.0048650153912603855,
|
| 817 |
+
"rewards/rejected": -0.06101011112332344,
|
| 818 |
+
"sft_loss": 0.6396956443786621,
|
| 819 |
+
"step": 45
|
| 820 |
+
},
|
| 821 |
+
{
|
| 822 |
+
"epoch": 0.606010703993413,
|
| 823 |
+
"grad_norm": 9890.376953125,
|
| 824 |
+
"learning_rate": 1.9763993430846392e-07,
|
| 825 |
+
"logits/chosen": 9.089374542236328,
|
| 826 |
+
"logits/rejected": 9.899026870727539,
|
| 827 |
+
"logps/chosen": -166.32931518554688,
|
| 828 |
+
"logps/ref_chosen": -160.89910888671875,
|
| 829 |
+
"logps/ref_rejected": -183.80149841308594,
|
| 830 |
+
"logps/rejected": -190.02410888671875,
|
| 831 |
+
"loss": 1219.3422,
|
| 832 |
+
"rewards/accuracies": 0.546875,
|
| 833 |
+
"rewards/chosen": -0.05430194362998009,
|
| 834 |
+
"rewards/margins": 0.007924157194793224,
|
| 835 |
+
"rewards/rejected": -0.062226101756095886,
|
| 836 |
+
"sft_loss": 0.6611277461051941,
|
| 837 |
+
"step": 46
|
| 838 |
+
},
|
| 839 |
+
{
|
| 840 |
+
"epoch": 0.6191848497324002,
|
| 841 |
+
"grad_norm": 10172.7646484375,
|
| 842 |
+
"learning_rate": 1.862393078595809e-07,
|
| 843 |
+
"logits/chosen": 9.095911026000977,
|
| 844 |
+
"logits/rejected": 9.976129531860352,
|
| 845 |
+
"logps/chosen": -169.3812255859375,
|
| 846 |
+
"logps/ref_chosen": -163.6266326904297,
|
| 847 |
+
"logps/ref_rejected": -187.1788330078125,
|
| 848 |
+
"logps/rejected": -193.5452880859375,
|
| 849 |
+
"loss": 1227.2684,
|
| 850 |
+
"rewards/accuracies": 0.53125,
|
| 851 |
+
"rewards/chosen": -0.05754602327942848,
|
| 852 |
+
"rewards/margins": 0.00611839909106493,
|
| 853 |
+
"rewards/rejected": -0.06366442143917084,
|
| 854 |
+
"sft_loss": 0.6642712354660034,
|
| 855 |
+
"step": 47
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"epoch": 0.6323589954713874,
|
| 859 |
+
"grad_norm": 19396.970703125,
|
| 860 |
+
"learning_rate": 1.7497884124991485e-07,
|
| 861 |
+
"logits/chosen": 9.59249210357666,
|
| 862 |
+
"logits/rejected": 10.533090591430664,
|
| 863 |
+
"logps/chosen": -164.8726043701172,
|
| 864 |
+
"logps/ref_chosen": -159.73843383789062,
|
| 865 |
+
"logps/ref_rejected": -183.07473754882812,
|
| 866 |
+
"logps/rejected": -189.20762634277344,
|
| 867 |
+
"loss": 1210.0222,
|
| 868 |
+
"rewards/accuracies": 0.5859375,
|
| 869 |
+
"rewards/chosen": -0.05134162679314613,
|
| 870 |
+
"rewards/margins": 0.009987279772758484,
|
| 871 |
+
"rewards/rejected": -0.06132890656590462,
|
| 872 |
+
"sft_loss": 0.6154706478118896,
|
| 873 |
+
"step": 48
|
| 874 |
+
},
|
| 875 |
+
{
|
| 876 |
+
"epoch": 0.6455331412103746,
|
| 877 |
+
"grad_norm": 10225.4775390625,
|
| 878 |
+
"learning_rate": 1.6388328742891678e-07,
|
| 879 |
+
"logits/chosen": 8.931614875793457,
|
| 880 |
+
"logits/rejected": 10.118232727050781,
|
| 881 |
+
"logps/chosen": -162.35116577148438,
|
| 882 |
+
"logps/ref_chosen": -156.84976196289062,
|
| 883 |
+
"logps/ref_rejected": -180.89483642578125,
|
| 884 |
+
"logps/rejected": -187.55239868164062,
|
| 885 |
+
"loss": 1202.4329,
|
| 886 |
+
"rewards/accuracies": 0.609375,
|
| 887 |
+
"rewards/chosen": -0.055014144629240036,
|
| 888 |
+
"rewards/margins": 0.011561589315533638,
|
| 889 |
+
"rewards/rejected": -0.06657573580741882,
|
| 890 |
+
"sft_loss": 0.6362596750259399,
|
| 891 |
+
"step": 49
|
| 892 |
+
},
|
| 893 |
+
{
|
| 894 |
+
"epoch": 0.6587072869493619,
|
| 895 |
+
"grad_norm": 12076.1318359375,
|
| 896 |
+
"learning_rate": 1.5297703683193753e-07,
|
| 897 |
+
"logits/chosen": 9.379952430725098,
|
| 898 |
+
"logits/rejected": 10.201663970947266,
|
| 899 |
+
"logps/chosen": -162.8404541015625,
|
| 900 |
+
"logps/ref_chosen": -157.3104248046875,
|
| 901 |
+
"logps/ref_rejected": -181.6476593017578,
|
| 902 |
+
"logps/rejected": -187.84884643554688,
|
| 903 |
+
"loss": 1225.0005,
|
| 904 |
+
"rewards/accuracies": 0.625,
|
| 905 |
+
"rewards/chosen": -0.055300273001194,
|
| 906 |
+
"rewards/margins": 0.006711489055305719,
|
| 907 |
+
"rewards/rejected": -0.062011756002902985,
|
| 908 |
+
"sft_loss": 0.5948672890663147,
|
| 909 |
+
"step": 50
|
| 910 |
+
},
|
| 911 |
+
{
|
| 912 |
+
"epoch": 0.6718814326883491,
|
| 913 |
+
"grad_norm": 9839.958984375,
|
| 914 |
+
"learning_rate": 1.422840637647574e-07,
|
| 915 |
+
"logits/chosen": 9.221153259277344,
|
| 916 |
+
"logits/rejected": 9.674837112426758,
|
| 917 |
+
"logps/chosen": -170.26763916015625,
|
| 918 |
+
"logps/ref_chosen": -164.4142303466797,
|
| 919 |
+
"logps/ref_rejected": -189.15463256835938,
|
| 920 |
+
"logps/rejected": -196.01943969726562,
|
| 921 |
+
"loss": 1210.0228,
|
| 922 |
+
"rewards/accuracies": 0.59375,
|
| 923 |
+
"rewards/chosen": -0.058534178882837296,
|
| 924 |
+
"rewards/margins": 0.01011375617235899,
|
| 925 |
+
"rewards/rejected": -0.06864793598651886,
|
| 926 |
+
"sft_loss": 0.6376750469207764,
|
| 927 |
+
"step": 51
|
| 928 |
+
},
|
| 929 |
+
{
|
| 930 |
+
"epoch": 0.6850555784273363,
|
| 931 |
+
"grad_norm": 11994.150390625,
|
| 932 |
+
"learning_rate": 1.3182787370285865e-07,
|
| 933 |
+
"logits/chosen": 8.866613388061523,
|
| 934 |
+
"logits/rejected": 9.9620943069458,
|
| 935 |
+
"logps/chosen": -164.61471557617188,
|
| 936 |
+
"logps/ref_chosen": -158.71780395507812,
|
| 937 |
+
"logps/ref_rejected": -186.26266479492188,
|
| 938 |
+
"logps/rejected": -192.55953979492188,
|
| 939 |
+
"loss": 1237.7555,
|
| 940 |
+
"rewards/accuracies": 0.5390625,
|
| 941 |
+
"rewards/chosen": -0.05896913632750511,
|
| 942 |
+
"rewards/margins": 0.003999476321041584,
|
| 943 |
+
"rewards/rejected": -0.06296861171722412,
|
| 944 |
+
"sft_loss": 0.6137311458587646,
|
| 945 |
+
"step": 52
|
| 946 |
+
},
|
| 947 |
+
{
|
| 948 |
+
"epoch": 0.6982297241663236,
|
| 949 |
+
"grad_norm": 13773.595703125,
|
| 950 |
+
"learning_rate": 1.2163145162128946e-07,
|
| 951 |
+
"logits/chosen": 9.425755500793457,
|
| 952 |
+
"logits/rejected": 10.286937713623047,
|
| 953 |
+
"logps/chosen": -173.0165557861328,
|
| 954 |
+
"logps/ref_chosen": -166.9249267578125,
|
| 955 |
+
"logps/ref_rejected": -194.2229766845703,
|
| 956 |
+
"logps/rejected": -201.09664916992188,
|
| 957 |
+
"loss": 1219.5342,
|
| 958 |
+
"rewards/accuracies": 0.6015625,
|
| 959 |
+
"rewards/chosen": -0.06091613695025444,
|
| 960 |
+
"rewards/margins": 0.007820552214980125,
|
| 961 |
+
"rewards/rejected": -0.06873668730258942,
|
| 962 |
+
"sft_loss": 0.6578559279441833,
|
| 963 |
+
"step": 53
|
| 964 |
+
},
|
| 965 |
+
{
|
| 966 |
+
"epoch": 0.7114038699053108,
|
| 967 |
+
"grad_norm": 18928.091796875,
|
| 968 |
+
"learning_rate": 1.1171721146870014e-07,
|
| 969 |
+
"logits/chosen": 8.70556354522705,
|
| 970 |
+
"logits/rejected": 9.344762802124023,
|
| 971 |
+
"logps/chosen": -169.91925048828125,
|
| 972 |
+
"logps/ref_chosen": -163.73155212402344,
|
| 973 |
+
"logps/ref_rejected": -185.25901794433594,
|
| 974 |
+
"logps/rejected": -192.32472229003906,
|
| 975 |
+
"loss": 1215.6115,
|
| 976 |
+
"rewards/accuracies": 0.5859375,
|
| 977 |
+
"rewards/chosen": -0.06187691166996956,
|
| 978 |
+
"rewards/margins": 0.008779974654316902,
|
| 979 |
+
"rewards/rejected": -0.07065688818693161,
|
| 980 |
+
"sft_loss": 0.7079038023948669,
|
| 981 |
+
"step": 54
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"epoch": 0.724578015644298,
|
| 985 |
+
"grad_norm": 11829.06640625,
|
| 986 |
+
"learning_rate": 1.0210694689661939e-07,
|
| 987 |
+
"logits/chosen": 9.351631164550781,
|
| 988 |
+
"logits/rejected": 9.926772117614746,
|
| 989 |
+
"logps/chosen": -165.41712951660156,
|
| 990 |
+
"logps/ref_chosen": -159.25161743164062,
|
| 991 |
+
"logps/ref_rejected": -182.14483642578125,
|
| 992 |
+
"logps/rejected": -189.38609313964844,
|
| 993 |
+
"loss": 1208.5001,
|
| 994 |
+
"rewards/accuracies": 0.59375,
|
| 995 |
+
"rewards/chosen": -0.0616549551486969,
|
| 996 |
+
"rewards/margins": 0.010757625102996826,
|
| 997 |
+
"rewards/rejected": -0.07241257280111313,
|
| 998 |
+
"sft_loss": 0.5927904844284058,
|
| 999 |
+
"step": 55
|
| 1000 |
+
},
|
| 1001 |
+
{
|
| 1002 |
+
"epoch": 0.7377521613832853,
|
| 1003 |
+
"grad_norm": 19731.275390625,
|
| 1004 |
+
"learning_rate": 9.282178335227883e-08,
|
| 1005 |
+
"logits/chosen": 9.275335311889648,
|
| 1006 |
+
"logits/rejected": 10.163053512573242,
|
| 1007 |
+
"logps/chosen": -170.1624755859375,
|
| 1008 |
+
"logps/ref_chosen": -164.87774658203125,
|
| 1009 |
+
"logps/ref_rejected": -188.59312438964844,
|
| 1010 |
+
"logps/rejected": -194.8134002685547,
|
| 1011 |
+
"loss": 1215.3372,
|
| 1012 |
+
"rewards/accuracies": 0.5703125,
|
| 1013 |
+
"rewards/chosen": -0.052847325801849365,
|
| 1014 |
+
"rewards/margins": 0.009355366230010986,
|
| 1015 |
+
"rewards/rejected": -0.06220268830657005,
|
| 1016 |
+
"sft_loss": 0.6573229432106018,
|
| 1017 |
+
"step": 56
|
| 1018 |
+
},
|
| 1019 |
+
{
|
| 1020 |
+
"epoch": 0.7509263071222725,
|
| 1021 |
+
"grad_norm": 13105.3037109375,
|
| 1022 |
+
"learning_rate": 8.388213164029459e-08,
|
| 1023 |
+
"logits/chosen": 8.516356468200684,
|
| 1024 |
+
"logits/rejected": 9.523008346557617,
|
| 1025 |
+
"logps/chosen": -171.08535766601562,
|
| 1026 |
+
"logps/ref_chosen": -164.48574829101562,
|
| 1027 |
+
"logps/ref_rejected": -195.56707763671875,
|
| 1028 |
+
"logps/rejected": -202.96926879882812,
|
| 1029 |
+
"loss": 1220.5337,
|
| 1030 |
+
"rewards/accuracies": 0.5625,
|
| 1031 |
+
"rewards/chosen": -0.0659961923956871,
|
| 1032 |
+
"rewards/margins": 0.008025763556361198,
|
| 1033 |
+
"rewards/rejected": -0.07402195781469345,
|
| 1034 |
+
"sft_loss": 0.6819319725036621,
|
| 1035 |
+
"step": 57
|
| 1036 |
+
},
|
| 1037 |
+
{
|
| 1038 |
+
"epoch": 0.7641004528612598,
|
| 1039 |
+
"grad_norm": 13435.5908203125,
|
| 1040 |
+
"learning_rate": 7.530764305528958e-08,
|
| 1041 |
+
"logits/chosen": 9.16685676574707,
|
| 1042 |
+
"logits/rejected": 10.048408508300781,
|
| 1043 |
+
"logps/chosen": -172.24224853515625,
|
| 1044 |
+
"logps/ref_chosen": -165.94154357910156,
|
| 1045 |
+
"logps/ref_rejected": -192.1100311279297,
|
| 1046 |
+
"logps/rejected": -199.4058837890625,
|
| 1047 |
+
"loss": 1209.3951,
|
| 1048 |
+
"rewards/accuracies": 0.6640625,
|
| 1049 |
+
"rewards/chosen": -0.06300710141658783,
|
| 1050 |
+
"rewards/margins": 0.009951447136700153,
|
| 1051 |
+
"rewards/rejected": -0.07295854389667511,
|
| 1052 |
+
"sft_loss": 0.7163535952568054,
|
| 1053 |
+
"step": 58
|
| 1054 |
+
},
|
| 1055 |
+
{
|
| 1056 |
+
"epoch": 0.7772745986002471,
|
| 1057 |
+
"grad_norm": 22198.599609375,
|
| 1058 |
+
"learning_rate": 6.711716618408281e-08,
|
| 1059 |
+
"logits/chosen": 8.751832962036133,
|
| 1060 |
+
"logits/rejected": 9.960253715515137,
|
| 1061 |
+
"logps/chosen": -173.29736328125,
|
| 1062 |
+
"logps/ref_chosen": -167.14024353027344,
|
| 1063 |
+
"logps/ref_rejected": -192.01669311523438,
|
| 1064 |
+
"logps/rejected": -199.43048095703125,
|
| 1065 |
+
"loss": 1196.2831,
|
| 1066 |
+
"rewards/accuracies": 0.625,
|
| 1067 |
+
"rewards/chosen": -0.06157132238149643,
|
| 1068 |
+
"rewards/margins": 0.012566398829221725,
|
| 1069 |
+
"rewards/rejected": -0.07413772493600845,
|
| 1070 |
+
"sft_loss": 0.6511445045471191,
|
| 1071 |
+
"step": 59
|
| 1072 |
+
},
|
| 1073 |
+
{
|
| 1074 |
+
"epoch": 0.7904487443392343,
|
| 1075 |
+
"grad_norm": 14903.919921875,
|
| 1076 |
+
"learning_rate": 5.932870547240454e-08,
|
| 1077 |
+
"logits/chosen": 8.80639934539795,
|
| 1078 |
+
"logits/rejected": 9.536232948303223,
|
| 1079 |
+
"logps/chosen": -169.44081115722656,
|
| 1080 |
+
"logps/ref_chosen": -162.84884643554688,
|
| 1081 |
+
"logps/ref_rejected": -182.6114501953125,
|
| 1082 |
+
"logps/rejected": -190.31076049804688,
|
| 1083 |
+
"loss": 1204.0352,
|
| 1084 |
+
"rewards/accuracies": 0.6171875,
|
| 1085 |
+
"rewards/chosen": -0.06591987609863281,
|
| 1086 |
+
"rewards/margins": 0.011073156259953976,
|
| 1087 |
+
"rewards/rejected": -0.07699302583932877,
|
| 1088 |
+
"sft_loss": 0.7044574618339539,
|
| 1089 |
+
"step": 60
|
| 1090 |
+
},
|
| 1091 |
+
{
|
| 1092 |
+
"epoch": 0.8036228900782215,
|
| 1093 |
+
"grad_norm": 11096.5361328125,
|
| 1094 |
+
"learning_rate": 5.1959381647217665e-08,
|
| 1095 |
+
"logits/chosen": 9.198155403137207,
|
| 1096 |
+
"logits/rejected": 9.714008331298828,
|
| 1097 |
+
"logps/chosen": -162.41522216796875,
|
| 1098 |
+
"logps/ref_chosen": -156.99459838867188,
|
| 1099 |
+
"logps/ref_rejected": -183.13221740722656,
|
| 1100 |
+
"logps/rejected": -190.27064514160156,
|
| 1101 |
+
"loss": 1176.4701,
|
| 1102 |
+
"rewards/accuracies": 0.6484375,
|
| 1103 |
+
"rewards/chosen": -0.054206304252147675,
|
| 1104 |
+
"rewards/margins": 0.017177969217300415,
|
| 1105 |
+
"rewards/rejected": -0.07138426601886749,
|
| 1106 |
+
"sft_loss": 0.5913216471672058,
|
| 1107 |
+
"step": 61
|
| 1108 |
+
},
|
| 1109 |
+
{
|
| 1110 |
+
"epoch": 0.8167970358172087,
|
| 1111 |
+
"grad_norm": 11606.82421875,
|
| 1112 |
+
"learning_rate": 4.502539408164385e-08,
|
| 1113 |
+
"logits/chosen": 9.229076385498047,
|
| 1114 |
+
"logits/rejected": 10.238713264465332,
|
| 1115 |
+
"logps/chosen": -164.31454467773438,
|
| 1116 |
+
"logps/ref_chosen": -158.83319091796875,
|
| 1117 |
+
"logps/ref_rejected": -185.24270629882812,
|
| 1118 |
+
"logps/rejected": -191.90802001953125,
|
| 1119 |
+
"loss": 1199.8636,
|
| 1120 |
+
"rewards/accuracies": 0.578125,
|
| 1121 |
+
"rewards/chosen": -0.05481347814202309,
|
| 1122 |
+
"rewards/margins": 0.011839599348604679,
|
| 1123 |
+
"rewards/rejected": -0.06665308028459549,
|
| 1124 |
+
"sft_loss": 0.6067987084388733,
|
| 1125 |
+
"step": 62
|
| 1126 |
+
},
|
| 1127 |
+
{
|
| 1128 |
+
"epoch": 0.829971181556196,
|
| 1129 |
+
"grad_norm": 20112.255859375,
|
| 1130 |
+
"learning_rate": 3.854198518522564e-08,
|
| 1131 |
+
"logits/chosen": 9.637617111206055,
|
| 1132 |
+
"logits/rejected": 9.869871139526367,
|
| 1133 |
+
"logps/chosen": -165.5172119140625,
|
| 1134 |
+
"logps/ref_chosen": -159.96975708007812,
|
| 1135 |
+
"logps/ref_rejected": -173.48886108398438,
|
| 1136 |
+
"logps/rejected": -179.82846069335938,
|
| 1137 |
+
"loss": 1220.7441,
|
| 1138 |
+
"rewards/accuracies": 0.5625,
|
| 1139 |
+
"rewards/chosen": -0.05547443777322769,
|
| 1140 |
+
"rewards/margins": 0.00792163796722889,
|
| 1141 |
+
"rewards/rejected": -0.06339608132839203,
|
| 1142 |
+
"sft_loss": 0.5795433521270752,
|
| 1143 |
+
"step": 63
|
| 1144 |
+
},
|
| 1145 |
+
{
|
| 1146 |
+
"epoch": 0.8431453272951832,
|
| 1147 |
+
"grad_norm": 7279.28564453125,
|
| 1148 |
+
"learning_rate": 3.2523406897802444e-08,
|
| 1149 |
+
"logits/chosen": 8.752022743225098,
|
| 1150 |
+
"logits/rejected": 9.561859130859375,
|
| 1151 |
+
"logps/chosen": -161.46749877929688,
|
| 1152 |
+
"logps/ref_chosen": -155.63494873046875,
|
| 1153 |
+
"logps/ref_rejected": -187.86007690429688,
|
| 1154 |
+
"logps/rejected": -194.855224609375,
|
| 1155 |
+
"loss": 1203.9415,
|
| 1156 |
+
"rewards/accuracies": 0.6015625,
|
| 1157 |
+
"rewards/chosen": -0.05832529067993164,
|
| 1158 |
+
"rewards/margins": 0.011626005172729492,
|
| 1159 |
+
"rewards/rejected": -0.06995129585266113,
|
| 1160 |
+
"sft_loss": 0.5411882996559143,
|
| 1161 |
+
"step": 64
|
| 1162 |
+
},
|
| 1163 |
+
{
|
| 1164 |
+
"epoch": 0.8563194730341704,
|
| 1165 |
+
"grad_norm": 14110.2802734375,
|
| 1166 |
+
"learning_rate": 2.6982889360653376e-08,
|
| 1167 |
+
"logits/chosen": 8.90047836303711,
|
| 1168 |
+
"logits/rejected": 10.215944290161133,
|
| 1169 |
+
"logps/chosen": -158.57235717773438,
|
| 1170 |
+
"logps/ref_chosen": -152.77847290039062,
|
| 1171 |
+
"logps/ref_rejected": -177.35072326660156,
|
| 1172 |
+
"logps/rejected": -183.6927032470703,
|
| 1173 |
+
"loss": 1231.4303,
|
| 1174 |
+
"rewards/accuracies": 0.53125,
|
| 1175 |
+
"rewards/chosen": -0.057939112186431885,
|
| 1176 |
+
"rewards/margins": 0.005480704363435507,
|
| 1177 |
+
"rewards/rejected": -0.06341981887817383,
|
| 1178 |
+
"sft_loss": 0.6049556732177734,
|
| 1179 |
+
"step": 65
|
| 1180 |
+
},
|
| 1181 |
+
{
|
| 1182 |
+
"epoch": 0.8694936187731577,
|
| 1183 |
+
"grad_norm": 12082.8798828125,
|
| 1184 |
+
"learning_rate": 2.1932611833775843e-08,
|
| 1185 |
+
"logits/chosen": 9.26243782043457,
|
| 1186 |
+
"logits/rejected": 10.02214527130127,
|
| 1187 |
+
"logps/chosen": -162.09317016601562,
|
| 1188 |
+
"logps/ref_chosen": -156.50210571289062,
|
| 1189 |
+
"logps/ref_rejected": -178.757568359375,
|
| 1190 |
+
"logps/rejected": -184.8837432861328,
|
| 1191 |
+
"loss": 1234.9696,
|
| 1192 |
+
"rewards/accuracies": 0.5625,
|
| 1193 |
+
"rewards/chosen": -0.055910591036081314,
|
| 1194 |
+
"rewards/margins": 0.005351049359887838,
|
| 1195 |
+
"rewards/rejected": -0.06126164272427559,
|
| 1196 |
+
"sft_loss": 0.6371285915374756,
|
| 1197 |
+
"step": 66
|
| 1198 |
+
},
|
| 1199 |
+
{
|
| 1200 |
+
"epoch": 0.8826677645121449,
|
| 1201 |
+
"grad_norm": 27654.07421875,
|
| 1202 |
+
"learning_rate": 1.738367592322837e-08,
|
| 1203 |
+
"logits/chosen": 9.491484642028809,
|
| 1204 |
+
"logits/rejected": 10.294921875,
|
| 1205 |
+
"logps/chosen": -164.4672088623047,
|
| 1206 |
+
"logps/ref_chosen": -159.2628173828125,
|
| 1207 |
+
"logps/ref_rejected": -188.97991943359375,
|
| 1208 |
+
"logps/rejected": -195.56919860839844,
|
| 1209 |
+
"loss": 1193.6108,
|
| 1210 |
+
"rewards/accuracies": 0.6015625,
|
| 1211 |
+
"rewards/chosen": -0.052044015377759933,
|
| 1212 |
+
"rewards/margins": 0.013848824426531792,
|
| 1213 |
+
"rewards/rejected": -0.06589283794164658,
|
| 1214 |
+
"sft_loss": 0.6365179419517517,
|
| 1215 |
+
"step": 67
|
| 1216 |
+
},
|
| 1217 |
+
{
|
| 1218 |
+
"epoch": 0.8958419102511321,
|
| 1219 |
+
"grad_norm": 10565.7470703125,
|
| 1220 |
+
"learning_rate": 1.3346081177391472e-08,
|
| 1221 |
+
"logits/chosen": 9.401812553405762,
|
| 1222 |
+
"logits/rejected": 10.087583541870117,
|
| 1223 |
+
"logps/chosen": -166.74407958984375,
|
| 1224 |
+
"logps/ref_chosen": -160.99803161621094,
|
| 1225 |
+
"logps/ref_rejected": -190.18405151367188,
|
| 1226 |
+
"logps/rejected": -197.23287963867188,
|
| 1227 |
+
"loss": 1195.428,
|
| 1228 |
+
"rewards/accuracies": 0.6171875,
|
| 1229 |
+
"rewards/chosen": -0.05746051296591759,
|
| 1230 |
+
"rewards/margins": 0.013027713634073734,
|
| 1231 |
+
"rewards/rejected": -0.07048822194337845,
|
| 1232 |
+
"sft_loss": 0.6548814177513123,
|
| 1233 |
+
"step": 68
|
| 1234 |
+
},
|
| 1235 |
+
{
|
| 1236 |
+
"epoch": 0.9090160559901194,
|
| 1237 |
+
"grad_norm": 17419.16015625,
|
| 1238 |
+
"learning_rate": 9.828703105789981e-09,
|
| 1239 |
+
"logits/chosen": 9.017786979675293,
|
| 1240 |
+
"logits/rejected": 9.950035095214844,
|
| 1241 |
+
"logps/chosen": -170.9835205078125,
|
| 1242 |
+
"logps/ref_chosen": -165.075439453125,
|
| 1243 |
+
"logps/ref_rejected": -188.81295776367188,
|
| 1244 |
+
"logps/rejected": -196.24879455566406,
|
| 1245 |
+
"loss": 1185.5491,
|
| 1246 |
+
"rewards/accuracies": 0.640625,
|
| 1247 |
+
"rewards/chosen": -0.05908071622252464,
|
| 1248 |
+
"rewards/margins": 0.015277737751603127,
|
| 1249 |
+
"rewards/rejected": -0.07435844838619232,
|
| 1250 |
+
"sft_loss": 0.6601569056510925,
|
| 1251 |
+
"step": 69
|
| 1252 |
+
},
|
| 1253 |
+
{
|
| 1254 |
+
"epoch": 0.9221902017291066,
|
| 1255 |
+
"grad_norm": 9676.4541015625,
|
| 1256 |
+
"learning_rate": 6.839273668796747e-09,
|
| 1257 |
+
"logits/chosen": 8.569165229797363,
|
| 1258 |
+
"logits/rejected": 9.33808708190918,
|
| 1259 |
+
"logps/chosen": -173.03811645507812,
|
| 1260 |
+
"logps/ref_chosen": -166.4983367919922,
|
| 1261 |
+
"logps/ref_rejected": -193.48855590820312,
|
| 1262 |
+
"logps/rejected": -201.1259765625,
|
| 1263 |
+
"loss": 1204.6237,
|
| 1264 |
+
"rewards/accuracies": 0.578125,
|
| 1265 |
+
"rewards/chosen": -0.06539767980575562,
|
| 1266 |
+
"rewards/margins": 0.010976485908031464,
|
| 1267 |
+
"rewards/rejected": -0.07637415081262589,
|
| 1268 |
+
"sft_loss": 0.6281808614730835,
|
| 1269 |
+
"step": 70
|
| 1270 |
+
},
|
| 1271 |
+
{
|
| 1272 |
+
"epoch": 0.9353643474680938,
|
| 1273 |
+
"grad_norm": 8870.37109375,
|
| 1274 |
+
"learning_rate": 4.384364281105973e-09,
|
| 1275 |
+
"logits/chosen": 9.240521430969238,
|
| 1276 |
+
"logits/rejected": 9.782825469970703,
|
| 1277 |
+
"logps/chosen": -168.765380859375,
|
| 1278 |
+
"logps/ref_chosen": -162.68539428710938,
|
| 1279 |
+
"logps/ref_rejected": -186.59564208984375,
|
| 1280 |
+
"logps/rejected": -193.93653869628906,
|
| 1281 |
+
"loss": 1197.6589,
|
| 1282 |
+
"rewards/accuracies": 0.671875,
|
| 1283 |
+
"rewards/chosen": -0.06079991161823273,
|
| 1284 |
+
"rewards/margins": 0.012609158642590046,
|
| 1285 |
+
"rewards/rejected": -0.0734090656042099,
|
| 1286 |
+
"sft_loss": 0.6100206971168518,
|
| 1287 |
+
"step": 71
|
| 1288 |
+
},
|
| 1289 |
+
{
|
| 1290 |
+
"epoch": 0.9485384932070811,
|
| 1291 |
+
"grad_norm": 13044.865234375,
|
| 1292 |
+
"learning_rate": 2.469371366337264e-09,
|
| 1293 |
+
"logits/chosen": 9.417778015136719,
|
| 1294 |
+
"logits/rejected": 10.087042808532715,
|
| 1295 |
+
"logps/chosen": -169.05316162109375,
|
| 1296 |
+
"logps/ref_chosen": -162.62753295898438,
|
| 1297 |
+
"logps/ref_rejected": -191.22463989257812,
|
| 1298 |
+
"logps/rejected": -199.12945556640625,
|
| 1299 |
+
"loss": 1187.1266,
|
| 1300 |
+
"rewards/accuracies": 0.625,
|
| 1301 |
+
"rewards/chosen": -0.06425632536411285,
|
| 1302 |
+
"rewards/margins": 0.014791999943554401,
|
| 1303 |
+
"rewards/rejected": -0.07904832810163498,
|
| 1304 |
+
"sft_loss": 0.6630038022994995,
|
| 1305 |
+
"step": 72
|
| 1306 |
+
},
|
| 1307 |
+
{
|
| 1308 |
+
"epoch": 0.9617126389460683,
|
| 1309 |
+
"grad_norm": 17405.087890625,
|
| 1310 |
+
"learning_rate": 1.0985044945254762e-09,
|
| 1311 |
+
"logits/chosen": 9.360172271728516,
|
| 1312 |
+
"logits/rejected": 10.11999225616455,
|
| 1313 |
+
"logps/chosen": -170.00250244140625,
|
| 1314 |
+
"logps/ref_chosen": -164.04856872558594,
|
| 1315 |
+
"logps/ref_rejected": -183.95240783691406,
|
| 1316 |
+
"logps/rejected": -190.49746704101562,
|
| 1317 |
+
"loss": 1229.5161,
|
| 1318 |
+
"rewards/accuracies": 0.5078125,
|
| 1319 |
+
"rewards/chosen": -0.05953914672136307,
|
| 1320 |
+
"rewards/margins": 0.0059114256873726845,
|
| 1321 |
+
"rewards/rejected": -0.06545057892799377,
|
| 1322 |
+
"sft_loss": 0.6415579915046692,
|
| 1323 |
+
"step": 73
|
| 1324 |
+
},
|
| 1325 |
+
{
|
| 1326 |
+
"epoch": 0.9748867846850556,
|
| 1327 |
+
"grad_norm": 10650.671875,
|
| 1328 |
+
"learning_rate": 2.7477712857215675e-10,
|
| 1329 |
+
"logits/chosen": 9.245479583740234,
|
| 1330 |
+
"logits/rejected": 10.170373916625977,
|
| 1331 |
+
"logps/chosen": -172.0705108642578,
|
| 1332 |
+
"logps/ref_chosen": -165.9273681640625,
|
| 1333 |
+
"logps/ref_rejected": -190.94757080078125,
|
| 1334 |
+
"logps/rejected": -197.87510681152344,
|
| 1335 |
+
"loss": 1220.1764,
|
| 1336 |
+
"rewards/accuracies": 0.5546875,
|
| 1337 |
+
"rewards/chosen": -0.06143137812614441,
|
| 1338 |
+
"rewards/margins": 0.007843904197216034,
|
| 1339 |
+
"rewards/rejected": -0.06927528232336044,
|
| 1340 |
+
"sft_loss": 0.6530526280403137,
|
| 1341 |
+
"step": 74
|
| 1342 |
+
},
|
| 1343 |
+
{
|
| 1344 |
+
"epoch": 0.9880609304240429,
|
| 1345 |
+
"grad_norm": 17721.173828125,
|
| 1346 |
+
"learning_rate": 0.0,
|
| 1347 |
+
"logits/chosen": 9.165303230285645,
|
| 1348 |
+
"logits/rejected": 9.725177764892578,
|
| 1349 |
+
"logps/chosen": -166.54443359375,
|
| 1350 |
+
"logps/ref_chosen": -161.05873107910156,
|
| 1351 |
+
"logps/ref_rejected": -186.65126037597656,
|
| 1352 |
+
"logps/rejected": -193.4801788330078,
|
| 1353 |
+
"loss": 1192.2148,
|
| 1354 |
+
"rewards/accuracies": 0.6171875,
|
| 1355 |
+
"rewards/chosen": -0.05485706776380539,
|
| 1356 |
+
"rewards/margins": 0.01343199796974659,
|
| 1357 |
+
"rewards/rejected": -0.06828906387090683,
|
| 1358 |
+
"sft_loss": 0.5920566320419312,
|
| 1359 |
+
"step": 75
|
| 1360 |
+
},
|
| 1361 |
+
{
|
| 1362 |
+
"epoch": 0.9880609304240429,
|
| 1363 |
+
"step": 75,
|
| 1364 |
+
"total_flos": 0.0,
|
| 1365 |
+
"train_loss": 1230.5828483072917,
|
| 1366 |
+
"train_runtime": 5273.3776,
|
| 1367 |
+
"train_samples_per_second": 1.842,
|
| 1368 |
+
"train_steps_per_second": 0.014
|
| 1369 |
+
}
|
| 1370 |
+
],
|
| 1371 |
+
"logging_steps": 1,
|
| 1372 |
+
"max_steps": 75,
|
| 1373 |
+
"num_input_tokens_seen": 0,
|
| 1374 |
+
"num_train_epochs": 1,
|
| 1375 |
+
"save_steps": 100000,
|
| 1376 |
+
"stateful_callbacks": {
|
| 1377 |
+
"TrainerControl": {
|
| 1378 |
+
"args": {
|
| 1379 |
+
"should_epoch_stop": false,
|
| 1380 |
+
"should_evaluate": false,
|
| 1381 |
+
"should_log": false,
|
| 1382 |
+
"should_save": false,
|
| 1383 |
+
"should_training_stop": false
|
| 1384 |
+
},
|
| 1385 |
+
"attributes": {}
|
| 1386 |
+
}
|
| 1387 |
+
},
|
| 1388 |
+
"total_flos": 0.0,
|
| 1389 |
+
"train_batch_size": 2,
|
| 1390 |
+
"trial_name": null,
|
| 1391 |
+
"trial_params": null
|
| 1392 |
+
}
|
Phi-3-mini-4k-instruct-ipo-proportion1.0-sft0.0-chunk7_6_rr_all/2/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b3377b7b962968d9fba89f367931136cfb672dffb06623e55ecb665cc9e654d
|
| 3 |
+
size 7352
|