Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- __pycache__/configuration_hybrid.cpython-312.pyc +0 -0
- __pycache__/modeling_hybrid.cpython-312.pyc +0 -0
- bridge_state.pt +3 -0
- chat_template.jinja +85 -0
- config.json +153 -0
- configuration_hybrid.py +11 -0
- modeling_hybrid.py +56 -0
- tokenizer.json +3 -0
- tokenizer_config.json +30 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
__pycache__/configuration_hybrid.cpython-312.pyc
ADDED
|
Binary file (983 Bytes). View file
|
|
|
__pycache__/modeling_hybrid.cpython-312.pyc
ADDED
|
Binary file (5.45 kB). View file
|
|
|
bridge_state.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5b119cfd562228dcd8fde6e71a95e9af1fdb1812af708380f4103a1627bc76b8
|
| 3 |
+
size 6293646
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 27 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
| 28 |
+
{%- elif message.role == "assistant" %}
|
| 29 |
+
{%- set content = message.content %}
|
| 30 |
+
{%- set reasoning_content = '' %}
|
| 31 |
+
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
|
| 32 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 33 |
+
{%- else %}
|
| 34 |
+
{%- if '</think>' in message.content %}
|
| 35 |
+
{%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
|
| 36 |
+
{%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- endif %}
|
| 39 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 40 |
+
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 41 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 42 |
+
{%- else %}
|
| 43 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- else %}
|
| 46 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- if message.tool_calls %}
|
| 49 |
+
{%- for tool_call in message.tool_calls %}
|
| 50 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 51 |
+
{{- '\n' }}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
{%- if tool_call.function %}
|
| 54 |
+
{%- set tool_call = tool_call.function %}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 57 |
+
{{- tool_call.name }}
|
| 58 |
+
{{- '", "arguments": ' }}
|
| 59 |
+
{%- if tool_call.arguments is string %}
|
| 60 |
+
{{- tool_call.arguments }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{{- tool_call.arguments | tojson }}
|
| 63 |
+
{%- endif %}
|
| 64 |
+
{{- '}\n</tool_call>' }}
|
| 65 |
+
{%- endfor %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{{- '<|im_end|>\n' }}
|
| 68 |
+
{%- elif message.role == "tool" %}
|
| 69 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 70 |
+
{{- '<|im_start|>user' }}
|
| 71 |
+
{%- endif %}
|
| 72 |
+
{{- '\n<tool_response>\n' }}
|
| 73 |
+
{{- message.content }}
|
| 74 |
+
{{- '\n</tool_response>' }}
|
| 75 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 76 |
+
{{- '<|im_end|>\n' }}
|
| 77 |
+
{%- endif %}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{%- endfor %}
|
| 80 |
+
{%- if add_generation_prompt %}
|
| 81 |
+
{{- '<|im_start|>assistant\n' }}
|
| 82 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 83 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 84 |
+
{%- endif %}
|
| 85 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoConfig": "configuration_hybrid.HybridConfig",
|
| 4 |
+
"AutoModelForCausalLM": "modeling_hybrid.HybridForCausalLM"
|
| 5 |
+
},
|
| 6 |
+
"minicpm_dict": {
|
| 7 |
+
"_name_or_path": "openbmb/MiniCPM5-1B",
|
| 8 |
+
"architectures": [
|
| 9 |
+
"LlamaForCausalLM"
|
| 10 |
+
],
|
| 11 |
+
"attention_bias": false,
|
| 12 |
+
"attention_dropout": 0.0,
|
| 13 |
+
"bos_token_id": 0,
|
| 14 |
+
"chunk_size_feed_forward": 0,
|
| 15 |
+
"dtype": "bfloat16",
|
| 16 |
+
"eos_token_id": [
|
| 17 |
+
1,
|
| 18 |
+
130073
|
| 19 |
+
],
|
| 20 |
+
"head_dim": 128,
|
| 21 |
+
"hidden_act": "silu",
|
| 22 |
+
"hidden_size": 1536,
|
| 23 |
+
"id2label": {
|
| 24 |
+
"0": "LABEL_0",
|
| 25 |
+
"1": "LABEL_1"
|
| 26 |
+
},
|
| 27 |
+
"initializer_range": 0.02,
|
| 28 |
+
"intermediate_size": 4608,
|
| 29 |
+
"is_encoder_decoder": false,
|
| 30 |
+
"label2id": {
|
| 31 |
+
"LABEL_0": 0,
|
| 32 |
+
"LABEL_1": 1
|
| 33 |
+
},
|
| 34 |
+
"max_position_embeddings": 131072,
|
| 35 |
+
"mlp_bias": false,
|
| 36 |
+
"model_type": "llama",
|
| 37 |
+
"num_attention_heads": 16,
|
| 38 |
+
"num_hidden_layers": 24,
|
| 39 |
+
"num_key_value_heads": 2,
|
| 40 |
+
"output_attentions": false,
|
| 41 |
+
"output_hidden_states": false,
|
| 42 |
+
"pad_token_id": 1,
|
| 43 |
+
"pretraining_tp": 1,
|
| 44 |
+
"problem_type": null,
|
| 45 |
+
"return_dict": true,
|
| 46 |
+
"rms_norm_eps": 1e-06,
|
| 47 |
+
"rope_parameters": {
|
| 48 |
+
"rope_theta": 5000000,
|
| 49 |
+
"rope_type": "default"
|
| 50 |
+
},
|
| 51 |
+
"tie_word_embeddings": false,
|
| 52 |
+
"transformers_version": "5.10.2",
|
| 53 |
+
"use_cache": true,
|
| 54 |
+
"vocab_size": 130560
|
| 55 |
+
},
|
| 56 |
+
"minicpm_model_name": "openbmb/MiniCPM5-1B",
|
| 57 |
+
"model_type": "true_hybrid_reasoning_agent",
|
| 58 |
+
"qwen_dict": {
|
| 59 |
+
"_name_or_path": "DavidAU/Qwen3-Zero-Coder-Reasoning-V2-0.8B",
|
| 60 |
+
"architectures": [
|
| 61 |
+
"Qwen3ForCausalLM"
|
| 62 |
+
],
|
| 63 |
+
"attention_bias": false,
|
| 64 |
+
"attention_dropout": 0.0,
|
| 65 |
+
"bos_token_id": 151643,
|
| 66 |
+
"chunk_size_feed_forward": 0,
|
| 67 |
+
"dtype": "float16",
|
| 68 |
+
"eos_token_id": 151645,
|
| 69 |
+
"head_dim": 128,
|
| 70 |
+
"hidden_act": "silu",
|
| 71 |
+
"hidden_size": 1024,
|
| 72 |
+
"id2label": {
|
| 73 |
+
"0": "LABEL_0",
|
| 74 |
+
"1": "LABEL_1"
|
| 75 |
+
},
|
| 76 |
+
"initializer_range": 0.02,
|
| 77 |
+
"intermediate_size": 3072,
|
| 78 |
+
"is_encoder_decoder": false,
|
| 79 |
+
"label2id": {
|
| 80 |
+
"LABEL_0": 0,
|
| 81 |
+
"LABEL_1": 1
|
| 82 |
+
},
|
| 83 |
+
"layer_types": [
|
| 84 |
+
"full_attention",
|
| 85 |
+
"full_attention",
|
| 86 |
+
"full_attention",
|
| 87 |
+
"full_attention",
|
| 88 |
+
"full_attention",
|
| 89 |
+
"full_attention",
|
| 90 |
+
"full_attention",
|
| 91 |
+
"full_attention",
|
| 92 |
+
"full_attention",
|
| 93 |
+
"full_attention",
|
| 94 |
+
"full_attention",
|
| 95 |
+
"full_attention",
|
| 96 |
+
"full_attention",
|
| 97 |
+
"full_attention",
|
| 98 |
+
"full_attention",
|
| 99 |
+
"full_attention",
|
| 100 |
+
"full_attention",
|
| 101 |
+
"full_attention",
|
| 102 |
+
"full_attention",
|
| 103 |
+
"full_attention",
|
| 104 |
+
"full_attention",
|
| 105 |
+
"full_attention",
|
| 106 |
+
"full_attention",
|
| 107 |
+
"full_attention",
|
| 108 |
+
"full_attention",
|
| 109 |
+
"full_attention",
|
| 110 |
+
"full_attention",
|
| 111 |
+
"full_attention",
|
| 112 |
+
"full_attention",
|
| 113 |
+
"full_attention",
|
| 114 |
+
"full_attention",
|
| 115 |
+
"full_attention",
|
| 116 |
+
"full_attention",
|
| 117 |
+
"full_attention",
|
| 118 |
+
"full_attention",
|
| 119 |
+
"full_attention",
|
| 120 |
+
"full_attention",
|
| 121 |
+
"full_attention",
|
| 122 |
+
"full_attention",
|
| 123 |
+
"full_attention",
|
| 124 |
+
"full_attention",
|
| 125 |
+
"full_attention"
|
| 126 |
+
],
|
| 127 |
+
"max_position_embeddings": 40960,
|
| 128 |
+
"max_window_layers": 28,
|
| 129 |
+
"model_type": "qwen3",
|
| 130 |
+
"num_attention_heads": 16,
|
| 131 |
+
"num_hidden_layers": 42,
|
| 132 |
+
"num_key_value_heads": 8,
|
| 133 |
+
"output_attentions": false,
|
| 134 |
+
"output_hidden_states": false,
|
| 135 |
+
"pad_token_id": null,
|
| 136 |
+
"problem_type": null,
|
| 137 |
+
"return_dict": true,
|
| 138 |
+
"rms_norm_eps": 1e-06,
|
| 139 |
+
"rope_parameters": {
|
| 140 |
+
"rope_theta": 1000000,
|
| 141 |
+
"rope_type": "default"
|
| 142 |
+
},
|
| 143 |
+
"sliding_window": null,
|
| 144 |
+
"tie_word_embeddings": true,
|
| 145 |
+
"transformers_version": "5.10.2",
|
| 146 |
+
"use_cache": true,
|
| 147 |
+
"use_sliding_window": false,
|
| 148 |
+
"vocab_size": 151936
|
| 149 |
+
},
|
| 150 |
+
"qwen_model_name": "DavidAU/Qwen3-Zero-Coder-Reasoning-V2-0.8B",
|
| 151 |
+
"transformers_version": "5.10.2",
|
| 152 |
+
"use_cache": false
|
| 153 |
+
}
|
configuration_hybrid.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class HybridConfig(PretrainedConfig):
|
| 4 |
+
model_type = "true_hybrid_reasoning_agent"
|
| 5 |
+
|
| 6 |
+
def __init__(self, qwen_dict=None, minicpm_dict=None, qwen_model_name=None, minicpm_model_name=None, **kwargs):
|
| 7 |
+
super().__init__(**kwargs)
|
| 8 |
+
self.qwen_dict = qwen_dict or {}
|
| 9 |
+
self.minicpm_dict = minicpm_dict or {}
|
| 10 |
+
self.qwen_model_name = qwen_model_name or "DavidAU/Qwen3-Zero-Coder-Reasoning-V2-0.8B"
|
| 11 |
+
self.minicpm_model_name = minicpm_model_name or "openbmb/MiniCPM5-1B"
|
modeling_hybrid.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
from transformers import PreTrainedModel, AutoModelForCausalLM, AutoConfig, GenerationMixin
|
| 4 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 5 |
+
from configuration_hybrid import HybridConfig
|
| 6 |
+
|
| 7 |
+
class HybridForCausalLM(PreTrainedModel, GenerationMixin):
|
| 8 |
+
config_class = HybridConfig
|
| 9 |
+
base_model_prefix = "hybrid"
|
| 10 |
+
|
| 11 |
+
def __init__(self, config, load_weights=False):
|
| 12 |
+
super().__init__(config)
|
| 13 |
+
|
| 14 |
+
qwen_obj_config = AutoConfig.from_pretrained(config.qwen_model_name)
|
| 15 |
+
minicpm_obj_config = AutoConfig.from_pretrained(config.minicpm_model_name)
|
| 16 |
+
|
| 17 |
+
if load_weights:
|
| 18 |
+
self.qwen = AutoModelForCausalLM.from_pretrained(config.qwen_model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True)
|
| 19 |
+
self.minicpm = AutoModelForCausalLM.from_pretrained(config.minicpm_model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True)
|
| 20 |
+
else:
|
| 21 |
+
self.qwen = AutoModelForCausalLM.from_config(qwen_obj_config)
|
| 22 |
+
self.minicpm = AutoModelForCausalLM.from_config(minicpm_obj_config)
|
| 23 |
+
|
| 24 |
+
self.qwen.eval()
|
| 25 |
+
self.minicpm.eval()
|
| 26 |
+
for p in self.qwen.parameters(): p.requires_grad = False
|
| 27 |
+
for p in self.minicpm.parameters(): p.requires_grad = False
|
| 28 |
+
|
| 29 |
+
self.embed_projection = nn.Linear(qwen_obj_config.hidden_size, minicpm_obj_config.hidden_size, bias=False, dtype=torch.bfloat16)
|
| 30 |
+
self.minicpm_to_qwen = nn.Linear(minicpm_obj_config.hidden_size, qwen_obj_config.hidden_size, bias=False, dtype=torch.bfloat16)
|
| 31 |
+
self.mix_gate = nn.Parameter(torch.tensor(0.0, dtype=torch.bfloat16))
|
| 32 |
+
self.config.use_cache = False
|
| 33 |
+
|
| 34 |
+
def forward(self, input_ids=None, attention_mask=None, labels=None, past_key_values=None, use_cache=None, **kwargs):
|
| 35 |
+
with torch.no_grad():
|
| 36 |
+
qwen_outputs = self.qwen(input_ids=input_ids, attention_mask=attention_mask, use_cache=False, output_hidden_states=True, return_dict=True, **kwargs)
|
| 37 |
+
qwen_hidden = qwen_outputs.hidden_states[-1]
|
| 38 |
+
qwen_embeds = self.qwen.get_input_embeddings()(input_ids)
|
| 39 |
+
|
| 40 |
+
minicpm_embeds = self.embed_projection(qwen_embeds)
|
| 41 |
+
minicpm_outputs = self.minicpm(inputs_embeds=minicpm_embeds, attention_mask=attention_mask, use_cache=False, output_hidden_states=True, return_dict=True, **kwargs)
|
| 42 |
+
minicpm_hidden = minicpm_outputs.hidden_states[-1]
|
| 43 |
+
|
| 44 |
+
fused_hidden = qwen_hidden + torch.sigmoid(self.mix_gate) * self.minicpm_to_qwen(minicpm_hidden)
|
| 45 |
+
lm_head = self.qwen.get_output_embeddings() or self.qwen.lm_head
|
| 46 |
+
final_logits = lm_head(fused_hidden)
|
| 47 |
+
|
| 48 |
+
loss = None
|
| 49 |
+
if labels is not None:
|
| 50 |
+
loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
|
| 51 |
+
loss = loss_fct(final_logits[:, :-1, :].contiguous().reshape(-1, final_logits.size(-1)), labels[:, 1:].contiguous().reshape(-1))
|
| 52 |
+
|
| 53 |
+
return CausalLMOutputWithPast(loss=loss, logits=final_logits)
|
| 54 |
+
|
| 55 |
+
def prepare_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, **kwargs):
|
| 56 |
+
return {"input_ids": input_ids[:, -1:] if past_key_values is not None else input_ids, "attention_mask": attention_mask, "past_key_values": None}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a6b7653762283a57ee2d7fcfb04c357f85e469f53d9ca456d4cd61914124f712
|
| 3 |
+
size 11422928
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": null,
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|im_end|>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<|im_start|>",
|
| 10 |
+
"<|im_end|>",
|
| 11 |
+
"<|object_ref_start|>",
|
| 12 |
+
"<|object_ref_end|>",
|
| 13 |
+
"<|box_start|>",
|
| 14 |
+
"<|box_end|>",
|
| 15 |
+
"<|quad_start|>",
|
| 16 |
+
"<|quad_end|>",
|
| 17 |
+
"<|vision_start|>",
|
| 18 |
+
"<|vision_end|>",
|
| 19 |
+
"<|vision_pad|>",
|
| 20 |
+
"<|image_pad|>",
|
| 21 |
+
"<|video_pad|>"
|
| 22 |
+
],
|
| 23 |
+
"is_local": false,
|
| 24 |
+
"local_files_only": false,
|
| 25 |
+
"model_max_length": 131072,
|
| 26 |
+
"pad_token": "<|endoftext|>",
|
| 27 |
+
"split_special_tokens": false,
|
| 28 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 29 |
+
"unk_token": null
|
| 30 |
+
}
|