Upload folder using huggingface_hub
Browse files- .gitattributes +2 -0
- README.md +109 -0
- added_tokens.json +12 -0
- config.json +145 -0
- configuration_phi3.py +226 -0
- generation_config.json +10 -0
- merges.txt +0 -0
- modeling_phi3.py +1180 -0
- npu/12251558561149292649.blob +3 -0
- openvino_detokenizer.bin +3 -0
- openvino_detokenizer.xml +220 -0
- openvino_model.bin +3 -0
- openvino_model.xml +0 -0
- openvino_tokenizer.bin +3 -0
- openvino_tokenizer.xml +686 -0
- special_tokens_map.json +30 -0
- tokenizer.json +3 -0
- tokenizer_config.json +112 -0
- vocab.json +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
npu/12251558561149292649.blob filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- multilingual
|
| 4 |
+
- ar
|
| 5 |
+
- zh
|
| 6 |
+
- cs
|
| 7 |
+
- da
|
| 8 |
+
- nl
|
| 9 |
+
- en
|
| 10 |
+
- fi
|
| 11 |
+
- fr
|
| 12 |
+
- de
|
| 13 |
+
- he
|
| 14 |
+
- hu
|
| 15 |
+
- it
|
| 16 |
+
- ja
|
| 17 |
+
- ko
|
| 18 |
+
- 'no'
|
| 19 |
+
- pl
|
| 20 |
+
- pt
|
| 21 |
+
- ru
|
| 22 |
+
- es
|
| 23 |
+
- sv
|
| 24 |
+
- th
|
| 25 |
+
- tr
|
| 26 |
+
- uk
|
| 27 |
+
license: mit
|
| 28 |
+
license_link: https://huggingface.co/microsoft/Phi-4-mini-instruct/resolve/main/LICENSE
|
| 29 |
+
pipeline_tag: text-generation
|
| 30 |
+
tags:
|
| 31 |
+
- nlp
|
| 32 |
+
- code
|
| 33 |
+
base_model: microsoft/Phi-4-mini-instruct
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
# Phi-4-mini-instruct-fp16-ov
|
| 37 |
+
* Model creator: [Microsoft](https://huggingface.co/microsoft)
|
| 38 |
+
* Original model: [Phi-4-mini-instruct](https://huggingface.co/microsoft/Phi-4-mini-instruct)
|
| 39 |
+
|
| 40 |
+
## Description
|
| 41 |
+
|
| 42 |
+
This is [Phi-4-mini-instruct](https://huggingface.co/microsoft/Phi-4-mini-instruct) model converted to the [OpenVINO™ IR](https://docs.openvino.ai/2025/documentation/openvino-ir-format.html) (Intermediate Representation) format with weights compressed to FP16.
|
| 43 |
+
|
| 44 |
+
## Compatibility
|
| 45 |
+
The provided OpenVINO™ IR model is compatible with:
|
| 46 |
+
* OpenVINO version 2025.1.0 and higher
|
| 47 |
+
* Optimum Intel 1.22.0 and higher
|
| 48 |
+
|
| 49 |
+
## Running Model Inference with [Optimum Intel](https://huggingface.co/docs/optimum/intel/index)
|
| 50 |
+
|
| 51 |
+
1. Install packages required for using [Optimum Intel](https://huggingface.co/docs/optimum/intel/index) integration with the OpenVINO backend:
|
| 52 |
+
```
|
| 53 |
+
pip install optimum[openvino]
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
2. Run model inference:
|
| 57 |
+
```
|
| 58 |
+
from transformers import AutoTokenizer
|
| 59 |
+
from optimum.intel.openvino import OVModelForCausalLM
|
| 60 |
+
model_id = "OpenVINO/Phi-4-mini-instruct-fp16-ov"
|
| 61 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 62 |
+
model = OVModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
| 63 |
+
|
| 64 |
+
inputs = tokenizer("What is OpenVINO?", return_tensors="pt")
|
| 65 |
+
outputs = model.generate(**inputs, max_length=200)
|
| 66 |
+
text = tokenizer.batch_decode(outputs)[0]
|
| 67 |
+
print(text)
|
| 68 |
+
```
|
| 69 |
+
For more examples and possible optimizations, refer to [the Inference with Optimum Intel](https://docs.openvino.ai/2025/openvino-workflow-generative/inference-with-optimum-intel.html).
|
| 70 |
+
|
| 71 |
+
## Running Model Inference with [OpenVINO GenAI](https://github.com/openvinotoolkit/openvino.genai)
|
| 72 |
+
|
| 73 |
+
1. Install packages required for using OpenVINO GenAI.
|
| 74 |
+
```
|
| 75 |
+
pip install -U openvino openvino-tokenizers openvino-genai
|
| 76 |
+
pip install huggingface_hub
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
2. Download model from HuggingFace Hub
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
import huggingface_hub as hf_hub
|
| 83 |
+
model_id = "OpenVINO/Phi-4-mini-instruct-fp16-ov"
|
| 84 |
+
model_path = "Phi-4-mini-instruct-fp16-ov"
|
| 85 |
+
hf_hub.snapshot_download(model_id, local_dir=model_path)
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
3. Run model inference:
|
| 89 |
+
```
|
| 90 |
+
import openvino_genai as ov_genai
|
| 91 |
+
device = "CPU"
|
| 92 |
+
pipe = ov_genai.LLMPipeline(model_path, device)
|
| 93 |
+
print(pipe.generate("What is OpenVINO?", max_length=200))
|
| 94 |
+
```
|
| 95 |
+
More GenAI usage examples can be found in OpenVINO GenAI library [docs](https://docs.openvino.ai/2025/openvino-workflow-generative/inference-with-genai.html) and [samples](https://github.com/openvinotoolkit/openvino.genai?tab=readme-ov-file#openvino-genai-samples)
|
| 96 |
+
|
| 97 |
+
You can find more detaild usage examples in OpenVINO Notebooks:
|
| 98 |
+
|
| 99 |
+
- [LLM](https://openvinotoolkit.github.io/openvino_notebooks/?search=LLM)
|
| 100 |
+
- [RAG text generation](https://openvinotoolkit.github.io/openvino_notebooks/?search=RAG+system&tasks=Text+Generation)
|
| 101 |
+
|
| 102 |
+
## Limitations
|
| 103 |
+
Check the original model card for [original model card](ttps://huggingface.co/microsoft/Phi-4-mini-instruct) for limitations.
|
| 104 |
+
|
| 105 |
+
## Legal information
|
| 106 |
+
The original model is distributed under [mit](https://huggingface.co/microsoft/Phi-4-mini-instruct/resolve/main/LICENSE) license. More details can be found in [original model card](ttps://huggingface.co/microsoft/Phi-4-mini-instruct).
|
| 107 |
+
|
| 108 |
+
## Disclaimer
|
| 109 |
+
Intel is committed to respecting human rights and avoiding causing or contributing to adverse impacts on human rights. See [Intel’s Global Human Rights Principles](https://www.intel.com/content/dam/www/central-libraries/us/en/documents/policy-human-rights.pdf). Intel’s products and software are intended only to be used in applications that do not cause or contribute to adverse impacts on human rights.
|
added_tokens.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<|/tool_call|>": 200026,
|
| 3 |
+
"<|/tool|>": 200024,
|
| 4 |
+
"<|assistant|>": 200019,
|
| 5 |
+
"<|end|>": 200020,
|
| 6 |
+
"<|system|>": 200022,
|
| 7 |
+
"<|tag|>": 200028,
|
| 8 |
+
"<|tool_call|>": 200025,
|
| 9 |
+
"<|tool_response|>": 200027,
|
| 10 |
+
"<|tool|>": 200023,
|
| 11 |
+
"<|user|>": 200021
|
| 12 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_attn_implementation_autoset": true,
|
| 3 |
+
"_name_or_path": "microsoft/Phi-4-mini-instruct",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"Phi3ForCausalLM"
|
| 6 |
+
],
|
| 7 |
+
"attention_bias": false,
|
| 8 |
+
"attention_dropout": 0.0,
|
| 9 |
+
"auto_map": {
|
| 10 |
+
"AutoConfig": "configuration_phi3.Phi3Config",
|
| 11 |
+
"AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM",
|
| 12 |
+
"AutoTokenizer": "microsoft/Phi-4-mini-instruct--Xenova/gpt-4o"
|
| 13 |
+
},
|
| 14 |
+
"bos_token_id": 199999,
|
| 15 |
+
"embd_pdrop": 0.0,
|
| 16 |
+
"eos_token_id": 199999,
|
| 17 |
+
"full_attn_mod": 1,
|
| 18 |
+
"hidden_act": "silu",
|
| 19 |
+
"hidden_size": 3072,
|
| 20 |
+
"initializer_range": 0.02,
|
| 21 |
+
"intermediate_size": 8192,
|
| 22 |
+
"interpolate_factor": 1,
|
| 23 |
+
"lm_head_bias": false,
|
| 24 |
+
"max_position_embeddings": 131072,
|
| 25 |
+
"mlp_bias": false,
|
| 26 |
+
"model_type": "phi3",
|
| 27 |
+
"num_attention_heads": 24,
|
| 28 |
+
"num_hidden_layers": 32,
|
| 29 |
+
"num_key_value_heads": 8,
|
| 30 |
+
"original_max_position_embeddings": 4096,
|
| 31 |
+
"pad_token_id": 199999,
|
| 32 |
+
"partial_rotary_factor": 0.75,
|
| 33 |
+
"resid_pdrop": 0.0,
|
| 34 |
+
"rms_norm_eps": 1e-05,
|
| 35 |
+
"rope_scaling": {
|
| 36 |
+
"long_factor": [
|
| 37 |
+
1,
|
| 38 |
+
1.118320672,
|
| 39 |
+
1.250641126,
|
| 40 |
+
1.398617824,
|
| 41 |
+
1.564103225,
|
| 42 |
+
1.74916897,
|
| 43 |
+
1.956131817,
|
| 44 |
+
2.187582649,
|
| 45 |
+
2.446418898,
|
| 46 |
+
2.735880826,
|
| 47 |
+
3.059592084,
|
| 48 |
+
3.421605075,
|
| 49 |
+
3.826451687,
|
| 50 |
+
4.279200023,
|
| 51 |
+
4.785517845,
|
| 52 |
+
5.351743533,
|
| 53 |
+
5.984965424,
|
| 54 |
+
6.693110555,
|
| 55 |
+
7.485043894,
|
| 56 |
+
8.370679318,
|
| 57 |
+
9.36110372,
|
| 58 |
+
10.4687158,
|
| 59 |
+
11.70738129,
|
| 60 |
+
13.09260651,
|
| 61 |
+
14.64173252,
|
| 62 |
+
16.37415215,
|
| 63 |
+
18.31155283,
|
| 64 |
+
20.47818807,
|
| 65 |
+
22.90118105,
|
| 66 |
+
25.61086418,
|
| 67 |
+
28.64115884,
|
| 68 |
+
32.03,
|
| 69 |
+
32.1,
|
| 70 |
+
32.13,
|
| 71 |
+
32.23,
|
| 72 |
+
32.6,
|
| 73 |
+
32.61,
|
| 74 |
+
32.64,
|
| 75 |
+
32.66,
|
| 76 |
+
32.7,
|
| 77 |
+
32.71,
|
| 78 |
+
32.93,
|
| 79 |
+
32.97,
|
| 80 |
+
33.28,
|
| 81 |
+
33.49,
|
| 82 |
+
33.5,
|
| 83 |
+
44.16,
|
| 84 |
+
47.77
|
| 85 |
+
],
|
| 86 |
+
"short_factor": [
|
| 87 |
+
1.0,
|
| 88 |
+
1.0,
|
| 89 |
+
1.0,
|
| 90 |
+
1.0,
|
| 91 |
+
1.0,
|
| 92 |
+
1.0,
|
| 93 |
+
1.0,
|
| 94 |
+
1.0,
|
| 95 |
+
1.0,
|
| 96 |
+
1.0,
|
| 97 |
+
1.0,
|
| 98 |
+
1.0,
|
| 99 |
+
1.0,
|
| 100 |
+
1.0,
|
| 101 |
+
1.0,
|
| 102 |
+
1.0,
|
| 103 |
+
1.0,
|
| 104 |
+
1.0,
|
| 105 |
+
1.0,
|
| 106 |
+
1.0,
|
| 107 |
+
1.0,
|
| 108 |
+
1.0,
|
| 109 |
+
1.0,
|
| 110 |
+
1.0,
|
| 111 |
+
1.0,
|
| 112 |
+
1.0,
|
| 113 |
+
1.0,
|
| 114 |
+
1.0,
|
| 115 |
+
1.0,
|
| 116 |
+
1.0,
|
| 117 |
+
1.0,
|
| 118 |
+
1.0,
|
| 119 |
+
1.0,
|
| 120 |
+
1.0,
|
| 121 |
+
1.0,
|
| 122 |
+
1.0,
|
| 123 |
+
1.0,
|
| 124 |
+
1.0,
|
| 125 |
+
1.0,
|
| 126 |
+
1.0,
|
| 127 |
+
1.0,
|
| 128 |
+
1.0,
|
| 129 |
+
1.0,
|
| 130 |
+
1.0,
|
| 131 |
+
1.0,
|
| 132 |
+
1.0,
|
| 133 |
+
1.0,
|
| 134 |
+
1.0
|
| 135 |
+
],
|
| 136 |
+
"type": "longrope"
|
| 137 |
+
},
|
| 138 |
+
"rope_theta": 10000.0,
|
| 139 |
+
"sliding_window": 262144,
|
| 140 |
+
"tie_word_embeddings": true,
|
| 141 |
+
"torch_dtype": "float16",
|
| 142 |
+
"transformers_version": "4.49.0",
|
| 143 |
+
"use_cache": true,
|
| 144 |
+
"vocab_size": 200064
|
| 145 |
+
}
|
configuration_phi3.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 19 |
+
from transformers.utils import logging
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class Phi3Config(PretrainedConfig):
|
| 26 |
+
r"""
|
| 27 |
+
This is the configuration class to store the configuration of a [`Phi3Model`]. It is used to instantiate a Phi-3
|
| 28 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 29 |
+
defaults will yield a similar configuration to that of the
|
| 30 |
+
[microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
|
| 31 |
+
|
| 32 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 33 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
vocab_size (`int`, *optional*, defaults to 32064):
|
| 37 |
+
Vocabulary size of the Phi-3 model. Defines the number of different tokens that can be represented by the
|
| 38 |
+
`inputs_ids` passed when calling [`Phi3Model`].
|
| 39 |
+
hidden_size (`int`, *optional*, defaults to 3072):
|
| 40 |
+
Dimension of the hidden representations.
|
| 41 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
| 42 |
+
Dimension of the MLP representations.
|
| 43 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 44 |
+
Number of hidden layers in the Transformer decoder.
|
| 45 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 46 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 47 |
+
num_key_value_heads (`int`, *optional*):
|
| 48 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 49 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 50 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 51 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 52 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 53 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 54 |
+
`num_attention_heads`.
|
| 55 |
+
resid_pdrop (`float`, *optional*, defaults to 0.0):
|
| 56 |
+
Dropout probability for mlp outputs.
|
| 57 |
+
embd_pdrop (`int`, *optional*, defaults to 0.0):
|
| 58 |
+
The dropout ratio for the embeddings.
|
| 59 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 60 |
+
The dropout ratio after computing the attention scores.
|
| 61 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 62 |
+
The non-linear activation function (function or string) in the decoder.
|
| 63 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 64 |
+
The maximum sequence length that this model might ever be used with.
|
| 65 |
+
original_max_position_embeddings (`int`, *optional*, defaults to 4096):
|
| 66 |
+
The maximum sequence length that this model was trained with. This is used to determine the size of the
|
| 67 |
+
original RoPE embeddings when using long scaling.
|
| 68 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 69 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 70 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 71 |
+
The epsilon value used for the RMSNorm.
|
| 72 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 73 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 74 |
+
relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
|
| 75 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 76 |
+
Whether to tie weight embeddings
|
| 77 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 78 |
+
The base period of the RoPE embeddings.
|
| 79 |
+
rope_scaling (`dict`, *optional*):
|
| 80 |
+
The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
|
| 81 |
+
contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be `longrope` and
|
| 82 |
+
the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
|
| 83 |
+
divided by the number of attention heads divided by 2.
|
| 84 |
+
partial_rotary_factor (`float`, *optional*, defaults to 1.0):
|
| 85 |
+
Percentage of the query and keys which will have rotary embedding. Must be between 0.0 and 1.0.
|
| 86 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 87 |
+
The id of the "beginning-of-sequence" token.
|
| 88 |
+
eos_token_id (`int`, *optional*, defaults to 32000):
|
| 89 |
+
The id of the "end-of-sequence" token.
|
| 90 |
+
pad_token_id (`int`, *optional*, defaults to 32000):
|
| 91 |
+
The id of the padding token.
|
| 92 |
+
sliding_window (`int`, *optional*):
|
| 93 |
+
Sliding window attention window size. If `None`, no sliding window is applied.
|
| 94 |
+
|
| 95 |
+
Example:
|
| 96 |
+
|
| 97 |
+
```python
|
| 98 |
+
>>> from transformers import Phi3Model, Phi3Config
|
| 99 |
+
|
| 100 |
+
>>> # Initializing a Phi-3 style configuration
|
| 101 |
+
>>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 102 |
+
|
| 103 |
+
>>> # Initializing a model from the configuration
|
| 104 |
+
>>> model = Phi3Model(configuration)
|
| 105 |
+
|
| 106 |
+
>>> # Accessing the model configuration
|
| 107 |
+
>>> configuration = model.config
|
| 108 |
+
```"""
|
| 109 |
+
|
| 110 |
+
model_type = "phi3"
|
| 111 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 112 |
+
|
| 113 |
+
def __init__(
|
| 114 |
+
self,
|
| 115 |
+
vocab_size=32064,
|
| 116 |
+
hidden_size=3072,
|
| 117 |
+
intermediate_size=8192,
|
| 118 |
+
num_hidden_layers=32,
|
| 119 |
+
num_attention_heads=32,
|
| 120 |
+
num_key_value_heads=None,
|
| 121 |
+
resid_pdrop=0.0,
|
| 122 |
+
embd_pdrop=0.0,
|
| 123 |
+
attention_dropout=0.0,
|
| 124 |
+
hidden_act="silu",
|
| 125 |
+
max_position_embeddings=4096,
|
| 126 |
+
original_max_position_embeddings=4096,
|
| 127 |
+
initializer_range=0.02,
|
| 128 |
+
rms_norm_eps=1e-5,
|
| 129 |
+
use_cache=True,
|
| 130 |
+
tie_word_embeddings=False,
|
| 131 |
+
rope_theta=10000.0,
|
| 132 |
+
rope_scaling=None,
|
| 133 |
+
partial_rotary_factor=1.0,
|
| 134 |
+
bos_token_id=1,
|
| 135 |
+
eos_token_id=32000,
|
| 136 |
+
pad_token_id=32000,
|
| 137 |
+
sliding_window=None,
|
| 138 |
+
**kwargs,
|
| 139 |
+
):
|
| 140 |
+
self.vocab_size = vocab_size
|
| 141 |
+
self.hidden_size = hidden_size
|
| 142 |
+
self.intermediate_size = intermediate_size
|
| 143 |
+
self.num_hidden_layers = num_hidden_layers
|
| 144 |
+
self.num_attention_heads = num_attention_heads
|
| 145 |
+
|
| 146 |
+
if num_key_value_heads is None:
|
| 147 |
+
num_key_value_heads = num_attention_heads
|
| 148 |
+
|
| 149 |
+
self.num_key_value_heads = num_key_value_heads
|
| 150 |
+
self.resid_pdrop = resid_pdrop
|
| 151 |
+
self.embd_pdrop = embd_pdrop
|
| 152 |
+
self.attention_dropout = attention_dropout
|
| 153 |
+
self.hidden_act = hidden_act
|
| 154 |
+
self.max_position_embeddings = max_position_embeddings
|
| 155 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
| 156 |
+
self.initializer_range = initializer_range
|
| 157 |
+
self.rms_norm_eps = rms_norm_eps
|
| 158 |
+
self.use_cache = use_cache
|
| 159 |
+
self.rope_theta = rope_theta
|
| 160 |
+
self.rope_scaling = rope_scaling
|
| 161 |
+
self.partial_rotary_factor = partial_rotary_factor
|
| 162 |
+
self._rope_scaling_adjustment()
|
| 163 |
+
self._rope_scaling_validation()
|
| 164 |
+
self.sliding_window = sliding_window
|
| 165 |
+
|
| 166 |
+
super().__init__(
|
| 167 |
+
bos_token_id=bos_token_id,
|
| 168 |
+
eos_token_id=eos_token_id,
|
| 169 |
+
pad_token_id=pad_token_id,
|
| 170 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 171 |
+
**kwargs,
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
def _rope_scaling_adjustment(self):
|
| 175 |
+
"""
|
| 176 |
+
Adjust the `type` of the `rope_scaling` configuration for backward compatibility.
|
| 177 |
+
"""
|
| 178 |
+
if self.rope_scaling is None:
|
| 179 |
+
return
|
| 180 |
+
|
| 181 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 182 |
+
|
| 183 |
+
# For backward compatibility if previous version used "su" or "yarn"
|
| 184 |
+
if rope_scaling_type is not None and rope_scaling_type in ["su", "yarn"]:
|
| 185 |
+
self.rope_scaling["type"] = "longrope"
|
| 186 |
+
|
| 187 |
+
def _rope_scaling_validation(self):
|
| 188 |
+
"""
|
| 189 |
+
Validate the `rope_scaling` configuration.
|
| 190 |
+
"""
|
| 191 |
+
if self.rope_scaling is None:
|
| 192 |
+
return
|
| 193 |
+
|
| 194 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
|
| 195 |
+
raise ValueError(
|
| 196 |
+
"`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
|
| 197 |
+
f"got {self.rope_scaling}"
|
| 198 |
+
)
|
| 199 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 200 |
+
rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
|
| 201 |
+
rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
|
| 202 |
+
if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
|
| 203 |
+
raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
|
| 204 |
+
if not (
|
| 205 |
+
isinstance(rope_scaling_short_factor, list)
|
| 206 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
|
| 207 |
+
):
|
| 208 |
+
raise ValueError(
|
| 209 |
+
f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
|
| 210 |
+
)
|
| 211 |
+
rotary_ndims = int(self.hidden_size // self.num_attention_heads * self.partial_rotary_factor)
|
| 212 |
+
if not len(rope_scaling_short_factor) == rotary_ndims // 2:
|
| 213 |
+
raise ValueError(
|
| 214 |
+
f"`rope_scaling`'s short_factor field must have length {rotary_ndims // 2}, got {len(rope_scaling_short_factor)}"
|
| 215 |
+
)
|
| 216 |
+
if not (
|
| 217 |
+
isinstance(rope_scaling_long_factor, list)
|
| 218 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
|
| 219 |
+
):
|
| 220 |
+
raise ValueError(
|
| 221 |
+
f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
|
| 222 |
+
)
|
| 223 |
+
if not len(rope_scaling_long_factor) == rotary_ndims // 2:
|
| 224 |
+
raise ValueError(
|
| 225 |
+
f"`rope_scaling`'s long_factor field must have length {rotary_ndims // 2}, got {len(rope_scaling_long_factor)}"
|
| 226 |
+
)
|
generation_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 199999,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
200020,
|
| 6 |
+
199999
|
| 7 |
+
],
|
| 8 |
+
"pad_token_id": 199999,
|
| 9 |
+
"transformers_version": "4.49.0"
|
| 10 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_phi3.py
ADDED
|
@@ -0,0 +1,1180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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 |
+
from typing import Callable, List, Optional, Tuple, Union
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
from torch import nn
|
| 22 |
+
|
| 23 |
+
from transformers.activations import ACT2FN
|
| 24 |
+
from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
|
| 25 |
+
from transformers.generation import GenerationMixin
|
| 26 |
+
from transformers.modeling_attn_mask_utils import AttentionMaskConverter
|
| 27 |
+
from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
|
| 28 |
+
from transformers.modeling_outputs import (
|
| 29 |
+
BaseModelOutputWithPast,
|
| 30 |
+
CausalLMOutputWithPast,
|
| 31 |
+
SequenceClassifierOutputWithPast,
|
| 32 |
+
TokenClassifierOutput,
|
| 33 |
+
)
|
| 34 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
|
| 35 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 36 |
+
from transformers.processing_utils import Unpack
|
| 37 |
+
from transformers.utils import (
|
| 38 |
+
LossKwargs,
|
| 39 |
+
add_code_sample_docstrings,
|
| 40 |
+
add_start_docstrings,
|
| 41 |
+
add_start_docstrings_to_model_forward,
|
| 42 |
+
logging,
|
| 43 |
+
replace_return_docstrings,
|
| 44 |
+
)
|
| 45 |
+
from transformers.utils.deprecation import deprecate_kwarg
|
| 46 |
+
from .configuration_phi3 import Phi3Config
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
logger = logging.get_logger(__name__)
|
| 50 |
+
|
| 51 |
+
_CHECKPOINT_FOR_DOC = "microsoft/Phi-3-mini-4k-instruct"
|
| 52 |
+
_CONFIG_FOR_DOC = "Phi3Config"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class Phi3MLP(nn.Module):
|
| 56 |
+
def __init__(self, config):
|
| 57 |
+
super().__init__()
|
| 58 |
+
|
| 59 |
+
self.config = config
|
| 60 |
+
self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
|
| 61 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 62 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
| 63 |
+
|
| 64 |
+
def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
|
| 65 |
+
up_states = self.gate_up_proj(hidden_states)
|
| 66 |
+
|
| 67 |
+
gate, up_states = up_states.chunk(2, dim=-1)
|
| 68 |
+
up_states = up_states * self.activation_fn(gate)
|
| 69 |
+
|
| 70 |
+
return self.down_proj(up_states)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def rotate_half(x):
|
| 74 |
+
"""Rotates half the hidden dims of the input."""
|
| 75 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 76 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 77 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 81 |
+
"""
|
| 82 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 83 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 84 |
+
"""
|
| 85 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 86 |
+
if n_rep == 1:
|
| 87 |
+
return hidden_states
|
| 88 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 89 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def eager_attention_forward(
|
| 93 |
+
module: nn.Module,
|
| 94 |
+
query: torch.Tensor,
|
| 95 |
+
key: torch.Tensor,
|
| 96 |
+
value: torch.Tensor,
|
| 97 |
+
attention_mask: Optional[torch.Tensor],
|
| 98 |
+
scaling: float,
|
| 99 |
+
dropout: float = 0.0,
|
| 100 |
+
**kwargs,
|
| 101 |
+
):
|
| 102 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 103 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 104 |
+
|
| 105 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 106 |
+
if attention_mask is not None:
|
| 107 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 108 |
+
attn_weights = attn_weights + causal_mask
|
| 109 |
+
|
| 110 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 111 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 112 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 113 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 114 |
+
|
| 115 |
+
return attn_output, attn_weights
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 119 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 120 |
+
|
| 121 |
+
Args:
|
| 122 |
+
q (`torch.Tensor`): The query tensor.
|
| 123 |
+
k (`torch.Tensor`): The key tensor.
|
| 124 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 125 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 126 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 127 |
+
Deprecated and unused.
|
| 128 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 129 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 130 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 131 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 132 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 133 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 134 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 135 |
+
Returns:
|
| 136 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 137 |
+
"""
|
| 138 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 139 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 140 |
+
|
| 141 |
+
rotary_dim = cos.shape[-1]
|
| 142 |
+
q_rot, q_pass = q[..., :rotary_dim], q[..., rotary_dim:]
|
| 143 |
+
k_rot, k_pass = k[..., :rotary_dim], k[..., rotary_dim:]
|
| 144 |
+
|
| 145 |
+
q_embed = torch.cat([(q_rot * cos) + (rotate_half(q_rot) * sin), q_pass], dim=-1)
|
| 146 |
+
k_embed = torch.cat([(k_rot * cos) + (rotate_half(k_rot) * sin), k_pass], dim=-1)
|
| 147 |
+
return q_embed, k_embed
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class Phi3Attention(nn.Module):
|
| 151 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 152 |
+
|
| 153 |
+
def __init__(self, config: Phi3Config, layer_idx: Optional[int] = None):
|
| 154 |
+
super().__init__()
|
| 155 |
+
self.config = config
|
| 156 |
+
self.layer_idx = layer_idx
|
| 157 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 158 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 159 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 160 |
+
self.scaling = self.head_dim**-0.5
|
| 161 |
+
self.attention_dropout = config.attention_dropout
|
| 162 |
+
self.is_causal = True
|
| 163 |
+
|
| 164 |
+
op_size = config.num_attention_heads * self.head_dim + 2 * (config.num_key_value_heads * self.head_dim)
|
| 165 |
+
self.o_proj = nn.Linear(config.num_attention_heads * self.head_dim, config.hidden_size, bias=False)
|
| 166 |
+
self.qkv_proj = nn.Linear(config.hidden_size, op_size, bias=False)
|
| 167 |
+
|
| 168 |
+
def forward(
|
| 169 |
+
self,
|
| 170 |
+
hidden_states: torch.Tensor,
|
| 171 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 172 |
+
attention_mask: Optional[torch.Tensor],
|
| 173 |
+
past_key_value: Optional[Cache] = None,
|
| 174 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 175 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 176 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
| 177 |
+
input_shape = hidden_states.shape[:-1]
|
| 178 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 179 |
+
|
| 180 |
+
qkv = self.qkv_proj(hidden_states)
|
| 181 |
+
query_pos = self.config.num_attention_heads * self.head_dim
|
| 182 |
+
query_states = qkv[..., :query_pos]
|
| 183 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
| 184 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
| 185 |
+
|
| 186 |
+
query_states = query_states.view(hidden_shape).transpose(1, 2)
|
| 187 |
+
key_states = key_states.view(hidden_shape).transpose(1, 2)
|
| 188 |
+
value_states = value_states.view(hidden_shape).transpose(1, 2)
|
| 189 |
+
|
| 190 |
+
cos, sin = position_embeddings
|
| 191 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 192 |
+
|
| 193 |
+
if past_key_value is not None:
|
| 194 |
+
# sin and cos are specific to RoPE models; cache_position needed for the static cache
|
| 195 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 196 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 197 |
+
|
| 198 |
+
attention_interface: Callable = eager_attention_forward
|
| 199 |
+
if self.config._attn_implementation != "eager":
|
| 200 |
+
if self.config._attn_implementation == "sdpa" and kwargs.get("output_attentions", False):
|
| 201 |
+
logger.warning_once(
|
| 202 |
+
"`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to "
|
| 203 |
+
'eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
| 204 |
+
)
|
| 205 |
+
else:
|
| 206 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 207 |
+
|
| 208 |
+
attn_output, attn_weights = attention_interface(
|
| 209 |
+
self,
|
| 210 |
+
query_states,
|
| 211 |
+
key_states,
|
| 212 |
+
value_states,
|
| 213 |
+
attention_mask,
|
| 214 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 215 |
+
scaling=self.scaling,
|
| 216 |
+
sliding_window=getattr(self.config, "sliding_window", None),
|
| 217 |
+
**kwargs,
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 221 |
+
attn_output = self.o_proj(attn_output)
|
| 222 |
+
return attn_output, attn_weights
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
class Phi3RMSNorm(nn.Module):
|
| 226 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 227 |
+
"""
|
| 228 |
+
Phi3RMSNorm is equivalent to T5LayerNorm
|
| 229 |
+
"""
|
| 230 |
+
super().__init__()
|
| 231 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 232 |
+
self.variance_epsilon = eps
|
| 233 |
+
|
| 234 |
+
def forward(self, hidden_states):
|
| 235 |
+
input_dtype = hidden_states.dtype
|
| 236 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 237 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 238 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 239 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 240 |
+
|
| 241 |
+
def extra_repr(self):
|
| 242 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
class Phi3DecoderLayer(nn.Module):
|
| 246 |
+
def __init__(self, config: Phi3Config, layer_idx: int):
|
| 247 |
+
super().__init__()
|
| 248 |
+
self.hidden_size = config.hidden_size
|
| 249 |
+
self.self_attn = Phi3Attention(config=config, layer_idx=layer_idx)
|
| 250 |
+
self.mlp = Phi3MLP(config)
|
| 251 |
+
self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 252 |
+
self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 253 |
+
self.config = config
|
| 254 |
+
self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
|
| 255 |
+
self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
|
| 256 |
+
|
| 257 |
+
def forward(
|
| 258 |
+
self,
|
| 259 |
+
hidden_states: torch.Tensor,
|
| 260 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 261 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 262 |
+
past_key_value: Optional[Cache] = None,
|
| 263 |
+
output_attentions: Optional[bool] = False,
|
| 264 |
+
use_cache: Optional[bool] = False,
|
| 265 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 266 |
+
position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
|
| 267 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 268 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
| 269 |
+
"""
|
| 270 |
+
Args:
|
| 271 |
+
hidden_states (`torch.FloatTensor`):
|
| 272 |
+
input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 273 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
| 274 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 275 |
+
position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
|
| 276 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
|
| 277 |
+
`[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
| 278 |
+
past_key_value (`Cache`, *optional*): cached past key and value projection states
|
| 279 |
+
output_attentions (`bool`, *optional*):
|
| 280 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 281 |
+
returned tensors for more detail.
|
| 282 |
+
use_cache (`bool`, *optional*):
|
| 283 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
| 284 |
+
(see `past_key_values`).
|
| 285 |
+
cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
|
| 286 |
+
Indices depicting the position of the input sequence tokens in the sequence
|
| 287 |
+
kwargs (`dict`, *optional*):
|
| 288 |
+
Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
|
| 289 |
+
into the model
|
| 290 |
+
"""
|
| 291 |
+
residual = hidden_states
|
| 292 |
+
|
| 293 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 294 |
+
|
| 295 |
+
# Self Attention
|
| 296 |
+
hidden_states, self_attn_weights = self.self_attn(
|
| 297 |
+
hidden_states=hidden_states,
|
| 298 |
+
attention_mask=attention_mask,
|
| 299 |
+
position_ids=position_ids,
|
| 300 |
+
past_key_value=past_key_value,
|
| 301 |
+
output_attentions=output_attentions,
|
| 302 |
+
use_cache=use_cache,
|
| 303 |
+
cache_position=cache_position,
|
| 304 |
+
position_embeddings=position_embeddings,
|
| 305 |
+
**kwargs,
|
| 306 |
+
)
|
| 307 |
+
hidden_states = residual + self.resid_attn_dropout(hidden_states) # main diff with Llama
|
| 308 |
+
|
| 309 |
+
residual = hidden_states
|
| 310 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 311 |
+
hidden_states = self.mlp(hidden_states)
|
| 312 |
+
hidden_states = residual + self.resid_mlp_dropout(hidden_states) # main diff with Llama
|
| 313 |
+
|
| 314 |
+
outputs = (hidden_states,)
|
| 315 |
+
if output_attentions:
|
| 316 |
+
outputs += (self_attn_weights,)
|
| 317 |
+
|
| 318 |
+
return outputs
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
class Phi3RotaryEmbedding(nn.Module):
|
| 322 |
+
def __init__(self, config: Phi3Config, device=None):
|
| 323 |
+
super().__init__()
|
| 324 |
+
# BC: "rope_type" was originally "type"
|
| 325 |
+
if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
|
| 326 |
+
self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
|
| 327 |
+
else:
|
| 328 |
+
self.rope_type = "default"
|
| 329 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 330 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 331 |
+
|
| 332 |
+
self.config = config
|
| 333 |
+
self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 334 |
+
|
| 335 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
|
| 336 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 337 |
+
self.original_inv_freq = self.inv_freq
|
| 338 |
+
|
| 339 |
+
def _dynamic_frequency_update(self, position_ids, device):
|
| 340 |
+
"""
|
| 341 |
+
dynamic RoPE layers should recompute `inv_freq` in the following situations:
|
| 342 |
+
1 - growing beyond the cached sequence length (allow scaling)
|
| 343 |
+
2 - the current sequence length is in the original scale (avoid losing precision with small sequences)
|
| 344 |
+
"""
|
| 345 |
+
seq_len = torch.max(position_ids) + 1
|
| 346 |
+
if seq_len > self.max_seq_len_cached: # growth
|
| 347 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device, seq_len=seq_len)
|
| 348 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False) # TODO joao: may break with compilation
|
| 349 |
+
self.max_seq_len_cached = seq_len
|
| 350 |
+
|
| 351 |
+
if seq_len < self.original_max_seq_len and self.max_seq_len_cached > self.original_max_seq_len: # reset
|
| 352 |
+
# This .to() is needed if the model has been moved to a device after being initialized (because
|
| 353 |
+
# the buffer is automatically moved, but not the original copy)
|
| 354 |
+
self.original_inv_freq = self.original_inv_freq.to(device)
|
| 355 |
+
self.register_buffer("inv_freq", self.original_inv_freq, persistent=False)
|
| 356 |
+
self.max_seq_len_cached = self.original_max_seq_len
|
| 357 |
+
|
| 358 |
+
@torch.no_grad()
|
| 359 |
+
def forward(self, x, position_ids):
|
| 360 |
+
if "dynamic" in self.rope_type:
|
| 361 |
+
self._dynamic_frequency_update(position_ids, device=x.device)
|
| 362 |
+
elif self.rope_type == "longrope":
|
| 363 |
+
self._longrope_frequency_update(position_ids, device=x.device)
|
| 364 |
+
|
| 365 |
+
# Core RoPE block
|
| 366 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
| 367 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 368 |
+
# Force float32 (see https://github.com/huggingface/transformers/pull/29285)
|
| 369 |
+
device_type = x.device.type
|
| 370 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
| 371 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 372 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 373 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 374 |
+
cos = emb.cos()
|
| 375 |
+
sin = emb.sin()
|
| 376 |
+
|
| 377 |
+
# Advanced RoPE types (e.g. yarn) apply a post-processing scaling factor, equivalent to scaling attention
|
| 378 |
+
cos = cos * self.attention_scaling
|
| 379 |
+
sin = sin * self.attention_scaling
|
| 380 |
+
|
| 381 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 382 |
+
|
| 383 |
+
def _longrope_frequency_update(self, position_ids, device):
|
| 384 |
+
"""Longrope uses long factor if sequence is larger than original pretraining length, short otherwise."""
|
| 385 |
+
seq_len = torch.max(position_ids) + 1
|
| 386 |
+
if hasattr(self.config, "original_max_position_embeddings"):
|
| 387 |
+
original_max_position_embeddings = self.config.original_max_position_embeddings
|
| 388 |
+
else:
|
| 389 |
+
original_max_position_embeddings = self.config.max_position_embeddings
|
| 390 |
+
if seq_len > original_max_position_embeddings:
|
| 391 |
+
if not hasattr(self, "long_inv_freq"):
|
| 392 |
+
self.long_inv_freq, _ = self.rope_init_fn(
|
| 393 |
+
self.config, device, seq_len=original_max_position_embeddings + 1
|
| 394 |
+
)
|
| 395 |
+
self.register_buffer("inv_freq", self.long_inv_freq, persistent=False)
|
| 396 |
+
else:
|
| 397 |
+
# This .to() is needed if the model has been moved to a device after being initialized (because
|
| 398 |
+
# the buffer is automatically moved, but not the original copy)
|
| 399 |
+
self.original_inv_freq = self.original_inv_freq.to(device)
|
| 400 |
+
self.register_buffer("inv_freq", self.original_inv_freq, persistent=False)
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
PHI3_START_DOCSTRING = r"""
|
| 404 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
| 405 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
| 406 |
+
etc.)
|
| 407 |
+
|
| 408 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
| 409 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
| 410 |
+
and behavior.
|
| 411 |
+
|
| 412 |
+
Parameters:
|
| 413 |
+
config ([`Phi3Config`]):
|
| 414 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
| 415 |
+
load the weights associated with the model, only the configuration. Check out the
|
| 416 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
| 417 |
+
"""
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
@add_start_docstrings(
|
| 421 |
+
"The bare Phi3 Model outputting raw hidden-states without any specific head on top.",
|
| 422 |
+
PHI3_START_DOCSTRING,
|
| 423 |
+
)
|
| 424 |
+
class Phi3PreTrainedModel(PreTrainedModel):
|
| 425 |
+
config_class = Phi3Config
|
| 426 |
+
base_model_prefix = "model"
|
| 427 |
+
supports_gradient_checkpointing = True
|
| 428 |
+
_no_split_modules = ["Phi3DecoderLayer"]
|
| 429 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 430 |
+
_supports_flash_attn_2 = True
|
| 431 |
+
_supports_sdpa = True
|
| 432 |
+
_supports_flex_attn = True
|
| 433 |
+
_supports_cache_class = True
|
| 434 |
+
_supports_quantized_cache = True
|
| 435 |
+
_supports_static_cache = True
|
| 436 |
+
_supports_attention_backend = True
|
| 437 |
+
_version = "0.0.5"
|
| 438 |
+
|
| 439 |
+
def _init_weights(self, module):
|
| 440 |
+
std = self.config.initializer_range
|
| 441 |
+
if isinstance(module, nn.Linear):
|
| 442 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 443 |
+
if module.bias is not None:
|
| 444 |
+
module.bias.data.zero_()
|
| 445 |
+
elif isinstance(module, nn.Embedding):
|
| 446 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 447 |
+
if module.padding_idx is not None:
|
| 448 |
+
module.weight.data[module.padding_idx].zero_()
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
PHI3_INPUTS_DOCSTRING = r"""
|
| 452 |
+
Args:
|
| 453 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 454 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 455 |
+
it.
|
| 456 |
+
|
| 457 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 458 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 459 |
+
|
| 460 |
+
[What are input IDs?](../glossary#input-ids)
|
| 461 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 462 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 463 |
+
|
| 464 |
+
- 1 for tokens that are **not masked**,
|
| 465 |
+
- 0 for tokens that are **masked**.
|
| 466 |
+
|
| 467 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 468 |
+
|
| 469 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 470 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 471 |
+
|
| 472 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
| 473 |
+
`past_key_values`).
|
| 474 |
+
|
| 475 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
| 476 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
| 477 |
+
information on the default strategy.
|
| 478 |
+
|
| 479 |
+
- 1 indicates the head is **not masked**,
|
| 480 |
+
- 0 indicates the head is **masked**.
|
| 481 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 482 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 483 |
+
config.n_positions - 1]`.
|
| 484 |
+
|
| 485 |
+
[What are position IDs?](../glossary#position-ids)
|
| 486 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 487 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
| 488 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
| 489 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
| 490 |
+
|
| 491 |
+
Two formats are allowed:
|
| 492 |
+
- a [`~cache_utils.Cache`] instance, see our
|
| 493 |
+
[kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
|
| 494 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
| 495 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
| 496 |
+
cache format.
|
| 497 |
+
|
| 498 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
| 499 |
+
legacy cache format will be returned.
|
| 500 |
+
|
| 501 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
| 502 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
| 503 |
+
of shape `(batch_size, sequence_length)`.
|
| 504 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 505 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
| 506 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
| 507 |
+
model's internal embedding lookup matrix.
|
| 508 |
+
use_cache (`bool`, *optional*):
|
| 509 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
| 510 |
+
`past_key_values`).
|
| 511 |
+
output_attentions (`bool`, *optional*):
|
| 512 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
| 513 |
+
tensors for more detail.
|
| 514 |
+
output_hidden_states (`bool`, *optional*):
|
| 515 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
| 516 |
+
more detail.
|
| 517 |
+
return_dict (`bool`, *optional*):
|
| 518 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 519 |
+
cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
|
| 520 |
+
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
|
| 521 |
+
this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
|
| 522 |
+
the complete sequence length.
|
| 523 |
+
"""
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
@add_start_docstrings(
|
| 527 |
+
"The bare Phi3 Model outputting raw hidden-states without any specific head on top.",
|
| 528 |
+
PHI3_START_DOCSTRING,
|
| 529 |
+
)
|
| 530 |
+
class Phi3Model(Phi3PreTrainedModel):
|
| 531 |
+
"""
|
| 532 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Phi3DecoderLayer`]
|
| 533 |
+
|
| 534 |
+
Args:
|
| 535 |
+
config: Phi3Config
|
| 536 |
+
"""
|
| 537 |
+
|
| 538 |
+
def __init__(self, config: Phi3Config):
|
| 539 |
+
super().__init__(config)
|
| 540 |
+
self.padding_idx = config.pad_token_id
|
| 541 |
+
self.vocab_size = config.vocab_size
|
| 542 |
+
|
| 543 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 544 |
+
self.layers = nn.ModuleList(
|
| 545 |
+
[Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 546 |
+
)
|
| 547 |
+
self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 548 |
+
self.rotary_emb = Phi3RotaryEmbedding(config=config)
|
| 549 |
+
self.gradient_checkpointing = False
|
| 550 |
+
|
| 551 |
+
# Initialize weights and apply final processing
|
| 552 |
+
self.post_init()
|
| 553 |
+
|
| 554 |
+
def get_input_embeddings(self):
|
| 555 |
+
return self.embed_tokens
|
| 556 |
+
|
| 557 |
+
def set_input_embeddings(self, value):
|
| 558 |
+
self.embed_tokens = value
|
| 559 |
+
|
| 560 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 561 |
+
def forward(
|
| 562 |
+
self,
|
| 563 |
+
input_ids: torch.LongTensor = None,
|
| 564 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 565 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 566 |
+
past_key_values: Optional[Cache] = None,
|
| 567 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 568 |
+
use_cache: Optional[bool] = None,
|
| 569 |
+
output_attentions: Optional[bool] = None,
|
| 570 |
+
output_hidden_states: Optional[bool] = None,
|
| 571 |
+
return_dict: Optional[bool] = None,
|
| 572 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 573 |
+
**flash_attn_kwargs: Unpack[FlashAttentionKwargs],
|
| 574 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 575 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 576 |
+
output_hidden_states = (
|
| 577 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 578 |
+
)
|
| 579 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 580 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 581 |
+
|
| 582 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 583 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 584 |
+
|
| 585 |
+
if self.gradient_checkpointing and self.training and use_cache:
|
| 586 |
+
logger.warning_once(
|
| 587 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
|
| 588 |
+
)
|
| 589 |
+
use_cache = False
|
| 590 |
+
|
| 591 |
+
if inputs_embeds is None:
|
| 592 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 593 |
+
|
| 594 |
+
if use_cache and past_key_values is None:
|
| 595 |
+
past_key_values = DynamicCache()
|
| 596 |
+
|
| 597 |
+
if cache_position is None:
|
| 598 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 599 |
+
cache_position = torch.arange(
|
| 600 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 601 |
+
)
|
| 602 |
+
|
| 603 |
+
if position_ids is None:
|
| 604 |
+
position_ids = cache_position.unsqueeze(0)
|
| 605 |
+
|
| 606 |
+
causal_mask = self._update_causal_mask(
|
| 607 |
+
attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
|
| 608 |
+
)
|
| 609 |
+
|
| 610 |
+
hidden_states = inputs_embeds
|
| 611 |
+
|
| 612 |
+
# create position embeddings to be shared across the decoder layers
|
| 613 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 614 |
+
|
| 615 |
+
# decoder layers
|
| 616 |
+
all_hidden_states = () if output_hidden_states else None
|
| 617 |
+
all_self_attns = () if output_attentions else None
|
| 618 |
+
|
| 619 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 620 |
+
if output_hidden_states:
|
| 621 |
+
all_hidden_states += (hidden_states,)
|
| 622 |
+
|
| 623 |
+
if self.gradient_checkpointing and self.training:
|
| 624 |
+
layer_outputs = self._gradient_checkpointing_func(
|
| 625 |
+
decoder_layer.__call__,
|
| 626 |
+
hidden_states,
|
| 627 |
+
causal_mask,
|
| 628 |
+
position_ids,
|
| 629 |
+
past_key_values,
|
| 630 |
+
output_attentions,
|
| 631 |
+
use_cache,
|
| 632 |
+
cache_position,
|
| 633 |
+
position_embeddings,
|
| 634 |
+
)
|
| 635 |
+
else:
|
| 636 |
+
layer_outputs = decoder_layer(
|
| 637 |
+
hidden_states,
|
| 638 |
+
attention_mask=causal_mask,
|
| 639 |
+
position_ids=position_ids,
|
| 640 |
+
past_key_value=past_key_values,
|
| 641 |
+
output_attentions=output_attentions,
|
| 642 |
+
use_cache=use_cache,
|
| 643 |
+
cache_position=cache_position,
|
| 644 |
+
position_embeddings=position_embeddings,
|
| 645 |
+
**flash_attn_kwargs,
|
| 646 |
+
)
|
| 647 |
+
|
| 648 |
+
hidden_states = layer_outputs[0]
|
| 649 |
+
|
| 650 |
+
if output_attentions:
|
| 651 |
+
all_self_attns += (layer_outputs[1],)
|
| 652 |
+
|
| 653 |
+
hidden_states = self.norm(hidden_states)
|
| 654 |
+
|
| 655 |
+
# add hidden states from the last decoder layer
|
| 656 |
+
if output_hidden_states:
|
| 657 |
+
all_hidden_states += (hidden_states,)
|
| 658 |
+
|
| 659 |
+
output = BaseModelOutputWithPast(
|
| 660 |
+
last_hidden_state=hidden_states,
|
| 661 |
+
past_key_values=past_key_values if use_cache else None,
|
| 662 |
+
hidden_states=all_hidden_states,
|
| 663 |
+
attentions=all_self_attns,
|
| 664 |
+
)
|
| 665 |
+
return output if return_dict else output.to_tuple()
|
| 666 |
+
|
| 667 |
+
def _update_causal_mask(
|
| 668 |
+
self,
|
| 669 |
+
attention_mask: torch.Tensor,
|
| 670 |
+
input_tensor: torch.Tensor,
|
| 671 |
+
cache_position: torch.Tensor,
|
| 672 |
+
past_key_values: Cache,
|
| 673 |
+
output_attentions: bool,
|
| 674 |
+
):
|
| 675 |
+
if self.config._attn_implementation == "flash_attention_2":
|
| 676 |
+
if attention_mask is not None and past_key_values is not None:
|
| 677 |
+
is_padding_right = attention_mask[:, -1].sum().item() != input_tensor.size()[0]
|
| 678 |
+
if is_padding_right:
|
| 679 |
+
raise ValueError(
|
| 680 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
| 681 |
+
" this may lead to unexpected behaviour for Flash Attention version of Phi3. Make sure to "
|
| 682 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
| 683 |
+
)
|
| 684 |
+
if attention_mask is not None and 0.0 in attention_mask:
|
| 685 |
+
return attention_mask
|
| 686 |
+
return None
|
| 687 |
+
|
| 688 |
+
# For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
|
| 689 |
+
# order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
|
| 690 |
+
# to infer the attention mask.
|
| 691 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 692 |
+
using_static_cache = isinstance(past_key_values, StaticCache)
|
| 693 |
+
using_sliding_window_cache = isinstance(past_key_values, SlidingWindowCache)
|
| 694 |
+
|
| 695 |
+
# When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
|
| 696 |
+
if (
|
| 697 |
+
self.config._attn_implementation == "sdpa"
|
| 698 |
+
and not (using_static_cache or using_sliding_window_cache)
|
| 699 |
+
and not output_attentions
|
| 700 |
+
):
|
| 701 |
+
if AttentionMaskConverter._ignore_causal_mask_sdpa(
|
| 702 |
+
attention_mask,
|
| 703 |
+
inputs_embeds=input_tensor,
|
| 704 |
+
past_key_values_length=past_seen_tokens,
|
| 705 |
+
sliding_window=self.config.sliding_window,
|
| 706 |
+
is_training=self.training,
|
| 707 |
+
):
|
| 708 |
+
return None
|
| 709 |
+
|
| 710 |
+
dtype, device = input_tensor.dtype, input_tensor.device
|
| 711 |
+
min_dtype = torch.finfo(dtype).min
|
| 712 |
+
sequence_length = input_tensor.shape[1]
|
| 713 |
+
# SlidingWindowCache or StaticCache
|
| 714 |
+
if using_sliding_window_cache or using_static_cache:
|
| 715 |
+
target_length = past_key_values.get_max_cache_shape()
|
| 716 |
+
# DynamicCache or no cache
|
| 717 |
+
else:
|
| 718 |
+
target_length = (
|
| 719 |
+
attention_mask.shape[-1]
|
| 720 |
+
if isinstance(attention_mask, torch.Tensor)
|
| 721 |
+
else past_seen_tokens + sequence_length + 1
|
| 722 |
+
)
|
| 723 |
+
|
| 724 |
+
# In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
|
| 725 |
+
causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
|
| 726 |
+
attention_mask,
|
| 727 |
+
sequence_length=sequence_length,
|
| 728 |
+
target_length=target_length,
|
| 729 |
+
dtype=dtype,
|
| 730 |
+
device=device,
|
| 731 |
+
cache_position=cache_position,
|
| 732 |
+
batch_size=input_tensor.shape[0],
|
| 733 |
+
config=self.config,
|
| 734 |
+
past_key_values=past_key_values,
|
| 735 |
+
)
|
| 736 |
+
|
| 737 |
+
if (
|
| 738 |
+
self.config._attn_implementation == "sdpa"
|
| 739 |
+
and attention_mask is not None
|
| 740 |
+
and attention_mask.device.type in ["cuda", "xpu"]
|
| 741 |
+
and not output_attentions
|
| 742 |
+
):
|
| 743 |
+
# Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
|
| 744 |
+
# using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
|
| 745 |
+
# Details: https://github.com/pytorch/pytorch/issues/110213
|
| 746 |
+
causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
|
| 747 |
+
|
| 748 |
+
return causal_mask
|
| 749 |
+
|
| 750 |
+
@staticmethod
|
| 751 |
+
def _prepare_4d_causal_attention_mask_with_cache_position(
|
| 752 |
+
attention_mask: torch.Tensor,
|
| 753 |
+
sequence_length: int,
|
| 754 |
+
target_length: int,
|
| 755 |
+
dtype: torch.dtype,
|
| 756 |
+
device: torch.device,
|
| 757 |
+
cache_position: torch.Tensor,
|
| 758 |
+
batch_size: int,
|
| 759 |
+
config: Phi3Config,
|
| 760 |
+
past_key_values: Cache,
|
| 761 |
+
):
|
| 762 |
+
"""
|
| 763 |
+
Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
|
| 764 |
+
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
|
| 765 |
+
|
| 766 |
+
Args:
|
| 767 |
+
attention_mask (`torch.Tensor`):
|
| 768 |
+
A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
|
| 769 |
+
sequence_length (`int`):
|
| 770 |
+
The sequence length being processed.
|
| 771 |
+
target_length (`int`):
|
| 772 |
+
The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
|
| 773 |
+
dtype (`torch.dtype`):
|
| 774 |
+
The dtype to use for the 4D attention mask.
|
| 775 |
+
device (`torch.device`):
|
| 776 |
+
The device to plcae the 4D attention mask on.
|
| 777 |
+
cache_position (`torch.Tensor`):
|
| 778 |
+
Indices depicting the position of the input sequence tokens in the sequence.
|
| 779 |
+
batch_size (`torch.Tensor`):
|
| 780 |
+
Batch size.
|
| 781 |
+
config (`Phi3Config`):
|
| 782 |
+
The model's configuration class
|
| 783 |
+
past_key_values (`Cache`):
|
| 784 |
+
The cache class that is being used currently to generate
|
| 785 |
+
"""
|
| 786 |
+
if attention_mask is not None and attention_mask.dim() == 4:
|
| 787 |
+
# In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
|
| 788 |
+
causal_mask = attention_mask
|
| 789 |
+
else:
|
| 790 |
+
min_dtype = torch.finfo(dtype).min
|
| 791 |
+
causal_mask = torch.full(
|
| 792 |
+
(sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
|
| 793 |
+
)
|
| 794 |
+
diagonal_attend_mask = torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
|
| 795 |
+
if config.sliding_window is not None:
|
| 796 |
+
# if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
|
| 797 |
+
# the check is needed to verify is current checkpoint was trained with sliding window or not
|
| 798 |
+
if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
|
| 799 |
+
sliding_attend_mask = torch.arange(target_length, device=device) <= (
|
| 800 |
+
cache_position.reshape(-1, 1) - config.sliding_window
|
| 801 |
+
)
|
| 802 |
+
diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
|
| 803 |
+
causal_mask *= diagonal_attend_mask
|
| 804 |
+
causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
|
| 805 |
+
if attention_mask is not None:
|
| 806 |
+
causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
|
| 807 |
+
if attention_mask.shape[-1] > target_length:
|
| 808 |
+
attention_mask = attention_mask[:, :target_length]
|
| 809 |
+
mask_length = attention_mask.shape[-1]
|
| 810 |
+
padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
|
| 811 |
+
causal_mask.device
|
| 812 |
+
)
|
| 813 |
+
padding_mask = padding_mask == 0
|
| 814 |
+
causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
|
| 815 |
+
padding_mask, min_dtype
|
| 816 |
+
)
|
| 817 |
+
return causal_mask
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ...
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
class Phi3ForCausalLM(Phi3PreTrainedModel, GenerationMixin):
|
| 824 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 825 |
+
_tp_plan = {"lm_head": "colwise_rep"}
|
| 826 |
+
_pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 827 |
+
|
| 828 |
+
def __init__(self, config):
|
| 829 |
+
super().__init__(config)
|
| 830 |
+
self.model = Phi3Model(config)
|
| 831 |
+
self.vocab_size = config.vocab_size
|
| 832 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 833 |
+
|
| 834 |
+
# Initialize weights and apply final processing
|
| 835 |
+
self.post_init()
|
| 836 |
+
|
| 837 |
+
def get_input_embeddings(self):
|
| 838 |
+
return self.model.embed_tokens
|
| 839 |
+
|
| 840 |
+
def set_input_embeddings(self, value):
|
| 841 |
+
self.model.embed_tokens = value
|
| 842 |
+
|
| 843 |
+
def get_output_embeddings(self):
|
| 844 |
+
return self.lm_head
|
| 845 |
+
|
| 846 |
+
def set_output_embeddings(self, new_embeddings):
|
| 847 |
+
self.lm_head = new_embeddings
|
| 848 |
+
|
| 849 |
+
def set_decoder(self, decoder):
|
| 850 |
+
self.model = decoder
|
| 851 |
+
|
| 852 |
+
def get_decoder(self):
|
| 853 |
+
return self.model
|
| 854 |
+
|
| 855 |
+
@deprecate_kwarg("num_logits_to_keep", version="4.50", new_name="logits_to_keep")
|
| 856 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 857 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
| 858 |
+
def forward(
|
| 859 |
+
self,
|
| 860 |
+
input_ids: torch.LongTensor = None,
|
| 861 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 862 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 863 |
+
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
|
| 864 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 865 |
+
labels: Optional[torch.LongTensor] = None,
|
| 866 |
+
use_cache: Optional[bool] = None,
|
| 867 |
+
output_attentions: Optional[bool] = None,
|
| 868 |
+
output_hidden_states: Optional[bool] = None,
|
| 869 |
+
return_dict: Optional[bool] = None,
|
| 870 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 871 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 872 |
+
**kwargs: Unpack[KwargsForCausalLM],
|
| 873 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 874 |
+
r"""
|
| 875 |
+
Args:
|
| 876 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 877 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 878 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 879 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 880 |
+
|
| 881 |
+
logits_to_keep (`int` or `torch.Tensor`, *optional*):
|
| 882 |
+
If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
|
| 883 |
+
`input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
|
| 884 |
+
token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
|
| 885 |
+
If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
|
| 886 |
+
This is useful when using packed tensor format (single dimension for batch and sequence length).
|
| 887 |
+
|
| 888 |
+
Returns:
|
| 889 |
+
|
| 890 |
+
Example:
|
| 891 |
+
|
| 892 |
+
```python
|
| 893 |
+
>>> from transformers import AutoTokenizer, Phi3ForCausalLM
|
| 894 |
+
|
| 895 |
+
>>> model = Phi3ForCausalLM.from_pretrained("meta-phi3/Phi3-2-7b-hf")
|
| 896 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("meta-phi3/Phi3-2-7b-hf")
|
| 897 |
+
|
| 898 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 899 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 900 |
+
|
| 901 |
+
>>> # Generate
|
| 902 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 903 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 904 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 905 |
+
```"""
|
| 906 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 907 |
+
output_hidden_states = (
|
| 908 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 909 |
+
)
|
| 910 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 911 |
+
|
| 912 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 913 |
+
outputs = self.model(
|
| 914 |
+
input_ids=input_ids,
|
| 915 |
+
attention_mask=attention_mask,
|
| 916 |
+
position_ids=position_ids,
|
| 917 |
+
past_key_values=past_key_values,
|
| 918 |
+
inputs_embeds=inputs_embeds,
|
| 919 |
+
use_cache=use_cache,
|
| 920 |
+
output_attentions=output_attentions,
|
| 921 |
+
output_hidden_states=output_hidden_states,
|
| 922 |
+
return_dict=return_dict,
|
| 923 |
+
cache_position=cache_position,
|
| 924 |
+
**kwargs,
|
| 925 |
+
)
|
| 926 |
+
|
| 927 |
+
hidden_states = outputs[0]
|
| 928 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 929 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 930 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 931 |
+
|
| 932 |
+
loss = None
|
| 933 |
+
if labels is not None:
|
| 934 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
|
| 935 |
+
|
| 936 |
+
if not return_dict:
|
| 937 |
+
output = (logits,) + outputs[1:]
|
| 938 |
+
return (loss,) + output if loss is not None else output
|
| 939 |
+
|
| 940 |
+
return CausalLMOutputWithPast(
|
| 941 |
+
loss=loss,
|
| 942 |
+
logits=logits,
|
| 943 |
+
past_key_values=outputs.past_key_values,
|
| 944 |
+
hidden_states=outputs.hidden_states,
|
| 945 |
+
attentions=outputs.attentions,
|
| 946 |
+
)
|
| 947 |
+
|
| 948 |
+
def prepare_inputs_for_generation(
|
| 949 |
+
self,
|
| 950 |
+
input_ids,
|
| 951 |
+
past_key_values=None,
|
| 952 |
+
attention_mask=None,
|
| 953 |
+
inputs_embeds=None,
|
| 954 |
+
cache_position=None,
|
| 955 |
+
position_ids=None,
|
| 956 |
+
use_cache=True,
|
| 957 |
+
logits_to_keep=None,
|
| 958 |
+
**kwargs,
|
| 959 |
+
):
|
| 960 |
+
# Overwritten -- this model may need to switch between short and long rope, invalidating the cache in the
|
| 961 |
+
# process
|
| 962 |
+
|
| 963 |
+
# When the first time input length reached long and short factor switching point, enforce re-compute cache
|
| 964 |
+
# It will cause downside of slower at this single token position, however, better than current failure.
|
| 965 |
+
if (
|
| 966 |
+
past_key_values
|
| 967 |
+
and self.config.rope_scaling
|
| 968 |
+
and input_ids.shape[1] >= self.config.original_max_position_embeddings + 1
|
| 969 |
+
):
|
| 970 |
+
past_length = cache_position[0]
|
| 971 |
+
if past_length <= self.config.original_max_position_embeddings:
|
| 972 |
+
past_key_values = None
|
| 973 |
+
|
| 974 |
+
model_inputs = super().prepare_inputs_for_generation(
|
| 975 |
+
input_ids=input_ids,
|
| 976 |
+
past_key_values=past_key_values,
|
| 977 |
+
attention_mask=attention_mask,
|
| 978 |
+
inputs_embeds=inputs_embeds,
|
| 979 |
+
cache_position=cache_position,
|
| 980 |
+
position_ids=position_ids,
|
| 981 |
+
use_cache=use_cache,
|
| 982 |
+
logits_to_keep=logits_to_keep,
|
| 983 |
+
**kwargs,
|
| 984 |
+
)
|
| 985 |
+
return model_inputs
|
| 986 |
+
|
| 987 |
+
|
| 988 |
+
@add_start_docstrings(
|
| 989 |
+
"""
|
| 990 |
+
The Phi3 Model transformer with a sequence classification head on top (linear layer).
|
| 991 |
+
|
| 992 |
+
[`Phi3ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
| 993 |
+
(e.g. GPT-2) do.
|
| 994 |
+
|
| 995 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
| 996 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
| 997 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
| 998 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
| 999 |
+
each row of the batch).
|
| 1000 |
+
""",
|
| 1001 |
+
PHI3_START_DOCSTRING,
|
| 1002 |
+
)
|
| 1003 |
+
class Phi3ForSequenceClassification(Phi3PreTrainedModel):
|
| 1004 |
+
def __init__(self, config):
|
| 1005 |
+
super().__init__(config)
|
| 1006 |
+
self.num_labels = config.num_labels
|
| 1007 |
+
self.model = Phi3Model(config)
|
| 1008 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
| 1009 |
+
|
| 1010 |
+
# Initialize weights and apply final processing
|
| 1011 |
+
self.post_init()
|
| 1012 |
+
|
| 1013 |
+
def get_input_embeddings(self):
|
| 1014 |
+
return self.model.embed_tokens
|
| 1015 |
+
|
| 1016 |
+
def set_input_embeddings(self, value):
|
| 1017 |
+
self.model.embed_tokens = value
|
| 1018 |
+
|
| 1019 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1020 |
+
def forward(
|
| 1021 |
+
self,
|
| 1022 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1023 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1024 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1025 |
+
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
|
| 1026 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1027 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1028 |
+
use_cache: Optional[bool] = None,
|
| 1029 |
+
output_attentions: Optional[bool] = None,
|
| 1030 |
+
output_hidden_states: Optional[bool] = None,
|
| 1031 |
+
return_dict: Optional[bool] = None,
|
| 1032 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
| 1033 |
+
r"""
|
| 1034 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1035 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1036 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1037 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1038 |
+
"""
|
| 1039 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1040 |
+
|
| 1041 |
+
transformer_outputs = self.model(
|
| 1042 |
+
input_ids,
|
| 1043 |
+
attention_mask=attention_mask,
|
| 1044 |
+
position_ids=position_ids,
|
| 1045 |
+
past_key_values=past_key_values,
|
| 1046 |
+
inputs_embeds=inputs_embeds,
|
| 1047 |
+
use_cache=use_cache,
|
| 1048 |
+
output_attentions=output_attentions,
|
| 1049 |
+
output_hidden_states=output_hidden_states,
|
| 1050 |
+
return_dict=return_dict,
|
| 1051 |
+
)
|
| 1052 |
+
hidden_states = transformer_outputs[0]
|
| 1053 |
+
logits = self.score(hidden_states)
|
| 1054 |
+
|
| 1055 |
+
if input_ids is not None:
|
| 1056 |
+
batch_size = input_ids.shape[0]
|
| 1057 |
+
else:
|
| 1058 |
+
batch_size = inputs_embeds.shape[0]
|
| 1059 |
+
|
| 1060 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
| 1061 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
| 1062 |
+
if self.config.pad_token_id is None:
|
| 1063 |
+
last_non_pad_token = -1
|
| 1064 |
+
elif input_ids is not None:
|
| 1065 |
+
# To handle both left- and right- padding, we take the rightmost token that is not equal to pad_token_id
|
| 1066 |
+
non_pad_mask = (input_ids != self.config.pad_token_id).to(logits.device, torch.int32)
|
| 1067 |
+
token_indices = torch.arange(input_ids.shape[-1], device=logits.device)
|
| 1068 |
+
last_non_pad_token = (token_indices * non_pad_mask).argmax(-1)
|
| 1069 |
+
else:
|
| 1070 |
+
last_non_pad_token = -1
|
| 1071 |
+
logger.warning_once(
|
| 1072 |
+
f"{self.__class__.__name__} will not detect padding tokens in `inputs_embeds`. Results may be "
|
| 1073 |
+
"unexpected if using padding tokens in conjunction with `inputs_embeds.`"
|
| 1074 |
+
)
|
| 1075 |
+
|
| 1076 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), last_non_pad_token]
|
| 1077 |
+
|
| 1078 |
+
loss = None
|
| 1079 |
+
if labels is not None:
|
| 1080 |
+
loss = self.loss_function(logits=logits, labels=labels, pooled_logits=pooled_logits, config=self.config)
|
| 1081 |
+
|
| 1082 |
+
if not return_dict:
|
| 1083 |
+
output = (pooled_logits,) + transformer_outputs[1:]
|
| 1084 |
+
return ((loss,) + output) if loss is not None else output
|
| 1085 |
+
|
| 1086 |
+
return SequenceClassifierOutputWithPast(
|
| 1087 |
+
loss=loss,
|
| 1088 |
+
logits=pooled_logits,
|
| 1089 |
+
past_key_values=transformer_outputs.past_key_values,
|
| 1090 |
+
hidden_states=transformer_outputs.hidden_states,
|
| 1091 |
+
attentions=transformer_outputs.attentions,
|
| 1092 |
+
)
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
@add_start_docstrings(
|
| 1096 |
+
"""
|
| 1097 |
+
The Phi3 Model transformer with a token classification head on top (a linear layer on top of the hidden-states
|
| 1098 |
+
output) e.g. for Named-Entity-Recognition (NER) tasks.
|
| 1099 |
+
""",
|
| 1100 |
+
PHI3_START_DOCSTRING,
|
| 1101 |
+
)
|
| 1102 |
+
class Phi3ForTokenClassification(Phi3PreTrainedModel):
|
| 1103 |
+
def __init__(self, config):
|
| 1104 |
+
super().__init__(config)
|
| 1105 |
+
self.num_labels = config.num_labels
|
| 1106 |
+
self.model = Phi3Model(config)
|
| 1107 |
+
if getattr(config, "classifier_dropout", None) is not None:
|
| 1108 |
+
classifier_dropout = config.classifier_dropout
|
| 1109 |
+
elif getattr(config, "hidden_dropout", None) is not None:
|
| 1110 |
+
classifier_dropout = config.hidden_dropout
|
| 1111 |
+
else:
|
| 1112 |
+
classifier_dropout = 0.1
|
| 1113 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
| 1114 |
+
self.score = nn.Linear(config.hidden_size, config.num_labels)
|
| 1115 |
+
|
| 1116 |
+
# Initialize weights and apply final processing
|
| 1117 |
+
self.post_init()
|
| 1118 |
+
|
| 1119 |
+
def get_input_embeddings(self):
|
| 1120 |
+
return self.model.embed_tokens
|
| 1121 |
+
|
| 1122 |
+
def set_input_embeddings(self, value):
|
| 1123 |
+
self.model.embed_tokens = value
|
| 1124 |
+
|
| 1125 |
+
@add_start_docstrings_to_model_forward(PHI3_INPUTS_DOCSTRING)
|
| 1126 |
+
@add_code_sample_docstrings(
|
| 1127 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
| 1128 |
+
output_type=TokenClassifierOutput,
|
| 1129 |
+
config_class=_CONFIG_FOR_DOC,
|
| 1130 |
+
)
|
| 1131 |
+
def forward(
|
| 1132 |
+
self,
|
| 1133 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1134 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1135 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1136 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 1137 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1138 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1139 |
+
use_cache: Optional[bool] = None,
|
| 1140 |
+
output_attentions: Optional[bool] = None,
|
| 1141 |
+
output_hidden_states: Optional[bool] = None,
|
| 1142 |
+
return_dict: Optional[bool] = None,
|
| 1143 |
+
) -> Union[Tuple, TokenClassifierOutput]:
|
| 1144 |
+
r"""
|
| 1145 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1146 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1147 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1148 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1149 |
+
"""
|
| 1150 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1151 |
+
|
| 1152 |
+
outputs = self.model(
|
| 1153 |
+
input_ids,
|
| 1154 |
+
attention_mask=attention_mask,
|
| 1155 |
+
position_ids=position_ids,
|
| 1156 |
+
past_key_values=past_key_values,
|
| 1157 |
+
inputs_embeds=inputs_embeds,
|
| 1158 |
+
use_cache=use_cache,
|
| 1159 |
+
output_attentions=output_attentions,
|
| 1160 |
+
output_hidden_states=output_hidden_states,
|
| 1161 |
+
return_dict=return_dict,
|
| 1162 |
+
)
|
| 1163 |
+
sequence_output = outputs[0]
|
| 1164 |
+
sequence_output = self.dropout(sequence_output)
|
| 1165 |
+
logits = self.score(sequence_output)
|
| 1166 |
+
|
| 1167 |
+
loss = None
|
| 1168 |
+
if labels is not None:
|
| 1169 |
+
loss = self.loss_function(logits, labels, self.config)
|
| 1170 |
+
|
| 1171 |
+
if not return_dict:
|
| 1172 |
+
output = (logits,) + outputs[2:]
|
| 1173 |
+
return ((loss,) + output) if loss is not None else output
|
| 1174 |
+
|
| 1175 |
+
return TokenClassifierOutput(
|
| 1176 |
+
loss=loss,
|
| 1177 |
+
logits=logits,
|
| 1178 |
+
hidden_states=outputs.hidden_states,
|
| 1179 |
+
attentions=outputs.attentions,
|
| 1180 |
+
)
|
npu/12251558561149292649.blob
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f0b944081ab39967ebd1484a5e212a1d977fdeeeffa0c70db6b1f15aea6fc7c1
|
| 3 |
+
size 60124628
|
openvino_detokenizer.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<net name="detokenizer" version="11">
|
| 3 |
+
<layers>
|
| 4 |
+
<layer id="0" name="Parameter_172325" type="Parameter" version="opset1">
|
| 5 |
+
<data shape="?,?" element_type="i64" />
|
| 6 |
+
<output>
|
| 7 |
+
<port id="0" precision="I64" names="Parameter_172325">
|
| 8 |
+
<dim>-1</dim>
|
| 9 |
+
<dim>-1</dim>
|
| 10 |
+
</port>
|
| 11 |
+
</output>
|
| 12 |
+
</layer>
|
| 13 |
+
<layer id="1" name="Convert_172495" type="Convert" version="opset1">
|
| 14 |
+
<data destination_type="i32" />
|
| 15 |
+
<input>
|
| 16 |
+
<port id="0" precision="I64">
|
| 17 |
+
<dim>-1</dim>
|
| 18 |
+
<dim>-1</dim>
|
| 19 |
+
</port>
|
| 20 |
+
</input>
|
| 21 |
+
<output>
|
| 22 |
+
<port id="1" precision="I32">
|
| 23 |
+
<dim>-1</dim>
|
| 24 |
+
<dim>-1</dim>
|
| 25 |
+
</port>
|
| 26 |
+
</output>
|
| 27 |
+
</layer>
|
| 28 |
+
<layer id="2" name="Constant_172327" type="Const" version="opset1">
|
| 29 |
+
<data element_type="i32" shape="200029" offset="0" size="800116" />
|
| 30 |
+
<output>
|
| 31 |
+
<port id="0" precision="I32">
|
| 32 |
+
<dim>200029</dim>
|
| 33 |
+
</port>
|
| 34 |
+
</output>
|
| 35 |
+
</layer>
|
| 36 |
+
<layer id="3" name="Constant_172329" type="Const" version="opset1">
|
| 37 |
+
<data element_type="i32" shape="200029" offset="800116" size="800116" />
|
| 38 |
+
<output>
|
| 39 |
+
<port id="0" precision="I32">
|
| 40 |
+
<dim>200029</dim>
|
| 41 |
+
</port>
|
| 42 |
+
</output>
|
| 43 |
+
</layer>
|
| 44 |
+
<layer id="4" name="Constant_172331" type="Const" version="opset1">
|
| 45 |
+
<data element_type="u8" shape="1398089" offset="1600232" size="1398089" />
|
| 46 |
+
<output>
|
| 47 |
+
<port id="0" precision="U8">
|
| 48 |
+
<dim>1398089</dim>
|
| 49 |
+
</port>
|
| 50 |
+
</output>
|
| 51 |
+
</layer>
|
| 52 |
+
<layer id="5" name="Slice_172336" type="Const" version="opset1">
|
| 53 |
+
<data element_type="i32" shape="7" offset="2998321" size="28" />
|
| 54 |
+
<output>
|
| 55 |
+
<port id="0" precision="I32">
|
| 56 |
+
<dim>7</dim>
|
| 57 |
+
</port>
|
| 58 |
+
</output>
|
| 59 |
+
</layer>
|
| 60 |
+
<layer id="6" name="VocabDecoder_172338" type="VocabDecoder" version="extension">
|
| 61 |
+
<data skip_tokens="" />
|
| 62 |
+
<input>
|
| 63 |
+
<port id="0" precision="I32">
|
| 64 |
+
<dim>-1</dim>
|
| 65 |
+
<dim>-1</dim>
|
| 66 |
+
</port>
|
| 67 |
+
<port id="1" precision="I32">
|
| 68 |
+
<dim>200029</dim>
|
| 69 |
+
</port>
|
| 70 |
+
<port id="2" precision="I32">
|
| 71 |
+
<dim>200029</dim>
|
| 72 |
+
</port>
|
| 73 |
+
<port id="3" precision="U8">
|
| 74 |
+
<dim>1398089</dim>
|
| 75 |
+
</port>
|
| 76 |
+
<port id="4" precision="I32">
|
| 77 |
+
<dim>7</dim>
|
| 78 |
+
</port>
|
| 79 |
+
</input>
|
| 80 |
+
<output>
|
| 81 |
+
<port id="5" precision="I32">
|
| 82 |
+
<dim>-1</dim>
|
| 83 |
+
</port>
|
| 84 |
+
<port id="6" precision="I32">
|
| 85 |
+
<dim>-1</dim>
|
| 86 |
+
</port>
|
| 87 |
+
<port id="7" precision="I32">
|
| 88 |
+
<dim>-1</dim>
|
| 89 |
+
</port>
|
| 90 |
+
<port id="8" precision="I32">
|
| 91 |
+
<dim>-1</dim>
|
| 92 |
+
</port>
|
| 93 |
+
<port id="9" precision="U8">
|
| 94 |
+
<dim>-1</dim>
|
| 95 |
+
</port>
|
| 96 |
+
</output>
|
| 97 |
+
</layer>
|
| 98 |
+
<layer id="7" name="FuzeRagged_172339" type="FuzeRagged" version="extension">
|
| 99 |
+
<input>
|
| 100 |
+
<port id="0" precision="I32">
|
| 101 |
+
<dim>-1</dim>
|
| 102 |
+
</port>
|
| 103 |
+
<port id="1" precision="I32">
|
| 104 |
+
<dim>-1</dim>
|
| 105 |
+
</port>
|
| 106 |
+
<port id="2" precision="I32">
|
| 107 |
+
<dim>-1</dim>
|
| 108 |
+
</port>
|
| 109 |
+
<port id="3" precision="I32">
|
| 110 |
+
<dim>-1</dim>
|
| 111 |
+
</port>
|
| 112 |
+
</input>
|
| 113 |
+
<output>
|
| 114 |
+
<port id="4" precision="I32">
|
| 115 |
+
<dim>-1</dim>
|
| 116 |
+
</port>
|
| 117 |
+
<port id="5" precision="I32">
|
| 118 |
+
<dim>-1</dim>
|
| 119 |
+
</port>
|
| 120 |
+
</output>
|
| 121 |
+
</layer>
|
| 122 |
+
<layer id="8" name="UTF8Validate_172340" type="UTF8Validate" version="extension">
|
| 123 |
+
<data replace_mode="true" />
|
| 124 |
+
<input>
|
| 125 |
+
<port id="0" precision="I32">
|
| 126 |
+
<dim>-1</dim>
|
| 127 |
+
</port>
|
| 128 |
+
<port id="1" precision="I32">
|
| 129 |
+
<dim>-1</dim>
|
| 130 |
+
</port>
|
| 131 |
+
<port id="2" precision="U8">
|
| 132 |
+
<dim>-1</dim>
|
| 133 |
+
</port>
|
| 134 |
+
</input>
|
| 135 |
+
<output>
|
| 136 |
+
<port id="3" precision="I32">
|
| 137 |
+
<dim>-1</dim>
|
| 138 |
+
</port>
|
| 139 |
+
<port id="4" precision="I32">
|
| 140 |
+
<dim>-1</dim>
|
| 141 |
+
</port>
|
| 142 |
+
<port id="5" precision="U8">
|
| 143 |
+
<dim>-1</dim>
|
| 144 |
+
</port>
|
| 145 |
+
</output>
|
| 146 |
+
</layer>
|
| 147 |
+
<layer id="9" name="StringTensorPack_172341" type="StringTensorPack" version="opset15">
|
| 148 |
+
<input>
|
| 149 |
+
<port id="0" precision="I32">
|
| 150 |
+
<dim>-1</dim>
|
| 151 |
+
</port>
|
| 152 |
+
<port id="1" precision="I32">
|
| 153 |
+
<dim>-1</dim>
|
| 154 |
+
</port>
|
| 155 |
+
<port id="2" precision="U8">
|
| 156 |
+
<dim>-1</dim>
|
| 157 |
+
</port>
|
| 158 |
+
</input>
|
| 159 |
+
<output>
|
| 160 |
+
<port id="3" precision="STRING" names="Result_172342,string_output">
|
| 161 |
+
<dim>-1</dim>
|
| 162 |
+
</port>
|
| 163 |
+
</output>
|
| 164 |
+
</layer>
|
| 165 |
+
<layer id="10" name="Result_172342" type="Result" version="opset1" output_names="Result_172342,string_output">
|
| 166 |
+
<input>
|
| 167 |
+
<port id="0" precision="STRING">
|
| 168 |
+
<dim>-1</dim>
|
| 169 |
+
</port>
|
| 170 |
+
</input>
|
| 171 |
+
</layer>
|
| 172 |
+
</layers>
|
| 173 |
+
<edges>
|
| 174 |
+
<edge from-layer="0" from-port="0" to-layer="1" to-port="0" />
|
| 175 |
+
<edge from-layer="1" from-port="1" to-layer="6" to-port="0" />
|
| 176 |
+
<edge from-layer="2" from-port="0" to-layer="6" to-port="1" />
|
| 177 |
+
<edge from-layer="3" from-port="0" to-layer="6" to-port="2" />
|
| 178 |
+
<edge from-layer="4" from-port="0" to-layer="6" to-port="3" />
|
| 179 |
+
<edge from-layer="5" from-port="0" to-layer="6" to-port="4" />
|
| 180 |
+
<edge from-layer="6" from-port="7" to-layer="7" to-port="2" />
|
| 181 |
+
<edge from-layer="6" from-port="9" to-layer="8" to-port="2" />
|
| 182 |
+
<edge from-layer="6" from-port="8" to-layer="7" to-port="3" />
|
| 183 |
+
<edge from-layer="6" from-port="6" to-layer="7" to-port="1" />
|
| 184 |
+
<edge from-layer="6" from-port="5" to-layer="7" to-port="0" />
|
| 185 |
+
<edge from-layer="7" from-port="4" to-layer="8" to-port="0" />
|
| 186 |
+
<edge from-layer="7" from-port="5" to-layer="8" to-port="1" />
|
| 187 |
+
<edge from-layer="8" from-port="3" to-layer="9" to-port="0" />
|
| 188 |
+
<edge from-layer="8" from-port="4" to-layer="9" to-port="1" />
|
| 189 |
+
<edge from-layer="8" from-port="5" to-layer="9" to-port="2" />
|
| 190 |
+
<edge from-layer="9" from-port="3" to-layer="10" to-port="0" />
|
| 191 |
+
</edges>
|
| 192 |
+
<rt_info>
|
| 193 |
+
<add_attention_mask value="True" />
|
| 194 |
+
<add_prefix_space />
|
| 195 |
+
<add_special_tokens value="True" />
|
| 196 |
+
<bos_token_id value="199999" />
|
| 197 |
+
<chat_template value="{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}" />
|
| 198 |
+
<clean_up_tokenization_spaces />
|
| 199 |
+
<detokenizer_input_type value="i64" />
|
| 200 |
+
<eos_token_id value="199999" />
|
| 201 |
+
<handle_special_tokens_with_re />
|
| 202 |
+
<max_length />
|
| 203 |
+
<number_of_inputs value="1" />
|
| 204 |
+
<openvino_tokenizers_version value="2025.1.0.0-523-710ddf14de8" />
|
| 205 |
+
<openvino_version value="2025.1.0-18503-6fec06580ab-releases/2025/1" />
|
| 206 |
+
<original_tokenizer_class value="<class 'transformers.models.gpt2.tokenization_gpt2_fast.GPT2TokenizerFast'>" />
|
| 207 |
+
<pad_token_id value="199999" />
|
| 208 |
+
<sentencepiece_version value="0.2.0" />
|
| 209 |
+
<skip_special_tokens value="True" />
|
| 210 |
+
<streaming_detokenizer value="False" />
|
| 211 |
+
<tiktoken_version value="0.7.0" />
|
| 212 |
+
<tokenizer_output_type value="i64" />
|
| 213 |
+
<tokenizers_version value="0.21.1" />
|
| 214 |
+
<transformers_version value="4.49.0" />
|
| 215 |
+
<use_max_padding value="False" />
|
| 216 |
+
<use_sentencepiece_backend value="False" />
|
| 217 |
+
<utf8_replace_mode value="replace" />
|
| 218 |
+
<with_detokenizer value="True" />
|
| 219 |
+
</rt_info>
|
| 220 |
+
</net>
|
openvino_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8b3c2cb44b725fa41ef90a482f20fd0c6ca2656a80b7869e6c9bee94a10c9e82
|
| 3 |
+
size 7672043906
|
openvino_model.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
openvino_tokenizer.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:818537d6633196e2f45e51017a6320010ca3c06120460c14028a6c325f92f477
|
| 3 |
+
size 7602768
|
openvino_tokenizer.xml
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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shape="?" element_type="string" />
|
| 6 |
+
<output>
|
| 7 |
+
<port id="0" precision="STRING" names="Parameter_172207">
|
| 8 |
+
<dim>-1</dim>
|
| 9 |
+
</port>
|
| 10 |
+
</output>
|
| 11 |
+
</layer>
|
| 12 |
+
<layer id="1" name="Constant_172213" type="Const" version="opset1">
|
| 13 |
+
<data element_type="i64" shape="" offset="0" size="8" />
|
| 14 |
+
<output>
|
| 15 |
+
<port id="0" precision="I64" />
|
| 16 |
+
</output>
|
| 17 |
+
</layer>
|
| 18 |
+
<layer id="2" name="StringTensorUnpack_172208" type="StringTensorUnpack" version="opset15">
|
| 19 |
+
<input>
|
| 20 |
+
<port id="0" precision="STRING">
|
| 21 |
+
<dim>-1</dim>
|
| 22 |
+
</port>
|
| 23 |
+
</input>
|
| 24 |
+
<output>
|
| 25 |
+
<port id="1" precision="I32">
|
| 26 |
+
<dim>-1</dim>
|
| 27 |
+
</port>
|
| 28 |
+
<port id="2" precision="I32">
|
| 29 |
+
<dim>-1</dim>
|
| 30 |
+
</port>
|
| 31 |
+
<port id="3" precision="U8">
|
| 32 |
+
<dim>-1</dim>
|
| 33 |
+
</port>
|
| 34 |
+
</output>
|
| 35 |
+
</layer>
|
| 36 |
+
<layer id="3" name="ShapeOf_172209" type="ShapeOf" version="opset3">
|
| 37 |
+
<data output_type="i64" />
|
| 38 |
+
<input>
|
| 39 |
+
<port id="0" precision="I32">
|
| 40 |
+
<dim>-1</dim>
|
| 41 |
+
</port>
|
| 42 |
+
</input>
|
| 43 |
+
<output>
|
| 44 |
+
<port id="1" precision="I64">
|
| 45 |
+
<dim>1</dim>
|
| 46 |
+
</port>
|
| 47 |
+
</output>
|
| 48 |
+
</layer>
|
| 49 |
+
<layer id="4" name="Constant_172210" type="Const" version="opset1">
|
| 50 |
+
<data element_type="i64" shape="" offset="0" size="8" />
|
| 51 |
+
<output>
|
| 52 |
+
<port id="0" precision="I64" />
|
| 53 |
+
</output>
|
| 54 |
+
</layer>
|
| 55 |
+
<layer id="5" name="Constant_172211" type="Const" version="opset1">
|
| 56 |
+
<data element_type="i64" shape="" offset="0" size="8" />
|
| 57 |
+
<output>
|
| 58 |
+
<port id="0" precision="I64" />
|
| 59 |
+
</output>
|
| 60 |
+
</layer>
|
| 61 |
+
<layer id="6" name="Gather_172212" type="Gather" version="opset8">
|
| 62 |
+
<data batch_dims="0" />
|
| 63 |
+
<input>
|
| 64 |
+
<port id="0" precision="I64">
|
| 65 |
+
<dim>1</dim>
|
| 66 |
+
</port>
|
| 67 |
+
<port id="1" precision="I64" />
|
| 68 |
+
<port id="2" precision="I64" />
|
| 69 |
+
</input>
|
| 70 |
+
<output>
|
| 71 |
+
<port id="3" precision="I64" />
|
| 72 |
+
</output>
|
| 73 |
+
</layer>
|
| 74 |
+
<layer id="7" name="Constant_172214" type="Const" version="opset1">
|
| 75 |
+
<data element_type="i64" shape="" offset="8" size="8" />
|
| 76 |
+
<output>
|
| 77 |
+
<port id="0" precision="I64" />
|
| 78 |
+
</output>
|
| 79 |
+
</layer>
|
| 80 |
+
<layer id="8" name="Range_172215" type="Range" version="opset4">
|
| 81 |
+
<data output_type="i32" />
|
| 82 |
+
<input>
|
| 83 |
+
<port id="0" precision="I64" />
|
| 84 |
+
<port id="1" precision="I64" />
|
| 85 |
+
<port id="2" precision="I64" />
|
| 86 |
+
</input>
|
| 87 |
+
<output>
|
| 88 |
+
<port id="3" precision="I32">
|
| 89 |
+
<dim>-1</dim>
|
| 90 |
+
</port>
|
| 91 |
+
</output>
|
| 92 |
+
</layer>
|
| 93 |
+
<layer id="9" name="Constant_172216" type="Const" version="opset1">
|
| 94 |
+
<data element_type="i64" shape="" offset="8" size="8" />
|
| 95 |
+
<output>
|
| 96 |
+
<port id="0" precision="I64" />
|
| 97 |
+
</output>
|
| 98 |
+
</layer>
|
| 99 |
+
<layer id="10" name="Constant_172217" type="Const" version="opset1">
|
| 100 |
+
<data element_type="i64" shape="" offset="8" size="8" />
|
| 101 |
+
<output>
|
| 102 |
+
<port id="0" precision="I64" />
|
| 103 |
+
</output>
|
| 104 |
+
</layer>
|
| 105 |
+
<layer id="11" name="Add_172218" type="Add" version="opset1">
|
| 106 |
+
<data auto_broadcast="numpy" />
|
| 107 |
+
<input>
|
| 108 |
+
<port id="0" precision="I64" />
|
| 109 |
+
<port id="1" precision="I64" />
|
| 110 |
+
</input>
|
| 111 |
+
<output>
|
| 112 |
+
<port id="2" precision="I64" />
|
| 113 |
+
</output>
|
| 114 |
+
</layer>
|
| 115 |
+
<layer id="12" name="Constant_172219" type="Const" version="opset1">
|
| 116 |
+
<data element_type="i64" shape="" offset="8" size="8" />
|
| 117 |
+
<output>
|
| 118 |
+
<port id="0" precision="I64" />
|
| 119 |
+
</output>
|
| 120 |
+
</layer>
|
| 121 |
+
<layer id="13" name="Range_172220" type="Range" version="opset4">
|
| 122 |
+
<data output_type="i32" />
|
| 123 |
+
<input>
|
| 124 |
+
<port id="0" precision="I64" />
|
| 125 |
+
<port id="1" precision="I64" />
|
| 126 |
+
<port id="2" precision="I64" />
|
| 127 |
+
</input>
|
| 128 |
+
<output>
|
| 129 |
+
<port id="3" precision="I32">
|
| 130 |
+
<dim>-1</dim>
|
| 131 |
+
</port>
|
| 132 |
+
</output>
|
| 133 |
+
</layer>
|
| 134 |
+
<layer id="14" name="Constant_172282" type="Const" version="opset1">
|
| 135 |
+
<data element_type="u8" shape="289" offset="16" size="289" />
|
| 136 |
+
<output>
|
| 137 |
+
<port id="0" precision="U8">
|
| 138 |
+
<dim>289</dim>
|
| 139 |
+
</port>
|
| 140 |
+
</output>
|
| 141 |
+
</layer>
|
| 142 |
+
<layer id="15" name="SpecialTokensSplit_172283" type="SpecialTokensSplit" version="extension">
|
| 143 |
+
<input>
|
| 144 |
+
<port id="0" precision="I32">
|
| 145 |
+
<dim>-1</dim>
|
| 146 |
+
</port>
|
| 147 |
+
<port id="1" precision="I32">
|
| 148 |
+
<dim>-1</dim>
|
| 149 |
+
</port>
|
| 150 |
+
<port id="2" precision="I32">
|
| 151 |
+
<dim>-1</dim>
|
| 152 |
+
</port>
|
| 153 |
+
<port id="3" precision="I32">
|
| 154 |
+
<dim>-1</dim>
|
| 155 |
+
</port>
|
| 156 |
+
<port id="4" precision="U8">
|
| 157 |
+
<dim>-1</dim>
|
| 158 |
+
</port>
|
| 159 |
+
<port id="5" precision="U8">
|
| 160 |
+
<dim>289</dim>
|
| 161 |
+
</port>
|
| 162 |
+
</input>
|
| 163 |
+
<output>
|
| 164 |
+
<port id="6" precision="I32">
|
| 165 |
+
<dim>-1</dim>
|
| 166 |
+
</port>
|
| 167 |
+
<port id="7" precision="I32">
|
| 168 |
+
<dim>-1</dim>
|
| 169 |
+
</port>
|
| 170 |
+
<port id="8" precision="I32">
|
| 171 |
+
<dim>-1</dim>
|
| 172 |
+
</port>
|
| 173 |
+
<port id="9" precision="I32">
|
| 174 |
+
<dim>-1</dim>
|
| 175 |
+
</port>
|
| 176 |
+
<port id="10" precision="U8">
|
| 177 |
+
<dim>-1</dim>
|
| 178 |
+
</port>
|
| 179 |
+
<port id="11" precision="BOOL">
|
| 180 |
+
<dim>-1</dim>
|
| 181 |
+
</port>
|
| 182 |
+
</output>
|
| 183 |
+
</layer>
|
| 184 |
+
<layer id="16" name="Constant_172285" type="Const" version="opset1">
|
| 185 |
+
<data element_type="u8" shape="274" offset="305" size="274" />
|
| 186 |
+
<output>
|
| 187 |
+
<port id="0" precision="U8">
|
| 188 |
+
<dim>274</dim>
|
| 189 |
+
</port>
|
| 190 |
+
</output>
|
| 191 |
+
</layer>
|
| 192 |
+
<layer id="17" name="RegexSplit_172286" type="RegexSplit" version="extension">
|
| 193 |
+
<data behaviour="remove" invert="true" max_splits="-1" />
|
| 194 |
+
<input>
|
| 195 |
+
<port id="0" precision="I32">
|
| 196 |
+
<dim>-1</dim>
|
| 197 |
+
</port>
|
| 198 |
+
<port id="1" precision="I32">
|
| 199 |
+
<dim>-1</dim>
|
| 200 |
+
</port>
|
| 201 |
+
<port id="2" precision="I32">
|
| 202 |
+
<dim>-1</dim>
|
| 203 |
+
</port>
|
| 204 |
+
<port id="3" precision="I32">
|
| 205 |
+
<dim>-1</dim>
|
| 206 |
+
</port>
|
| 207 |
+
<port id="4" precision="U8">
|
| 208 |
+
<dim>-1</dim>
|
| 209 |
+
</port>
|
| 210 |
+
<port id="5" precision="BOOL">
|
| 211 |
+
<dim>-1</dim>
|
| 212 |
+
</port>
|
| 213 |
+
<port id="6" precision="U8">
|
| 214 |
+
<dim>274</dim>
|
| 215 |
+
</port>
|
| 216 |
+
</input>
|
| 217 |
+
<output>
|
| 218 |
+
<port id="7" precision="I32">
|
| 219 |
+
<dim>-1</dim>
|
| 220 |
+
</port>
|
| 221 |
+
<port id="8" precision="I32">
|
| 222 |
+
<dim>-1</dim>
|
| 223 |
+
</port>
|
| 224 |
+
<port id="9" precision="I32">
|
| 225 |
+
<dim>-1</dim>
|
| 226 |
+
</port>
|
| 227 |
+
<port id="10" precision="I32">
|
| 228 |
+
<dim>-1</dim>
|
| 229 |
+
</port>
|
| 230 |
+
<port id="11" precision="U8">
|
| 231 |
+
<dim>-1</dim>
|
| 232 |
+
</port>
|
| 233 |
+
<port id="12" precision="BOOL">
|
| 234 |
+
<dim>-1</dim>
|
| 235 |
+
</port>
|
| 236 |
+
</output>
|
| 237 |
+
</layer>
|
| 238 |
+
<layer id="18" name="Constant_172288" type="Const" version="opset1">
|
| 239 |
+
<data element_type="i32" shape="200029" offset="579" size="800116" />
|
| 240 |
+
<output>
|
| 241 |
+
<port id="0" precision="I32">
|
| 242 |
+
<dim>200029</dim>
|
| 243 |
+
</port>
|
| 244 |
+
</output>
|
| 245 |
+
</layer>
|
| 246 |
+
<layer id="19" name="Constant_172290" type="Const" version="opset1">
|
| 247 |
+
<data element_type="i32" shape="200029" offset="800695" size="800116" />
|
| 248 |
+
<output>
|
| 249 |
+
<port id="0" precision="I32">
|
| 250 |
+
<dim>200029</dim>
|
| 251 |
+
</port>
|
| 252 |
+
</output>
|
| 253 |
+
</layer>
|
| 254 |
+
<layer id="20" name="Constant_172292" type="Const" version="opset1">
|
| 255 |
+
<data element_type="u8" shape="1398109" offset="1600811" size="1398109" />
|
| 256 |
+
<output>
|
| 257 |
+
<port id="0" precision="U8">
|
| 258 |
+
<dim>1398109</dim>
|
| 259 |
+
</port>
|
| 260 |
+
</output>
|
| 261 |
+
</layer>
|
| 262 |
+
<layer id="21" name="Constant_172300" type="Const" version="opset1">
|
| 263 |
+
<data element_type="i32" shape="199742" offset="2998920" size="798968" />
|
| 264 |
+
<output>
|
| 265 |
+
<port id="0" precision="I32">
|
| 266 |
+
<dim>199742</dim>
|
| 267 |
+
</port>
|
| 268 |
+
</output>
|
| 269 |
+
</layer>
|
| 270 |
+
<layer id="22" name="Constant_172302" type="Const" version="opset1">
|
| 271 |
+
<data element_type="i32" shape="199742" offset="3797888" size="798968" />
|
| 272 |
+
<output>
|
| 273 |
+
<port id="0" precision="I32">
|
| 274 |
+
<dim>199742</dim>
|
| 275 |
+
</port>
|
| 276 |
+
</output>
|
| 277 |
+
</layer>
|
| 278 |
+
<layer id="23" name="Constant_172304" type="Const" version="opset1">
|
| 279 |
+
<data element_type="u8" shape="718313" offset="4596856" size="718313" />
|
| 280 |
+
<output>
|
| 281 |
+
<port id="0" precision="U8">
|
| 282 |
+
<dim>718313</dim>
|
| 283 |
+
</port>
|
| 284 |
+
</output>
|
| 285 |
+
</layer>
|
| 286 |
+
<layer id="24" name="Constant_172306" type="Const" version="opset1">
|
| 287 |
+
<data element_type="i32" shape="199742" offset="5315169" size="798968" />
|
| 288 |
+
<output>
|
| 289 |
+
<port id="0" precision="I32">
|
| 290 |
+
<dim>199742</dim>
|
| 291 |
+
</port>
|
| 292 |
+
</output>
|
| 293 |
+
</layer>
|
| 294 |
+
<layer id="25" name="Constant_172308" type="Const" version="opset1">
|
| 295 |
+
<data element_type="i32" shape="199742" offset="6114137" size="798968" />
|
| 296 |
+
<output>
|
| 297 |
+
<port id="0" precision="I32">
|
| 298 |
+
<dim>199742</dim>
|
| 299 |
+
</port>
|
| 300 |
+
</output>
|
| 301 |
+
</layer>
|
| 302 |
+
<layer id="26" name="Constant_172310" type="Const" version="opset1">
|
| 303 |
+
<data element_type="u8" shape="679101" offset="6913105" size="679101" />
|
| 304 |
+
<output>
|
| 305 |
+
<port id="0" precision="U8">
|
| 306 |
+
<dim>679101</dim>
|
| 307 |
+
</port>
|
| 308 |
+
</output>
|
| 309 |
+
</layer>
|
| 310 |
+
<layer id="27" name="Constant_172294" type="Const" version="opset1">
|
| 311 |
+
<data element_type="i32" shape="432" offset="7592206" size="1728" />
|
| 312 |
+
<output>
|
| 313 |
+
<port id="0" precision="I32">
|
| 314 |
+
<dim>432</dim>
|
| 315 |
+
</port>
|
| 316 |
+
</output>
|
| 317 |
+
</layer>
|
| 318 |
+
<layer id="28" name="Constant_172296" type="Const" version="opset1">
|
| 319 |
+
<data element_type="i32" shape="432" offset="7593934" size="1728" />
|
| 320 |
+
<output>
|
| 321 |
+
<port id="0" precision="I32">
|
| 322 |
+
<dim>432</dim>
|
| 323 |
+
</port>
|
| 324 |
+
</output>
|
| 325 |
+
</layer>
|
| 326 |
+
<layer id="29" name="Constant_172298" type="Const" version="opset1">
|
| 327 |
+
<data element_type="u8" shape="5366" offset="7595662" size="5366" />
|
| 328 |
+
<output>
|
| 329 |
+
<port id="0" precision="U8">
|
| 330 |
+
<dim>5366</dim>
|
| 331 |
+
</port>
|
| 332 |
+
</output>
|
| 333 |
+
</layer>
|
| 334 |
+
<layer id="30" name="Constant_172311" type="Const" version="opset1">
|
| 335 |
+
<data element_type="i32" shape="432" offset="7601028" size="1728" />
|
| 336 |
+
<output>
|
| 337 |
+
<port id="0" precision="I32">
|
| 338 |
+
<dim>432</dim>
|
| 339 |
+
</port>
|
| 340 |
+
</output>
|
| 341 |
+
</layer>
|
| 342 |
+
<layer id="31" name="BPETokenizer_172312" type="BPETokenizer" version="extension">
|
| 343 |
+
<data unk_token="" fuse_unk="false" suffix_indicator="" end_suffix="" byte_fallback="false" cache_capacity="40003" />
|
| 344 |
+
<input>
|
| 345 |
+
<port id="0" precision="I32">
|
| 346 |
+
<dim>-1</dim>
|
| 347 |
+
</port>
|
| 348 |
+
<port id="1" precision="I32">
|
| 349 |
+
<dim>-1</dim>
|
| 350 |
+
</port>
|
| 351 |
+
<port id="2" precision="I32">
|
| 352 |
+
<dim>-1</dim>
|
| 353 |
+
</port>
|
| 354 |
+
<port id="3" precision="I32">
|
| 355 |
+
<dim>-1</dim>
|
| 356 |
+
</port>
|
| 357 |
+
<port id="4" precision="U8">
|
| 358 |
+
<dim>-1</dim>
|
| 359 |
+
</port>
|
| 360 |
+
<port id="5" precision="I32">
|
| 361 |
+
<dim>200029</dim>
|
| 362 |
+
</port>
|
| 363 |
+
<port id="6" precision="I32">
|
| 364 |
+
<dim>200029</dim>
|
| 365 |
+
</port>
|
| 366 |
+
<port id="7" precision="U8">
|
| 367 |
+
<dim>1398109</dim>
|
| 368 |
+
</port>
|
| 369 |
+
<port id="8" precision="I32">
|
| 370 |
+
<dim>199742</dim>
|
| 371 |
+
</port>
|
| 372 |
+
<port id="9" precision="I32">
|
| 373 |
+
<dim>199742</dim>
|
| 374 |
+
</port>
|
| 375 |
+
<port id="10" precision="U8">
|
| 376 |
+
<dim>718313</dim>
|
| 377 |
+
</port>
|
| 378 |
+
<port id="11" precision="I32">
|
| 379 |
+
<dim>199742</dim>
|
| 380 |
+
</port>
|
| 381 |
+
<port id="12" precision="I32">
|
| 382 |
+
<dim>199742</dim>
|
| 383 |
+
</port>
|
| 384 |
+
<port id="13" precision="U8">
|
| 385 |
+
<dim>679101</dim>
|
| 386 |
+
</port>
|
| 387 |
+
<port id="14" precision="I32">
|
| 388 |
+
<dim>432</dim>
|
| 389 |
+
</port>
|
| 390 |
+
<port id="15" precision="I32">
|
| 391 |
+
<dim>432</dim>
|
| 392 |
+
</port>
|
| 393 |
+
<port id="16" precision="U8">
|
| 394 |
+
<dim>5366</dim>
|
| 395 |
+
</port>
|
| 396 |
+
<port id="17" precision="I32">
|
| 397 |
+
<dim>432</dim>
|
| 398 |
+
</port>
|
| 399 |
+
</input>
|
| 400 |
+
<output>
|
| 401 |
+
<port id="18" precision="I32">
|
| 402 |
+
<dim>-1</dim>
|
| 403 |
+
</port>
|
| 404 |
+
<port id="19" precision="I32">
|
| 405 |
+
<dim>-1</dim>
|
| 406 |
+
</port>
|
| 407 |
+
<port id="20" precision="I32">
|
| 408 |
+
<dim>-1</dim>
|
| 409 |
+
</port>
|
| 410 |
+
</output>
|
| 411 |
+
</layer>
|
| 412 |
+
<layer id="32" name="Subtract_172313" type="Subtract" version="opset1">
|
| 413 |
+
<data auto_broadcast="numpy" />
|
| 414 |
+
<input>
|
| 415 |
+
<port id="0" precision="I32">
|
| 416 |
+
<dim>-1</dim>
|
| 417 |
+
</port>
|
| 418 |
+
<port id="1" precision="I32">
|
| 419 |
+
<dim>-1</dim>
|
| 420 |
+
</port>
|
| 421 |
+
</input>
|
| 422 |
+
<output>
|
| 423 |
+
<port id="2" precision="I32">
|
| 424 |
+
<dim>-1</dim>
|
| 425 |
+
</port>
|
| 426 |
+
</output>
|
| 427 |
+
</layer>
|
| 428 |
+
<layer id="33" name="Constant_172314" type="Const" version="opset1">
|
| 429 |
+
<data element_type="i32" shape="" offset="7602756" size="4" />
|
| 430 |
+
<output>
|
| 431 |
+
<port id="0" precision="I32" />
|
| 432 |
+
</output>
|
| 433 |
+
</layer>
|
| 434 |
+
<layer id="34" name="Minimum_172315" type="Minimum" version="opset1">
|
| 435 |
+
<data auto_broadcast="numpy" />
|
| 436 |
+
<input>
|
| 437 |
+
<port id="0" precision="I32">
|
| 438 |
+
<dim>-1</dim>
|
| 439 |
+
</port>
|
| 440 |
+
<port id="1" precision="I32" />
|
| 441 |
+
</input>
|
| 442 |
+
<output>
|
| 443 |
+
<port id="2" precision="I32">
|
| 444 |
+
<dim>-1</dim>
|
| 445 |
+
</port>
|
| 446 |
+
</output>
|
| 447 |
+
</layer>
|
| 448 |
+
<layer id="35" name="Subtract_172316" type="Subtract" version="opset1">
|
| 449 |
+
<data auto_broadcast="numpy" />
|
| 450 |
+
<input>
|
| 451 |
+
<port id="0" precision="I32">
|
| 452 |
+
<dim>-1</dim>
|
| 453 |
+
</port>
|
| 454 |
+
<port id="1" precision="I32">
|
| 455 |
+
<dim>-1</dim>
|
| 456 |
+
</port>
|
| 457 |
+
</input>
|
| 458 |
+
<output>
|
| 459 |
+
<port id="2" precision="I32">
|
| 460 |
+
<dim>-1</dim>
|
| 461 |
+
</port>
|
| 462 |
+
</output>
|
| 463 |
+
</layer>
|
| 464 |
+
<layer id="36" name="Subtract_172317" type="Subtract" version="opset1">
|
| 465 |
+
<data auto_broadcast="numpy" />
|
| 466 |
+
<input>
|
| 467 |
+
<port id="0" precision="I32">
|
| 468 |
+
<dim>-1</dim>
|
| 469 |
+
</port>
|
| 470 |
+
<port id="1" precision="I32">
|
| 471 |
+
<dim>-1</dim>
|
| 472 |
+
</port>
|
| 473 |
+
</input>
|
| 474 |
+
<output>
|
| 475 |
+
<port id="2" precision="I32">
|
| 476 |
+
<dim>-1</dim>
|
| 477 |
+
</port>
|
| 478 |
+
</output>
|
| 479 |
+
</layer>
|
| 480 |
+
<layer id="37" name="Constant_172318" type="Const" version="opset1">
|
| 481 |
+
<data element_type="i32" shape="" offset="7602760" size="4" />
|
| 482 |
+
<output>
|
| 483 |
+
<port id="0" precision="I32" />
|
| 484 |
+
</output>
|
| 485 |
+
</layer>
|
| 486 |
+
<layer id="38" name="ReduceMax_172319" type="ReduceMax" version="opset1">
|
| 487 |
+
<data keep_dims="false" />
|
| 488 |
+
<input>
|
| 489 |
+
<port id="0" precision="I32">
|
| 490 |
+
<dim>-1</dim>
|
| 491 |
+
</port>
|
| 492 |
+
<port id="1" precision="I32" />
|
| 493 |
+
</input>
|
| 494 |
+
<output>
|
| 495 |
+
<port id="2" precision="I32" />
|
| 496 |
+
</output>
|
| 497 |
+
</layer>
|
| 498 |
+
<layer id="39" name="Constant_172320" type="Const" version="opset1">
|
| 499 |
+
<data element_type="i32" shape="" offset="7602764" size="4" />
|
| 500 |
+
<output>
|
| 501 |
+
<port id="0" precision="I32" />
|
| 502 |
+
</output>
|
| 503 |
+
</layer>
|
| 504 |
+
<layer id="40" name="RaggedToDense_172321" type="RaggedToDense" version="extension">
|
| 505 |
+
<data pad_right="false" m_pad_max_length="false" />
|
| 506 |
+
<input>
|
| 507 |
+
<port id="0" precision="I32">
|
| 508 |
+
<dim>-1</dim>
|
| 509 |
+
</port>
|
| 510 |
+
<port id="1" precision="I32">
|
| 511 |
+
<dim>-1</dim>
|
| 512 |
+
</port>
|
| 513 |
+
<port id="2" precision="I32">
|
| 514 |
+
<dim>-1</dim>
|
| 515 |
+
</port>
|
| 516 |
+
<port id="3" precision="I32" />
|
| 517 |
+
<port id="4" precision="I32" />
|
| 518 |
+
</input>
|
| 519 |
+
<output>
|
| 520 |
+
<port id="5" precision="I32">
|
| 521 |
+
<dim>-1</dim>
|
| 522 |
+
<dim>-1</dim>
|
| 523 |
+
</port>
|
| 524 |
+
<port id="6" precision="BOOL">
|
| 525 |
+
<dim>-1</dim>
|
| 526 |
+
<dim>-1</dim>
|
| 527 |
+
</port>
|
| 528 |
+
</output>
|
| 529 |
+
</layer>
|
| 530 |
+
<layer id="41" name="Convert_172322" type="Convert" version="opset1">
|
| 531 |
+
<data destination_type="i32" />
|
| 532 |
+
<input>
|
| 533 |
+
<port id="0" precision="BOOL">
|
| 534 |
+
<dim>-1</dim>
|
| 535 |
+
<dim>-1</dim>
|
| 536 |
+
</port>
|
| 537 |
+
</input>
|
| 538 |
+
<output>
|
| 539 |
+
<port id="1" precision="I32">
|
| 540 |
+
<dim>-1</dim>
|
| 541 |
+
<dim>-1</dim>
|
| 542 |
+
</port>
|
| 543 |
+
</output>
|
| 544 |
+
</layer>
|
| 545 |
+
<layer id="42" name="Convert_172322.0" type="Convert" version="opset1">
|
| 546 |
+
<data destination_type="i64" />
|
| 547 |
+
<input>
|
| 548 |
+
<port id="0" precision="I32">
|
| 549 |
+
<dim>-1</dim>
|
| 550 |
+
<dim>-1</dim>
|
| 551 |
+
</port>
|
| 552 |
+
</input>
|
| 553 |
+
<output>
|
| 554 |
+
<port id="1" precision="I64" names="attention_mask">
|
| 555 |
+
<dim>-1</dim>
|
| 556 |
+
<dim>-1</dim>
|
| 557 |
+
</port>
|
| 558 |
+
</output>
|
| 559 |
+
</layer>
|
| 560 |
+
<layer id="44" name="RaggedToDense_172321.0" type="Convert" version="opset1">
|
| 561 |
+
<data destination_type="i64" />
|
| 562 |
+
<input>
|
| 563 |
+
<port id="0" precision="I32">
|
| 564 |
+
<dim>-1</dim>
|
| 565 |
+
<dim>-1</dim>
|
| 566 |
+
</port>
|
| 567 |
+
</input>
|
| 568 |
+
<output>
|
| 569 |
+
<port id="1" precision="I64" names="input_ids">
|
| 570 |
+
<dim>-1</dim>
|
| 571 |
+
<dim>-1</dim>
|
| 572 |
+
</port>
|
| 573 |
+
</output>
|
| 574 |
+
</layer>
|
| 575 |
+
<layer id="45" name="Result_172323" type="Result" version="opset1" output_names="input_ids">
|
| 576 |
+
<input>
|
| 577 |
+
<port id="0" precision="I64">
|
| 578 |
+
<dim>-1</dim>
|
| 579 |
+
<dim>-1</dim>
|
| 580 |
+
</port>
|
| 581 |
+
</input>
|
| 582 |
+
</layer>
|
| 583 |
+
<layer id="43" name="Result_172324" type="Result" version="opset1" output_names="attention_mask">
|
| 584 |
+
<input>
|
| 585 |
+
<port id="0" precision="I64">
|
| 586 |
+
<dim>-1</dim>
|
| 587 |
+
<dim>-1</dim>
|
| 588 |
+
</port>
|
| 589 |
+
</input>
|
| 590 |
+
</layer>
|
| 591 |
+
</layers>
|
| 592 |
+
<edges>
|
| 593 |
+
<edge from-layer="0" from-port="0" to-layer="2" to-port="0" />
|
| 594 |
+
<edge from-layer="1" from-port="0" to-layer="8" to-port="0" />
|
| 595 |
+
<edge from-layer="2" from-port="2" to-layer="15" to-port="3" />
|
| 596 |
+
<edge from-layer="2" from-port="3" to-layer="15" to-port="4" />
|
| 597 |
+
<edge from-layer="2" from-port="1" to-layer="15" to-port="2" />
|
| 598 |
+
<edge from-layer="2" from-port="1" to-layer="3" to-port="0" />
|
| 599 |
+
<edge from-layer="3" from-port="1" to-layer="6" to-port="0" />
|
| 600 |
+
<edge from-layer="4" from-port="0" to-layer="6" to-port="1" />
|
| 601 |
+
<edge from-layer="5" from-port="0" to-layer="6" to-port="2" />
|
| 602 |
+
<edge from-layer="6" from-port="3" to-layer="8" to-port="1" />
|
| 603 |
+
<edge from-layer="6" from-port="3" to-layer="11" to-port="0" />
|
| 604 |
+
<edge from-layer="7" from-port="0" to-layer="8" to-port="2" />
|
| 605 |
+
<edge from-layer="8" from-port="3" to-layer="15" to-port="0" />
|
| 606 |
+
<edge from-layer="9" from-port="0" to-layer="13" to-port="0" />
|
| 607 |
+
<edge from-layer="10" from-port="0" to-layer="11" to-port="1" />
|
| 608 |
+
<edge from-layer="11" from-port="2" to-layer="13" to-port="1" />
|
| 609 |
+
<edge from-layer="12" from-port="0" to-layer="13" to-port="2" />
|
| 610 |
+
<edge from-layer="13" from-port="3" to-layer="15" to-port="1" />
|
| 611 |
+
<edge from-layer="14" from-port="0" to-layer="15" to-port="5" />
|
| 612 |
+
<edge from-layer="15" from-port="6" to-layer="17" to-port="0" />
|
| 613 |
+
<edge from-layer="15" from-port="7" to-layer="17" to-port="1" />
|
| 614 |
+
<edge from-layer="15" from-port="8" to-layer="17" to-port="2" />
|
| 615 |
+
<edge from-layer="15" from-port="9" to-layer="17" to-port="3" />
|
| 616 |
+
<edge from-layer="15" from-port="10" to-layer="17" to-port="4" />
|
| 617 |
+
<edge from-layer="15" from-port="11" to-layer="17" to-port="5" />
|
| 618 |
+
<edge from-layer="16" from-port="0" to-layer="17" to-port="6" />
|
| 619 |
+
<edge from-layer="17" from-port="7" to-layer="31" to-port="0" />
|
| 620 |
+
<edge from-layer="17" from-port="8" to-layer="31" to-port="1" />
|
| 621 |
+
<edge from-layer="17" from-port="9" to-layer="31" to-port="2" />
|
| 622 |
+
<edge from-layer="17" from-port="10" to-layer="31" to-port="3" />
|
| 623 |
+
<edge from-layer="17" from-port="11" to-layer="31" to-port="4" />
|
| 624 |
+
<edge from-layer="18" from-port="0" to-layer="31" to-port="5" />
|
| 625 |
+
<edge from-layer="19" from-port="0" to-layer="31" to-port="6" />
|
| 626 |
+
<edge from-layer="20" from-port="0" to-layer="31" to-port="7" />
|
| 627 |
+
<edge from-layer="21" from-port="0" to-layer="31" to-port="8" />
|
| 628 |
+
<edge from-layer="22" from-port="0" to-layer="31" to-port="9" />
|
| 629 |
+
<edge from-layer="23" from-port="0" to-layer="31" to-port="10" />
|
| 630 |
+
<edge from-layer="24" from-port="0" to-layer="31" to-port="11" />
|
| 631 |
+
<edge from-layer="25" from-port="0" to-layer="31" to-port="12" />
|
| 632 |
+
<edge from-layer="26" from-port="0" to-layer="31" to-port="13" />
|
| 633 |
+
<edge from-layer="27" from-port="0" to-layer="31" to-port="14" />
|
| 634 |
+
<edge from-layer="28" from-port="0" to-layer="31" to-port="15" />
|
| 635 |
+
<edge from-layer="29" from-port="0" to-layer="31" to-port="16" />
|
| 636 |
+
<edge from-layer="30" from-port="0" to-layer="31" to-port="17" />
|
| 637 |
+
<edge from-layer="31" from-port="19" to-layer="35" to-port="0" />
|
| 638 |
+
<edge from-layer="31" from-port="20" to-layer="40" to-port="2" />
|
| 639 |
+
<edge from-layer="31" from-port="19" to-layer="40" to-port="1" />
|
| 640 |
+
<edge from-layer="31" from-port="19" to-layer="36" to-port="0" />
|
| 641 |
+
<edge from-layer="31" from-port="18" to-layer="32" to-port="1" />
|
| 642 |
+
<edge from-layer="31" from-port="19" to-layer="32" to-port="0" />
|
| 643 |
+
<edge from-layer="32" from-port="2" to-layer="34" to-port="0" />
|
| 644 |
+
<edge from-layer="33" from-port="0" to-layer="34" to-port="1" />
|
| 645 |
+
<edge from-layer="34" from-port="2" to-layer="35" to-port="1" />
|
| 646 |
+
<edge from-layer="35" from-port="2" to-layer="36" to-port="1" />
|
| 647 |
+
<edge from-layer="35" from-port="2" to-layer="40" to-port="0" />
|
| 648 |
+
<edge from-layer="36" from-port="2" to-layer="38" to-port="0" />
|
| 649 |
+
<edge from-layer="37" from-port="0" to-layer="38" to-port="1" />
|
| 650 |
+
<edge from-layer="38" from-port="2" to-layer="40" to-port="3" />
|
| 651 |
+
<edge from-layer="39" from-port="0" to-layer="40" to-port="4" />
|
| 652 |
+
<edge from-layer="40" from-port="6" to-layer="41" to-port="0" />
|
| 653 |
+
<edge from-layer="40" from-port="5" to-layer="44" to-port="0" />
|
| 654 |
+
<edge from-layer="41" from-port="1" to-layer="42" to-port="0" />
|
| 655 |
+
<edge from-layer="42" from-port="1" to-layer="43" to-port="0" />
|
| 656 |
+
<edge from-layer="44" from-port="1" to-layer="45" to-port="0" />
|
| 657 |
+
</edges>
|
| 658 |
+
<rt_info>
|
| 659 |
+
<add_attention_mask value="True" />
|
| 660 |
+
<add_prefix_space />
|
| 661 |
+
<add_special_tokens value="True" />
|
| 662 |
+
<bos_token_id value="199999" />
|
| 663 |
+
<chat_template value="{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}" />
|
| 664 |
+
<clean_up_tokenization_spaces />
|
| 665 |
+
<detokenizer_input_type value="i64" />
|
| 666 |
+
<eos_token_id value="199999" />
|
| 667 |
+
<handle_special_tokens_with_re />
|
| 668 |
+
<max_length />
|
| 669 |
+
<number_of_inputs value="1" />
|
| 670 |
+
<openvino_tokenizers_version value="2025.1.0.0-523-710ddf14de8" />
|
| 671 |
+
<openvino_version value="2025.1.0-18503-6fec06580ab-releases/2025/1" />
|
| 672 |
+
<original_tokenizer_class value="<class 'transformers.models.gpt2.tokenization_gpt2_fast.GPT2TokenizerFast'>" />
|
| 673 |
+
<pad_token_id value="199999" />
|
| 674 |
+
<sentencepiece_version value="0.2.0" />
|
| 675 |
+
<skip_special_tokens value="True" />
|
| 676 |
+
<streaming_detokenizer value="False" />
|
| 677 |
+
<tiktoken_version value="0.7.0" />
|
| 678 |
+
<tokenizer_output_type value="i64" />
|
| 679 |
+
<tokenizers_version value="0.21.1" />
|
| 680 |
+
<transformers_version value="4.49.0" />
|
| 681 |
+
<use_max_padding value="False" />
|
| 682 |
+
<use_sentencepiece_backend value="False" />
|
| 683 |
+
<utf8_replace_mode value="replace" />
|
| 684 |
+
<with_detokenizer value="True" />
|
| 685 |
+
</rt_info>
|
| 686 |
+
</net>
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|endoftext|>",
|
| 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": "<|endoftext|>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:382cc235b56c725945e149cc25f191da667c836655efd0857b004320e90e91ea
|
| 3 |
+
size 15524095
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"add_prefix_space": false,
|
| 5 |
+
"added_tokens_decoder": {
|
| 6 |
+
"199999": {
|
| 7 |
+
"content": "<|endoftext|>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false,
|
| 12 |
+
"special": true
|
| 13 |
+
},
|
| 14 |
+
"200018": {
|
| 15 |
+
"content": "<|endofprompt|>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": false,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false,
|
| 20 |
+
"special": true
|
| 21 |
+
},
|
| 22 |
+
"200019": {
|
| 23 |
+
"content": "<|assistant|>",
|
| 24 |
+
"lstrip": false,
|
| 25 |
+
"normalized": false,
|
| 26 |
+
"rstrip": true,
|
| 27 |
+
"single_word": false,
|
| 28 |
+
"special": true
|
| 29 |
+
},
|
| 30 |
+
"200020": {
|
| 31 |
+
"content": "<|end|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": true,
|
| 35 |
+
"single_word": false,
|
| 36 |
+
"special": true
|
| 37 |
+
},
|
| 38 |
+
"200021": {
|
| 39 |
+
"content": "<|user|>",
|
| 40 |
+
"lstrip": false,
|
| 41 |
+
"normalized": false,
|
| 42 |
+
"rstrip": true,
|
| 43 |
+
"single_word": false,
|
| 44 |
+
"special": true
|
| 45 |
+
},
|
| 46 |
+
"200022": {
|
| 47 |
+
"content": "<|system|>",
|
| 48 |
+
"lstrip": false,
|
| 49 |
+
"normalized": false,
|
| 50 |
+
"rstrip": true,
|
| 51 |
+
"single_word": false,
|
| 52 |
+
"special": true
|
| 53 |
+
},
|
| 54 |
+
"200023": {
|
| 55 |
+
"content": "<|tool|>",
|
| 56 |
+
"lstrip": false,
|
| 57 |
+
"normalized": false,
|
| 58 |
+
"rstrip": true,
|
| 59 |
+
"single_word": false,
|
| 60 |
+
"special": false
|
| 61 |
+
},
|
| 62 |
+
"200024": {
|
| 63 |
+
"content": "<|/tool|>",
|
| 64 |
+
"lstrip": false,
|
| 65 |
+
"normalized": false,
|
| 66 |
+
"rstrip": true,
|
| 67 |
+
"single_word": false,
|
| 68 |
+
"special": false
|
| 69 |
+
},
|
| 70 |
+
"200025": {
|
| 71 |
+
"content": "<|tool_call|>",
|
| 72 |
+
"lstrip": false,
|
| 73 |
+
"normalized": false,
|
| 74 |
+
"rstrip": true,
|
| 75 |
+
"single_word": false,
|
| 76 |
+
"special": false
|
| 77 |
+
},
|
| 78 |
+
"200026": {
|
| 79 |
+
"content": "<|/tool_call|>",
|
| 80 |
+
"lstrip": false,
|
| 81 |
+
"normalized": false,
|
| 82 |
+
"rstrip": true,
|
| 83 |
+
"single_word": false,
|
| 84 |
+
"special": false
|
| 85 |
+
},
|
| 86 |
+
"200027": {
|
| 87 |
+
"content": "<|tool_response|>",
|
| 88 |
+
"lstrip": false,
|
| 89 |
+
"normalized": false,
|
| 90 |
+
"rstrip": true,
|
| 91 |
+
"single_word": false,
|
| 92 |
+
"special": false
|
| 93 |
+
},
|
| 94 |
+
"200028": {
|
| 95 |
+
"content": "<|tag|>",
|
| 96 |
+
"lstrip": false,
|
| 97 |
+
"normalized": false,
|
| 98 |
+
"rstrip": true,
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"special": true
|
| 101 |
+
}
|
| 102 |
+
},
|
| 103 |
+
"bos_token": "<|endoftext|>",
|
| 104 |
+
"chat_template": "{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}",
|
| 105 |
+
"clean_up_tokenization_spaces": false,
|
| 106 |
+
"eos_token": "<|endoftext|>",
|
| 107 |
+
"extra_special_tokens": {},
|
| 108 |
+
"model_max_length": 131072,
|
| 109 |
+
"pad_token": "<|endoftext|>",
|
| 110 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 111 |
+
"unk_token": "<|endoftext|>"
|
| 112 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|