Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,4 @@
|
|
1 |
-
import json
|
2 |
-
from transformers import AutoConfig
|
3 |
|
4 |
-
# 下载原始配置
|
5 |
-
config = AutoConfig.from_pretrained("unsloth/DeepSeek-R1-Distill-Llama-8B")
|
6 |
-
|
7 |
-
# 修正RoPE参数
|
8 |
-
config.rope_scaling = {"type": "linear", "factor": 8.0}
|
9 |
-
|
10 |
-
# 保存为规范JSON格式
|
11 |
-
with open("fixed_config/config.json", "w", encoding="utf-8") as f:
|
12 |
-
json.dump(config.to_dict(), f, indent=2, ensure_ascii=False)
|
13 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
14 |
import gradio as gr
|
15 |
import torch
|
@@ -18,16 +7,29 @@ import re
|
|
18 |
# 加载医学诊断模型
|
19 |
# 修改后(正确)
|
20 |
# from transformers import LlamaForSequenceClassification, LlamaTokenizer
|
21 |
-
from transformers import
|
22 |
import torch
|
23 |
|
24 |
-
# ====
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
"unsloth/DeepSeek-R1-Distill-Llama-8B",
|
30 |
-
config=config, #
|
31 |
trust_remote_code=True
|
32 |
)
|
33 |
|
@@ -35,7 +37,10 @@ model = LlamaForSequenceClassification.from_pretrained(
|
|
35 |
model.load_adapter("yxccai/ds-ai-app")
|
36 |
|
37 |
# ==== 加载分词器 ===-
|
38 |
-
tokenizer =
|
|
|
|
|
|
|
39 |
|
40 |
# 2. 加载你的适配器
|
41 |
# model.load_adapter("yxccai/ds-ai-app") # 替换为你的仓库名
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import gradio as gr
|
4 |
import torch
|
|
|
7 |
# 加载医学诊断模型
|
8 |
# 修改后(正确)
|
9 |
# from transformers import LlamaForSequenceClassification, LlamaTokenizer
|
10 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
|
11 |
import torch
|
12 |
|
13 |
+
# ==== 动态修正配置 ====
|
14 |
+
# 1. 加载原始配置
|
15 |
+
config = AutoConfig.from_pretrained("unsloth/DeepSeek-R1-Distill-Llama-8B")
|
16 |
|
17 |
+
# 2. 强制覆盖RoPE参数(关键步骤)
|
18 |
+
config.rope_scaling = {
|
19 |
+
"type": "linear", # 必须字段
|
20 |
+
"factor": 8.0 # 保留原缩放因子
|
21 |
+
}
|
22 |
+
|
23 |
+
# 3. 删除冲突字段(重要!)
|
24 |
+
del config.rope_scaling["high_freq_factor"]
|
25 |
+
del config.rope_scaling["low_freq_factor"]
|
26 |
+
del config.rope_scaling["original_max_position_embeddings"]
|
27 |
+
del config.rope_scaling["rope_type"]
|
28 |
+
|
29 |
+
# ==== 加载模型 ====
|
30 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
31 |
"unsloth/DeepSeek-R1-Distill-Llama-8B",
|
32 |
+
config=config, # 注入动态修正的配置
|
33 |
trust_remote_code=True
|
34 |
)
|
35 |
|
|
|
37 |
model.load_adapter("yxccai/ds-ai-app")
|
38 |
|
39 |
# ==== 加载分词器 ===-
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained("yxccai/ds-ai-app")
|
41 |
+
|
42 |
+
# ==== 验证配置 ===-
|
43 |
+
print("修正后的RoPE配置:", model.config.rope_scaling) # 应输出: {'type': 'linear', 'factor': 8.0}
|
44 |
|
45 |
# 2. 加载你的适配器
|
46 |
# model.load_adapter("yxccai/ds-ai-app") # 替换为你的仓库名
|