commit 7fc96fc8c39813f5b6c71a62e483d295c388be70 Author: ModelHub XC Date: Fri Aug 14 06:43:13 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: FreedomIntelligence/HuatuoGPT-3-7B-Pangu Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d394c09 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,57 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bin.* filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text + +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zstandard filter=lfs diff=lfs merge=lfs -text +*.tfevents* filter=lfs diff=lfs merge=lfs -text +*.db* filter=lfs diff=lfs merge=lfs -text +*.ark* filter=lfs diff=lfs merge=lfs -text +**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text +**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text +**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text + +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.gguf* filter=lfs diff=lfs merge=lfs -text +*.ggml filter=lfs diff=lfs merge=lfs -text +*.llamafile* filter=lfs diff=lfs merge=lfs -text +*.pt2 filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text + + + + + + + +*.safetensors filter=lfs diff=lfs merge=lfs -text + +*.model filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a32e5f2 --- /dev/null +++ b/README.md @@ -0,0 +1,130 @@ +--- +library_name: transformers +license: apache-2.0 +pipeline_tag: text-generation +language: +- en +- zh +base_model: +- FreedomIntelligence/openPangu-Embedded-7B +tags: +- medical +- reasoning +--- + +
+

🩺 HuatuoGPT-3-7B-Pangu

+
+ +
+ 🏠 GitHub + | + 📄 Paper +
+ +# Introduction + +**HuatuoGPT-3** is an open-source medical LLM trained with **SeedRL**, an RL-only domain adaptation paradigm that transforms a base model into a medical expert in a single RL stage. + +**HuatuoGPT-3-7B-Pangu** is the Pangu-based variant in the HuatuoGPT-3 series. Different from the Qwen-based versions, it is built on **FreedomIntelligence/openPangu-Embedded-7B** and trained with **Ascend NPUs**. + +For more information, visit our GitHub repository: +[https://github.com/FreedomIntelligence/HuatuoGPT-3](https://github.com/FreedomIntelligence/HuatuoGPT-3) + +> [!IMPORTANT] +> **HuatuoGPT-3-7B-Pangu is set to thinking mode by default.** Since it is based on openPangu, the generated reasoning content is placed between `[unused16]` and `[unused17]`, and the final response starts after `[unused17]`. + +# Model Info + +| Model | Description | Backbone | Link | +| --- | --- | --- | --- | +| **HuatuoGPT-3-32B** | 32B medical LLM trained with SeedRL | Qwen3-32B | [HF Link](https://huggingface.co/FreedomIntelligence/HuatuoGPT-3-32B) | +| **HuatuoGPT-3-8B** | 8B medical LLM trained with SeedRL | Qwen3-8B-Base | [HF Link](https://huggingface.co/FreedomIntelligence/HuatuoGPT-3-8B) | +| **HuatuoGPT-3-7B-Pangu** | 7B medical LLM trained with SeedRL | openPangu-Embedded-7B | [HF Link](https://huggingface.co/FreedomIntelligence/HuatuoGPT-3-7B-Pangu) | + +# Usage + +You can use HuatuoGPT-3-7B-Pangu in the same way as `FreedomIntelligence/openPangu-Embedded-7B`. + +When using this model, please note that the Pangu backbone requires `trust_remote_code=True` in Transformers, and `--trust_remote_code` when serving with vLLM. + +- Direct inference: + +```python +from transformers import AutoModelForCausalLM, AutoTokenizer + +model_name = "FreedomIntelligence/HuatuoGPT-3-7B-Pangu" + +tokenizer = AutoTokenizer.from_pretrained( + model_name, + use_fast=False, + trust_remote_code=True +) +model = AutoModelForCausalLM.from_pretrained( + model_name, + trust_remote_code=True, + torch_dtype="auto", + device_map="auto" +) + +messages = [ + {"role": "user", "content": "What are the common causes of chest pain?"} +] + +text = tokenizer.apply_chat_template( + messages, + tokenize=False, + add_generation_prompt=True +) + +inputs = tokenizer([text], return_tensors="pt").to(model.device) +outputs = model.generate( + **inputs, + max_new_tokens=4096, + eos_token_id=45892, + return_dict_in_generate=True +) + +input_length = inputs.input_ids.shape[1] +generated_tokens = outputs.sequences[:, input_length:] +output_text = tokenizer.decode(generated_tokens[0]) + +thinking_content = output_text.split("[unused17]")[0].split("[unused16]")[-1].strip() +content = output_text.split("[unused17]")[-1].split("[unused10]")[0].strip() + +print("thinking content:", thinking_content) +print("content:", content) +``` + +- You can also serve the model with vLLM. Make sure to include `--trust_remote_code`: + +```bash +CUDA_VISIBLE_DEVICES=0 \ +vllm serve FreedomIntelligence/HuatuoGPT-3-7B-Pangu \ + --served-model-name HuatuoGPT-3-7B-Pangu \ + --trust_remote_code \ + --port 8000 +``` + +Or: + +```bash +CUDA_VISIBLE_DEVICES=0 \ +python -m vllm.entrypoints.openai.api_server \ + --model FreedomIntelligence/HuatuoGPT-3-7B-Pangu \ + --served-model-name HuatuoGPT-3-7B-Pangu \ + --trust_remote_code \ + --port 8000 +``` + + +# 📖 Citation + +```bibtex +@article{huatuogpt3, + title={HuatuoGPT-3: RL-Only Domain Adaptation from Base Models via Off-Policy Seeding}, + author={Coming soon}, + journal={arXiv preprint}, + year={2026} +} +``` diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..d304366 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1 @@ +{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '[unused9]系统:[unused10]' }}{% endif %}{% if message['role'] == 'system' %}{{ '[unused9]系统:' + message['content'] + '[unused10]' }}{% endif %}{% if message['role'] == 'assistant' %}{{'[unused9]助手:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'tool' %}{{'[unused9]工具:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'function' %}{{'[unused9]方法:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'user' %}{{'[unused9]用户:' + message['content'] + '[unused10]'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '[unused9]助手:' }}{% endif %} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..10ec88a --- /dev/null +++ b/config.json @@ -0,0 +1,31 @@ +{ + "architectures": [ + "PanguEmbeddedForCausalLM" + ], + "attention_dropout": 0.0, + "auto_map": { + "AutoConfig": "configuration_openpangu_dense.PanguEmbeddedConfig", + "AutoModel": "modeling_openpangu_dense.PanguEmbeddedModel", + "AutoModelForCausalLM": "modeling_openpangu_dense.PanguEmbeddedForCausalLM" + }, + "bias": true, + "bos_token_id": 1, + "dtype": "bfloat16", + "eos_token_id": 45892, + "hidden_act": "silu", + "hidden_size": 4096, + "initializer_range": 0.02, + "intermediate_size": 12800, + "max_position_embeddings": 32768, + "model_type": "PanguEmbedded", + "num_attention_heads": 32, + "num_hidden_layers": 34, + "num_key_value_heads": 8, + "pad_token_id": 0, + "rms_norm_eps": 1e-05, + "rope_theta": 16000000.0, + "tie_word_embeddings": false, + "transformers_version": "4.57.3", + "use_cache": true, + "vocab_size": 153376 +} diff --git a/configuration.json b/configuration.json new file mode 100644 index 0000000..bbeeda1 --- /dev/null +++ b/configuration.json @@ -0,0 +1 @@ +{"framework": "pytorch", "task": "text-generation", "allow_remote": true} \ No newline at end of file diff --git a/configuration_openpangu_dense.py b/configuration_openpangu_dense.py new file mode 100644 index 0000000..72505be --- /dev/null +++ b/configuration_openpangu_dense.py @@ -0,0 +1,56 @@ +# coding=utf-8 +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + +from transformers.utils import logging +from transformers.configuration_utils import PretrainedConfig + + +logger = logging.get_logger(__name__) + + +class PanguEmbeddedConfig(PretrainedConfig): + + model_type = "PanguEmbedded" + _auto_class = "AutoConfig" + + def __init__( + self, + vocab_size=153376, + hidden_size=4096, + intermediate_size=12800, + num_hidden_layers=34, + num_attention_heads=32, + num_key_value_heads=8, + hidden_act="silu", + max_position_embeddings=32768, + initializer_range=0.02, + rms_norm_eps=1e-5, + use_cache=True, + pad_token_id=0, + bos_token_id=1, + eos_token_id=45892, + tie_word_embeddings=False, + rope_theta=16000000.0, + bias=True, + **kwargs, + ): + self.vocab_size = vocab_size + self.max_position_embeddings = max_position_embeddings + self.hidden_size = hidden_size + self.intermediate_size = intermediate_size + self.num_hidden_layers = num_hidden_layers + self.num_attention_heads = num_attention_heads + self.num_key_value_heads = num_key_value_heads + self.hidden_act = hidden_act + self.initializer_range = initializer_range + self.rms_norm_eps = rms_norm_eps + self.use_cache = use_cache + self.rope_theta = rope_theta + self.bias = bias + super().__init__( + pad_token_id=pad_token_id, + bos_token_id=bos_token_id, + eos_token_id=eos_token_id, + tie_word_embeddings=tie_word_embeddings, + **kwargs, + ) diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..8a6c5f8 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,10 @@ +{ + "_from_model_config": true, + "bos_token_id": 1, + "do_sample": true, + "eos_token_id": 45892, + "pad_token_id": 0, + "top_k": 0, + "top_p": 0.8, + "transformers_version": "4.57.3" +} diff --git a/model-00001-of-00004.safetensors b/model-00001-of-00004.safetensors new file mode 100644 index 0000000..3ecd7ab --- /dev/null +++ b/model-00001-of-00004.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b92db8321039ac073b0599b71f94ca36de8f1fcc0295398d6dc714e24a75e48c +size 4968747160 diff --git a/model-00002-of-00004.safetensors b/model-00002-of-00004.safetensors new file mode 100644 index 0000000..f629b34 --- /dev/null +++ b/model-00002-of-00004.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e631d9f32776f4a9ac448744ef34097a7d4100856bbedb4785d29798a8a4eeff +size 4987563272 diff --git a/model-00003-of-00004.safetensors b/model-00003-of-00004.safetensors new file mode 100644 index 0000000..ba22eb5 --- /dev/null +++ b/model-00003-of-00004.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64357389fe7f4e46de3a92f99206c92bc83784c3e12edab30d2dd4c69f2ebddc +size 3951399856 diff --git a/model-00004-of-00004.safetensors b/model-00004-of-00004.safetensors new file mode 100644 index 0000000..7b25910 --- /dev/null +++ b/model-00004-of-00004.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:941d0b1409340b491b3d6c017b6b1a2c742e4a9d7c2b9553419706f110fe3431 +size 2154116592 diff --git a/model.safetensors.index.json b/model.safetensors.index.json new file mode 100644 index 0000000..d970d9c --- /dev/null +++ b/model.safetensors.index.json @@ -0,0 +1,453 @@ +{ + "metadata": { + "total_parameters": 8030887936, + "total_size": 16061775872 + }, + "weight_map": { + "lm_head.weight": "model-00004-of-00004.safetensors", + "model.embed_tokens.weight": "model-00001-of-00004.safetensors", + "model.layers.0.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.0.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.0.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.0.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.0.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.0.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.0.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.0.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.0.self_attn.q_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.0.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.0.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.1.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.1.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.1.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.1.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.1.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.1.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.1.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.1.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.1.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.1.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.10.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.10.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.10.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.10.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.10.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.10.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.10.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.10.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.10.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.11.input_layernorm.weight": "model-00004-of-00004.safetensors", + "model.layers.11.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.11.mlp.up_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.11.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.11.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.11.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.11.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.12.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.12.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.12.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.12.self_attn.v_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.12.self_attn.v_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.13.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.13.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.13.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.13.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.13.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.13.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.14.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.14.mlp.up_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.14.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.14.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.14.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.14.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.14.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.14.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.15.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.15.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.15.self_attn.k_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.15.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.15.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.15.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.16.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.16.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.16.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.16.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.16.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.16.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.16.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.17.input_layernorm.weight": "model-00004-of-00004.safetensors", + "model.layers.17.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.17.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.17.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.17.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.17.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.17.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.18.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.18.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.18.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.18.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.18.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.18.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.18.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.18.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.18.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.19.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.19.mlp.down_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.19.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.19.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.19.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.19.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.2.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.2.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.2.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.2.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.2.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.2.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.2.self_attn.q_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.2.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.2.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.20.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.20.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.20.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.20.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.20.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.20.self_attn.q_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.21.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.21.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.21.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.21.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.21.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.22.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.22.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.22.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.23.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.23.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.23.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.23.self_attn.k_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.23.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.23.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.23.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.23.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.23.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.23.self_attn.v_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.24.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.24.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.24.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.24.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.24.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.24.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.24.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.24.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.25.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.25.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.25.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.25.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.25.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.25.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.25.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.25.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.25.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.26.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.26.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.26.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.26.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.26.self_attn.k_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.26.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.26.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.26.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.26.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.27.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.27.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.27.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.27.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.27.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.27.self_attn.q_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.27.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.27.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.28.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.28.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.28.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.28.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.28.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.28.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.28.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.28.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.28.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.29.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.29.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.29.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.29.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.29.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.29.self_attn.o_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.29.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.29.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.29.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.29.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.3.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.3.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.3.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.3.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.3.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.3.self_attn.q_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.3.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.3.self_attn.v_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.3.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.30.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.30.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.30.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.30.post_attention_layernorm.weight": "model-00004-of-00004.safetensors", + "model.layers.30.self_attn.k_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.30.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.30.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.30.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.30.self_attn.v_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.30.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.31.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.31.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.31.mlp.gate_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.31.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.31.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.31.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.31.self_attn.o_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.31.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.31.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.31.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.31.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.31.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.32.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.32.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.32.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.32.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.32.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.32.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.32.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.32.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.32.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.32.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.32.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.32.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.32.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.33.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.33.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.33.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.33.mlp.up_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.33.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.33.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.33.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.33.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.33.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.33.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.33.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.33.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.33.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.4.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.4.mlp.gate_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.4.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.4.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.4.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.4.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.4.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.4.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.4.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.4.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.5.input_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.5.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.5.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.5.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.5.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.5.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.5.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.5.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.5.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.6.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.6.mlp.down_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.6.mlp.up_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.6.self_attn.k_proj.bias": "model-00004-of-00004.safetensors", + "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.6.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.6.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.6.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors", + "model.layers.7.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.7.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", + "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.7.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.7.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.7.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.7.self_attn.q_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.7.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.8.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.8.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.8.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.8.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.8.self_attn.o_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.8.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.8.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.8.self_attn.v_proj.bias": "model-00003-of-00004.safetensors", + "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.9.input_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.9.mlp.down_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.9.mlp.up_proj.weight": "model-00003-of-00004.safetensors", + "model.layers.9.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", + "model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", + "model.layers.9.self_attn.o_proj.bias": "model-00001-of-00004.safetensors", + "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", + "model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.9.self_attn.q_proj.weight": "model-00004-of-00004.safetensors", + "model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors", + "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", + "model.norm.weight": "model-00002-of-00004.safetensors" + } +} diff --git a/modeling_openpangu_dense.py b/modeling_openpangu_dense.py new file mode 100644 index 0000000..f1ef695 --- /dev/null +++ b/modeling_openpangu_dense.py @@ -0,0 +1,594 @@ +# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 +# This file was automatically generated from modular_openpangu_dense.py. +# Do NOT edit this file manually as any edits will be overwritten by the generation of +# the file from the modular. If any change should be done, please apply the change to the +# modular_openpangu_dense.py file directly. One of our CI enforces this. +# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 + +# coding=utf-8 +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. +# +# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX +# and OPT implementations in this library. It has been modified from its +# original forms to accommodate minor architectural differences compared +# to GPT-NeoX and OPT used by the Meta AI team that trained the model. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Callable, Optional, Union + +import torch +from torch import nn + +try: + import torch_npu + from torch_npu.contrib import transfer_to_npu + if "910" in torch.npu.get_device_name(): + NPU_ATTN_INFR = True + print("[INFO] torch_npu detected. Using NPU fused infer attention.") + else: + NPU_ATTN_INFR = False +except ImportError: + NPU_ATTN_INFR = False + +from transformers.activations import ACT2FN +from transformers.cache_utils import Cache, DynamicCache +from transformers.generation import GenerationMixin +from transformers.masking_utils import create_causal_mask +from transformers.modeling_flash_attention_utils import FlashAttentionKwargs +from transformers.modeling_layers import GradientCheckpointingLayer +from transformers.modeling_outputs import ( + BaseModelOutputWithPast, + CausalLMOutputWithPast, + SequenceClassifierOutputWithPast, +) +from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update +from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel +from transformers.processing_utils import Unpack +try: + from transformers.utils import LossKwargs, auto_docstring, can_return_tuple, logging +except ImportError: + from transformers.utils import auto_docstring, can_return_tuple, logging + from typing import TypedDict + class LossKwargs(TypedDict, total=False): + pass +from .configuration_openpangu_dense import PanguEmbeddedConfig + + +logger = logging.get_logger(__name__) + + +class PanguEmbeddedRMSNorm(nn.Module): + def __init__(self, hidden_size, eps=1e-6): + """ + PanguEmbeddedRMSNorm is equivalent to T5LayerNorm + """ + super().__init__() + self.weight = nn.Parameter(torch.ones(hidden_size)) + self.variance_epsilon = eps + + def forward(self, hidden_states): + input_dtype = hidden_states.dtype + hidden_states = hidden_states.to(torch.float32) + variance = hidden_states.pow(2).mean(-1, keepdim=True) + hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon) + return self.weight * hidden_states.to(input_dtype) + + def extra_repr(self): + return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}" + + +class PanguEmbeddedRotaryEmbedding(nn.Module): + def __init__(self, config: PanguEmbeddedConfig, device=None): + super().__init__() + # BC: "rope_type" was originally "type" + if hasattr(config, "rope_scaling") and config.rope_scaling is not None: + self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type")) + else: + self.rope_type = "default" + self.max_seq_len_cached = config.max_position_embeddings + self.original_max_seq_len = config.max_position_embeddings + + self.config = config + self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type] + + inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device) + self.register_buffer("inv_freq", inv_freq, persistent=False) + self.original_inv_freq = self.inv_freq + + @torch.no_grad() + @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope) + def forward(self, x, position_ids): + inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device) + position_ids_expanded = position_ids[:, None, :].float() + + device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu" + with torch.autocast(device_type=device_type, enabled=False): # Force float32 + freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2) + emb = torch.cat((freqs, freqs), dim=-1) + cos = emb.cos() * self.attention_scaling + sin = emb.sin() * self.attention_scaling + + return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype) + + +def rotate_half(x): + """Rotates half the hidden dims of the input.""" + x1 = x[..., : x.shape[-1] // 2] + x2 = x[..., x.shape[-1] // 2 :] + return torch.cat((-x2, x1), dim=-1) + + +def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1): + """Applies Rotary Position Embedding to the query and key tensors. + + Args: + q (`torch.Tensor`): The query tensor. + k (`torch.Tensor`): The key tensor. + cos (`torch.Tensor`): The cosine part of the rotary embedding. + sin (`torch.Tensor`): The sine part of the rotary embedding. + position_ids (`torch.Tensor`, *optional*): + Deprecated and unused. + unsqueeze_dim (`int`, *optional*, defaults to 1): + The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and + sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note + that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and + k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes + cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have + the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2. + Returns: + `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding. + """ + cos = cos.unsqueeze(unsqueeze_dim) + sin = sin.unsqueeze(unsqueeze_dim) + q_embed = (q * cos) + (rotate_half(q) * sin) + k_embed = (k * cos) + (rotate_half(k) * sin) + return q_embed, k_embed + + +class PanguEmbeddedMLP(nn.Module): + def __init__(self, config): + super().__init__() + self.config = config + self.hidden_size = config.hidden_size + self.intermediate_size = config.intermediate_size + self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False) + self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False) + self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False) + self.act_fn = ACT2FN[config.hidden_act] + + def forward(self, x): + down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x)) + return down_proj + + +def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor: + """ + This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, + num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim) + """ + batch, num_key_value_heads, slen, head_dim = hidden_states.shape + if n_rep == 1: + return hidden_states + hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim) + return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim) + + +def eager_attention_forward( + module: nn.Module, + query: torch.Tensor, + key: torch.Tensor, + value: torch.Tensor, + attention_mask: Optional[torch.Tensor], + scaling: float, + dropout: float = 0.0, + **kwargs, +): + key_states = repeat_kv(key, module.num_key_value_groups) + value_states = repeat_kv(value, module.num_key_value_groups) + + attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling + if attention_mask is not None: + causal_mask = attention_mask[:, :, :, : key_states.shape[-2]] + attn_weights = attn_weights + causal_mask + + attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype) + attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training) + attn_output = torch.matmul(attn_weights, value_states) + attn_output = attn_output.transpose(1, 2).contiguous() + + return attn_output, attn_weights + + +class PanguEmbeddedAttention(nn.Module): + """Multi-headed attention from 'Attention Is All You Need' paper""" + + def __init__(self, config: PanguEmbeddedConfig, layer_idx: int): + super().__init__() + self.config = config + self.layer_idx = layer_idx + self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads) + self.num_heads = config.num_attention_heads + self.num_key_value_heads = config.num_key_value_heads + self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads + self.scaling = self.head_dim**-0.5 + self.attention_dropout = config.attention_dropout + self.is_causal = True + + self.q_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.bias) + self.k_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.bias) + self.v_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.bias) + self.o_proj = nn.Linear(config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.bias) + + def forward( + self, + hidden_states: torch.Tensor, + position_embeddings: tuple[torch.Tensor, torch.Tensor], + attention_mask: Optional[torch.Tensor], + past_key_value: Optional[Cache] = None, + cache_position: Optional[torch.LongTensor] = None, + **kwargs: Unpack[FlashAttentionKwargs], + ) -> tuple[torch.Tensor, Optional[torch.Tensor], Optional[tuple[torch.Tensor]]]: + input_shape = hidden_states.shape[:-1] + hidden_shape = (*input_shape, -1, self.head_dim) + + query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2) + key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2) + value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2) + + cos, sin = position_embeddings + query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin) + + if past_key_value is not None: + # sin and cos are specific to RoPE models; cache_position needed for the static cache + cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position} + key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs) + + attention_interface: Callable = eager_attention_forward + if self.config._attn_implementation != "eager": + attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation] + + if not self.training and NPU_ATTN_INFR: + q_len = input_shape[1] + if attention_mask is not None: + attention_mask = ~attention_mask.bool() + elif q_len > 1: + attention_mask = torch.triu(torch.ones([q_len, q_len]), diagonal=1).bool().unsqueeze(0).unsqueeze(0).to(query_states.device) + + attn_output, _ = torch_npu.npu_fused_infer_attention_score( + query_states, key_states, value_states, + num_heads=self.num_heads, num_key_value_heads=self.num_key_value_heads, + input_layout="BNSD", atten_mask=attention_mask, scale=self.scaling) + attn_output = attn_output.transpose(1, 2) + attn_weights = None + else: + attn_output, attn_weights = attention_interface( + self, + query_states, + key_states, + value_states, + attention_mask, + dropout=0.0 if not self.training else self.attention_dropout, + scaling=self.scaling, + **kwargs, + ) + + attn_output = attn_output.reshape(*input_shape, -1).contiguous() + attn_output = self.o_proj(attn_output) + return attn_output, attn_weights + + +class PanguEmbeddedDecoderLayer(GradientCheckpointingLayer): + def __init__(self, config: PanguEmbeddedConfig, layer_idx: int): + super().__init__() + self.hidden_size = config.hidden_size + self.self_attn = PanguEmbeddedAttention(config=config, layer_idx=layer_idx) + self.mlp = PanguEmbeddedMLP(config) + self.input_layernorm = PanguEmbeddedRMSNorm(config.hidden_size, eps=config.rms_norm_eps) + self.post_attention_layernorm = PanguEmbeddedRMSNorm(config.hidden_size, eps=config.rms_norm_eps) + + def forward( + self, + hidden_states: torch.Tensor, + attention_mask: Optional[torch.Tensor] = None, + position_ids: Optional[torch.LongTensor] = None, + past_key_value: Optional[Cache] = None, + output_attentions: Optional[bool] = False, + use_cache: Optional[bool] = False, + cache_position: Optional[torch.LongTensor] = None, + position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC + **kwargs: Unpack[FlashAttentionKwargs], + ) -> tuple[torch.FloatTensor, Optional[tuple[torch.FloatTensor, torch.FloatTensor]]]: + residual = hidden_states + hidden_states = self.input_layernorm(hidden_states) + + # Self Attention + hidden_states, self_attn_weights = self.self_attn( + hidden_states=hidden_states, + attention_mask=attention_mask, + position_ids=position_ids, + past_key_value=past_key_value, + output_attentions=output_attentions, + use_cache=use_cache, + cache_position=cache_position, + position_embeddings=position_embeddings, + **kwargs, + ) + hidden_states = residual + hidden_states + + # Fully Connected + residual = hidden_states + hidden_states = self.post_attention_layernorm(hidden_states) + hidden_states = self.mlp(hidden_states) + hidden_states = residual + hidden_states + + outputs = (hidden_states,) + if output_attentions: + outputs += (self_attn_weights,) + + return outputs + + +@auto_docstring +class PanguEmbeddedPreTrainedModel(PreTrainedModel): + config_class = PanguEmbeddedConfig + base_model_prefix = "model" + supports_gradient_checkpointing = True + _no_split_modules = ["PanguEmbeddedDecoderLayer"] + _skip_keys_device_placement = ["past_key_values"] + _supports_flash_attn_3 = True + _supports_flash_attn_2 = True + _supports_sdpa = True + _supports_flex_attn = True + _supports_cache_class = True + _supports_quantized_cache = True + _supports_static_cache = True + _supports_attention_backend = True + + def _init_weights(self, module): + std = self.config.initializer_range + if isinstance(module, nn.Linear): + module.weight.data.normal_(mean=0.0, std=std) + if module.bias is not None: + module.bias.data.zero_() + elif isinstance(module, nn.Embedding): + module.weight.data.normal_(mean=0.0, std=std) + if module.padding_idx is not None: + module.weight.data[module.padding_idx].zero_() + elif isinstance(module, PanguEmbeddedRMSNorm): + module.weight.data.fill_(1.0) + + +@auto_docstring +class PanguEmbeddedModel(PanguEmbeddedPreTrainedModel): + def __init__(self, config: PanguEmbeddedConfig): + super().__init__(config) + self.padding_idx = config.pad_token_id + self.vocab_size = config.vocab_size + + self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx) + self.layers = nn.ModuleList( + [PanguEmbeddedDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)] + ) + self.norm = PanguEmbeddedRMSNorm(config.hidden_size, eps=config.rms_norm_eps) + self.rotary_emb = PanguEmbeddedRotaryEmbedding(config=config) + self.gradient_checkpointing = False + + # Initialize weights and apply final processing + self.post_init() + + def get_input_embeddings(self): + return self.embed_tokens + + def set_input_embeddings(self, value): + self.embed_tokens = value + + @can_return_tuple + @auto_docstring + def forward( + self, + input_ids: Optional[torch.LongTensor] = None, + attention_mask: Optional[torch.Tensor] = None, + position_ids: Optional[torch.LongTensor] = None, + past_key_values: Optional[Cache] = None, + inputs_embeds: Optional[torch.FloatTensor] = None, + use_cache: Optional[bool] = None, + output_attentions: Optional[bool] = None, + output_hidden_states: Optional[bool] = None, + cache_position: Optional[torch.LongTensor] = None, + **flash_attn_kwargs: Unpack[FlashAttentionKwargs], + ) -> BaseModelOutputWithPast: + output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions + output_hidden_states = ( + output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states + ) + use_cache = use_cache if use_cache is not None else self.config.use_cache + + if (input_ids is None) ^ (inputs_embeds is not None): + raise ValueError("You must specify exactly one of input_ids or inputs_embeds") + + if self.gradient_checkpointing and self.training and use_cache: + logger.warning_once( + "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`." + ) + use_cache = False + + # TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache + if not isinstance(past_key_values, (type(None), Cache)): + raise ValueError("The `past_key_values` should be either a `Cache` object or `None`.") + + if inputs_embeds is None: + inputs_embeds = self.embed_tokens(input_ids) + + if use_cache and past_key_values is None: + past_key_values = DynamicCache() + + if cache_position is None: + past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0 + cache_position = torch.arange( + past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device + ) + + if position_ids is None: + position_ids = cache_position.unsqueeze(0) + + causal_mask = create_causal_mask( + config=self.config, + input_embeds=inputs_embeds, + attention_mask=attention_mask, + cache_position=cache_position, + past_key_values=past_key_values, + position_ids=position_ids, + ) + + hidden_states = inputs_embeds + + # create position embeddings to be shared across the decoder layers + position_embeddings = self.rotary_emb(hidden_states, position_ids) + + # decoder layers + all_hidden_states = () if output_hidden_states else None + all_self_attns = () if output_attentions else None + + for decoder_layer in self.layers[: self.config.num_hidden_layers]: + if output_hidden_states: + all_hidden_states += (hidden_states,) + + layer_outputs = decoder_layer( + hidden_states, + attention_mask=causal_mask, + position_ids=position_ids, + past_key_value=past_key_values, + output_attentions=output_attentions, + use_cache=use_cache, + cache_position=cache_position, + position_embeddings=position_embeddings, + **flash_attn_kwargs, + ) + + hidden_states = layer_outputs[0] + + if output_attentions: + all_self_attns += (layer_outputs[1],) + + hidden_states = self.norm(hidden_states) + + # add hidden states from the last decoder layer + if output_hidden_states: + all_hidden_states += (hidden_states,) + + return BaseModelOutputWithPast( + last_hidden_state=hidden_states, + past_key_values=past_key_values if use_cache else None, + hidden_states=all_hidden_states, + attentions=all_self_attns, + ) + + +class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ... + + +@auto_docstring +class PanguEmbeddedForCausalLM(PanguEmbeddedPreTrainedModel, GenerationMixin): + _tied_weights_keys = ["lm_head.weight"] + _tp_plan = {"lm_head": "colwise_rep"} + _pp_plan = {"lm_head": (["hidden_states"], ["logits"])} + + def __init__(self, config): + super().__init__(config) + self.model = PanguEmbeddedModel(config) + self.vocab_size = config.vocab_size + self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False) + + # Initialize weights and apply final processing + self.post_init() + + def get_input_embeddings(self): + return self.model.embed_tokens + + def set_input_embeddings(self, value): + self.model.embed_tokens = value + + def get_output_embeddings(self): + return self.lm_head + + def set_output_embeddings(self, new_embeddings): + self.lm_head = new_embeddings + + def set_decoder(self, decoder): + self.model = decoder + + def get_decoder(self): + return self.model + + @can_return_tuple + @auto_docstring + def forward( + self, + input_ids: Optional[torch.LongTensor] = None, + attention_mask: Optional[torch.Tensor] = None, + position_ids: Optional[torch.LongTensor] = None, + past_key_values: Optional[Cache] = None, + inputs_embeds: Optional[torch.FloatTensor] = None, + labels: Optional[torch.LongTensor] = None, + use_cache: Optional[bool] = None, + output_attentions: Optional[bool] = None, + output_hidden_states: Optional[bool] = None, + cache_position: Optional[torch.LongTensor] = None, + logits_to_keep: Union[int, torch.Tensor] = 0, + **kwargs: Unpack[KwargsForCausalLM], + ) -> CausalLMOutputWithPast: + + output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions + output_hidden_states = ( + output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states + ) + + # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn) + outputs: BaseModelOutputWithPast = self.model( + input_ids=input_ids, + attention_mask=attention_mask, + position_ids=position_ids, + past_key_values=past_key_values, + inputs_embeds=inputs_embeds, + use_cache=use_cache, + output_attentions=output_attentions, + output_hidden_states=output_hidden_states, + cache_position=cache_position, + **kwargs, + ) + + hidden_states = outputs.last_hidden_state + # Only compute necessary logits, and do not upcast them to float if we are not computing the loss + slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep + logits = self.lm_head(hidden_states[:, slice_indices, :]) + + loss = None + if labels is not None: + loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs) + + return CausalLMOutputWithPast( + loss=loss, + logits=logits, + past_key_values=outputs.past_key_values, + hidden_states=outputs.hidden_states, + attentions=outputs.attentions, + ) + + +__all__ = [ + "PanguEmbeddedForCausalLM", + "PanguEmbeddedModel", + "PanguEmbeddedPreTrainedModel", +] diff --git a/modular_openpangu_dense.py b/modular_openpangu_dense.py new file mode 100644 index 0000000..22ef987 --- /dev/null +++ b/modular_openpangu_dense.py @@ -0,0 +1,152 @@ +# coding=utf-8 +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. +# +# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX +# and OPT implementations in this library. It has been modified from its +# original forms to accommodate minor architectural differences compared +# to GPT-NeoX and OPT used by the Meta AI team that trained the model. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Callable, Optional, Tuple + +import torch +from torch import nn + +try: + import torch_npu + from torch_npu.contrib import transfer_to_npu + if "910" in torch.npu.get_device_name(): + NPU_ATTN_INFR = True + print("[INFO] torch_npu detected. Using NPU fused infer attention.") + else: + NPU_ATTN_INFR = False +except ImportError: + NPU_ATTN_INFR = False + +from transformers.cache_utils import Cache +from transformers.modeling_flash_attention_utils import FlashAttentionKwargs +from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS +from transformers.processing_utils import Unpack +from transformers.utils import logging +from transformers.models.llama.modeling_llama import ( + LlamaAttention, + LlamaDecoderLayer, + LlamaForCausalLM, + LlamaForSequenceClassification, + LlamaMLP, + LlamaModel, + apply_rotary_pos_emb, + eager_attention_forward, +) +from .configuration_openpangu_dense import PanguEmbeddedConfig + + +logger = logging.get_logger(__name__) + + +class PanguEmbeddedMLP(LlamaMLP): + def __init__(self, config): + super().__init__(config) + self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False) + self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False) + self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False) + + +class PanguEmbeddedAttention(LlamaAttention): + def __init__(self, config: PanguEmbeddedConfig, layer_idx: int): + super().__init__() + self.config = config + self.layer_idx = layer_idx + self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads) + self.num_heads = config.num_attention_heads + self.num_key_value_heads = config.num_key_value_heads + self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads + self.scaling = self.head_dim**-0.5 + self.attention_dropout = config.attention_dropout + self.is_causal = True + + self.q_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.bias) + self.k_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.bias) + self.v_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.bias) + self.o_proj = nn.Linear(config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.bias) + + def forward( + self, + hidden_states: torch.Tensor, + position_embeddings: tuple[torch.Tensor, torch.Tensor], + attention_mask: Optional[torch.Tensor], + past_key_value: Optional[Cache] = None, + cache_position: Optional[torch.LongTensor] = None, + **kwargs: Unpack[FlashAttentionKwargs], + ) -> tuple[torch.Tensor, Optional[torch.Tensor], Optional[tuple[torch.Tensor]]]: + input_shape = hidden_states.shape[:-1] + hidden_shape = (*input_shape, -1, self.head_dim) + + query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2) + key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2) + value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2) + + cos, sin = position_embeddings + query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin) + + if past_key_value is not None: + # sin and cos are specific to RoPE models; cache_position needed for the static cache + cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position} + key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs) + + attention_interface: Callable = eager_attention_forward + if self.config._attn_implementation != "eager": + attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation] + + if not self.training and NPU_ATTN_INFR: + q_len = input_shape[1] + if attention_mask is not None: + attention_mask = ~attention_mask.bool() + elif q_len > 1: + attention_mask = torch.triu(torch.ones([q_len, q_len]), diagonal=1).bool().unsqueeze(0).unsqueeze(0).to(query_states.device) + + attn_output, _ = torch_npu.npu_fused_infer_attention_score( + query_states, key_states, value_states, + num_heads=self.num_heads, num_key_value_heads=self.num_key_value_heads, + input_layout="BNSD", atten_mask=attention_mask, scale=self.scaling) + attn_output = attn_output.transpose(1, 2) + attn_weights = None + else: + attn_output, attn_weights = attention_interface( + self, + query_states, + key_states, + value_states, + attention_mask, + dropout=0.0 if not self.training else self.attention_dropout, + scaling=self.scaling, + **kwargs, + ) + + attn_output = attn_output.reshape(*input_shape, -1).contiguous() + attn_output = self.o_proj(attn_output) + return attn_output, attn_weights + + +class PanguEmbeddedDecoderLayer(LlamaDecoderLayer): + pass + + +class PanguEmbeddedModel(LlamaModel): + pass + + +class PanguEmbeddedForCausalLM(LlamaForCausalLM): + pass diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..1892f3c --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1,30 @@ +{ + "bos_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "eos_token": { + "content": "[unused10]", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "pad_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + }, + "unk_token": { + "content": "", + "lstrip": false, + "normalized": false, + "rstrip": false, + "single_word": false + } +} diff --git a/tokenization_openpangu.py b/tokenization_openpangu.py new file mode 100644 index 0000000..b9e0408 --- /dev/null +++ b/tokenization_openpangu.py @@ -0,0 +1,273 @@ +# coding=utf-8 +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. +# +# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX +# and OPT implementations in this library. It has been modified from its +# original forms to accommodate minor architectural differences compared +# to GPT-NeoX and OPT used by the Meta AI team that trained the model. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from shutil import copyfile +from typing import Any, Dict, List, Optional, Tuple + +import sentencepiece as spm + +from transformers.tokenization_utils import PreTrainedTokenizer +from transformers.utils import logging + + +logger = logging.get_logger(__name__) + +VOCAB_FILES_NAMES = {"vocab_file": "./tokenizer.model"} + +PRETRAINED_VOCAB_FILES_MAP = {} + + +def convert_bool(string): + if isinstance(string, str): + if string.lower() == "true": + return True + elif string.lower() == "false": + return False + else: + return string + else: + return string + + +class PanguTokenizer(PreTrainedTokenizer): + """ + Construct a tokenizer. Based on byte-level Byte-Pair-Encoding. + + Args: + vocab_file (`str`): + Path to the vocabulary file. + """ + + vocab_files_names = VOCAB_FILES_NAMES + pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP + model_input_names = ["input_ids", "attention_mask"] + _auto_class = "AutoTokenizer" + + def __init__( + self, + vocab_file, + unk_token="", + bos_token="", + eos_token="", + pad_token="", + sp_model_kwargs: Optional[Dict[str, Any]] = None, + add_bos_token=True, + add_eos_token=False, + decode_with_prefix_space=False, + clean_up_tokenization_spaces=False, + **kwargs, + ): + self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs + self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) + self.sp_model.Load(vocab_file) + super().__init__( + bos_token=bos_token, + eos_token=eos_token, + unk_token=unk_token, + pad_token=pad_token, + clean_up_tokenization_spaces=clean_up_tokenization_spaces, + **kwargs, + ) + self.vocab_file = vocab_file + self.add_bos_token = convert_bool(add_bos_token) + self.add_eos_token = add_eos_token + self.decode_with_prefix_space = decode_with_prefix_space + self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) + self.sp_model.Load(vocab_file) + self._no_prefix_space_tokens = None + + """ Initialisation""" + + @property + def no_prefix_space_tokens(self): + if self._no_prefix_space_tokens is None: + vocab = self.convert_ids_to_tokens(list(range(self.vocab_size))) + self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith("▁")} + return self._no_prefix_space_tokens + + @property + def vocab_size(self): + """Returns vocab size""" + return self.sp_model.get_piece_size() + + @property + def bos_token_id(self) -> Optional[int]: + return self.sp_model.bos_id() + + @property + def eos_token_id(self) -> Optional[int]: + return super().eos_token_id + + def get_vocab(self): + """Returns vocab as a dict""" + vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)} + vocab.update(self.added_tokens_encoder) + return vocab + + def _tokenize(self, text): + """Returns a tokenized string.""" + return self.sp_model.encode(text, out_type=str) + + def _convert_token_to_id(self, token): + """Converts a token (str) in an id using the vocab.""" + return self.sp_model.piece_to_id(token) + + def _convert_id_to_token(self, index): + """Converts an index (integer) in a token (str) using the vocab.""" + token = self.sp_model.IdToPiece(index) + return token + + def _maybe_add_prefix_space(self, tokens, decoded): + if tokens and tokens[0] not in self.no_prefix_space_tokens: + return " " + decoded + else: + return decoded + + def convert_tokens_to_string(self, tokens): + """Converts a sequence of tokens (string) in a single string.""" + current_sub_tokens = [] + out_string = "" + prev_is_special = False + for token in tokens: + # make sure that special tokens are not decoded using sentencepiece model + if token in self.all_special_tokens: + # Decode the current sub-tokens first + if current_sub_tokens: + out_string += self.sp_model.decode(current_sub_tokens) + current_sub_tokens = [] + # Append the special token without adding extra spaces + out_string += token + prev_is_special = True + else: + current_sub_tokens.append(token) + prev_is_special = False + # Decode any remaining sub-tokens + if current_sub_tokens: + out_string += self.sp_model.decode(current_sub_tokens) + # Clean up leading and trailing spaces + if self.clean_up_tokenization_spaces: + out_string = self.clean_up_tokenization(out_string) + out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string) + return out_string[1:] + + # Override decode to set spaces_between_special_tokens to True as default + def decode(self, + token_ids, + spaces_between_special_tokens: bool = False, + **kwargs): + return super().decode( + token_ids=token_ids, + spaces_between_special_tokens=spaces_between_special_tokens, + **kwargs, + ) + + def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]: + """ + Save the vocabulary and special tokens file to a directory. + + Args: + save_directory (`str`): + The directory in which to save the vocabulary. + + Returns: + `Tuple(str)`: Paths to the files saved. + """ + if not os.path.isdir(save_directory): + logger.error(f"Vocabulary path ({save_directory}) should be a directory") + return ("",) + out_vocab_file = os.path.join( + save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] + ) + + if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file): + copyfile(self.vocab_file, out_vocab_file) + elif not os.path.isfile(self.vocab_file): + with open(out_vocab_file, "wb") as fi: + content_spiece_model = self.sp_model.serialized_model_proto() + fi.write(content_spiece_model) + + return (out_vocab_file,) + + def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): + if self.add_bos_token: + bos_token_ids = [self.bos_token_id] + else: + bos_token_ids = [] + + output = bos_token_ids + token_ids_0 + + if token_ids_1 is not None: + output = output + token_ids_1 + + if self.add_eos_token: + output = output + [self.eos_token_id] + + return output + + def get_special_tokens_mask( + self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False + ) -> List[int]: + """ + Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding + special tokens using the tokenizer `prepare_for_model` method. + + Args: + token_ids_0 (`List[int]`): + List of IDs. + token_ids_1 (`List[int]`, *optional*): + Optional second list of IDs for sequence pairs. + already_has_special_tokens (`bool`, *optional*, defaults to `False`): + Whether or not the token list is already formatted with special tokens for the model. + + Returns: + `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token. + """ + if already_has_special_tokens: + return super().get_special_tokens_mask( + token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True + ) + + if token_ids_1 is None: + return [1] + ([0] * len(token_ids_0)) + [1] + return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1] + + def create_token_type_ids_from_sequences( + self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None + ) -> List[int]: + """ + Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make + use of token type ids, therefore a list of zeros is returned. + + Args: + token_ids_0 (`List[int]`): + List of IDs. + token_ids_1 (`List[int]`, *optional*): + Optional second list of IDs for sequence pairs. + + Returns: + `List[int]`: List of zeros. + """ + eos = [self.eos_token_id] + + if token_ids_1 is None: + return len(token_ids_0 + eos) * [0] + return len(token_ids_0 + eos + token_ids_1 + eos) * [0] diff --git a/tokenizer.model b/tokenizer.model new file mode 100644 index 0000000..14ca2f8 --- /dev/null +++ b/tokenizer.model @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b16f1558c0cd4ae6ef1a2c605713be0a514f50e1ce2d2c878979ce988c148ec +size 2477809 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..cccff2d --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1 @@ +{"add_bos_token": true, "add_eos_token": false, "add_prefix_space": true, "added_tokens_decoder": {"0": {"content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "1": {"content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "2": {"content": "", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45806": {"content": "<|User|>:", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45813": {"content": "<|Bot|>:", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45830": {"content": "[unused0]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45840": {"content": "[unused1]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45846": {"content": "[unused2]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45849": {"content": "[unused3]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45861": {"content": "[unused4]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45866": {"content": "[unused5]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45874": {"content": "[unused6]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45883": {"content": "[unused7]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45884": {"content": "[unused8]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45887": {"content": "[unused9]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45892": {"content": "[unused10]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45920": {"content": "[unused11]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45932": {"content": "[unused12]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45938": {"content": "[unused13]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45953": {"content": "[unused14]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45968": {"content": "[unused15]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45974": {"content": "[unused16]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45982": {"content": "[unused17]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "45986": {"content": "[unused18]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46005": {"content": "[unused19]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46007": {"content": "[unused20]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46014": {"content": "[unused21]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46017": {"content": "[unused22]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46028": {"content": "[unused23]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46032": {"content": "[unused24]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46081": {"content": "[unused25]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46086": {"content": "[unused26]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46101": {"content": "[unused27]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46183": {"content": "[unused28]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46230": {"content": "[unused29]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46245": {"content": "[unused30]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "46257": {"content": "[unused31]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "144208": {"content": "[unused32]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}, "144209": {"content": "[unused33]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true}}, "auto_map": {"AutoTokenizer": ["tokenization_openpangu.PanguTokenizer", null]}, "bos_token": "", "clean_up_tokenization_spaces": false, "eos_token": "[unused10]", "legacy": true, "model_max_length": 1000000000000000019884624838656, "pad_token": "", "sp_model_kwargs": {}, "spaces_between_special_tokens": false, "tokenizer_class": "PanguTokenizer", "unk_token": "", "use_default_system_prompt": false, "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '[unused9]系统:[unused10]' }}{% endif %}{% if message['role'] == 'system' %}{{ '[unused9]系统:' + message['content'] + '[unused10]' }}{% endif %}{% if message['role'] == 'assistant' %}{{'[unused9]助手:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'tool' %}{{'[unused9]工具:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'function' %}{{'[unused9]方法:' + message['content'] + '[unused10]'}}{% endif %}{% if message['role'] == 'user' %}{{'[unused9]用户:' + message['content'] + '[unused10]'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '[unused9]助手:' }}{% endif %}"}