README.md 5.11 KB
Newer Older
weishb's avatar
weishb committed
1
# Spark-X1
weishb's avatar
weishb committed
2
3
## 论文
[Spark-Prover-X1: Formal Theorem Proving Through Diverse Data Training](https://arxiv.org/abs/2511.13043)
weishb's avatar
weishb committed
4

weishb's avatar
weishb committed
5
6
7
8
9
10
11
12
13
14
15
## 模型简介
Spark-X1 系列是科大讯飞星火大模型体系中的深度推理模型系列。Spark-X1 强调数学、逻辑、代码、语言理解和知识问答等复杂推理能力,并采用快思考/慢思考统一的推理模式。当前开源的 Spark-X1 相关模型主要不是通用 base checkpoint,而是基于 Spark-X1 或科大讯飞新一代基础模型微调得到的垂直领域模型,包括数学形式化与定理证明方向的 Spark-Formalizer-X1-7B / Spark-Prover-X1-7B、化学方向的 Spark-Chemistry-X1-13B、科技文献方向的 Spark-Scilit-X1-13B 等。

## 环境依赖
| 软件 | 版本 |
| :------: | :------: |
| DTK | 26.04 |
| Python | 3.10 |
| Transformers | 4.56.1 |
| vLLM | 0.18.1+das.dtk2604 |

weishb's avatar
weishb committed
16
推荐使用镜像: harbor.sourcefind.cn:5443/dcu/admin/base/custom:vllm0.18.1-ubuntu22.04-dtk26.04-py3.10-20260528-iflytek
weishb's avatar
weishb committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

- 挂载地址`-v` 根据实际模型情况修改
```bash
docker run -it \
    --shm-size 60g \
    --network=host \
    --name Spark-X1 \
    --privileged \
    --device=/dev/kfd \
    --device=/dev/dri \
    --device=/dev/mkfd \
    --group-add video \
    --cap-add=SYS_PTRACE \
    --security-opt seccomp=unconfined \
    -u root \
    -v /opt/hyhal/:/opt/hyhal/:ro \
    -v /path/your_code_data/:/path/your_code_data/ \
weishb's avatar
weishb committed
34
    harbor.sourcefind.cn:5443/dcu/admin/base/custom:vllm0.18.1-ubuntu22.04-dtk26.04-py3.10-20260528-iflytek bash
weishb's avatar
weishb committed
35
36
37
38
39
```
更多镜像可前往[光源](https://sourcefind.cn/#/service-list)下载使用。

关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。

weishb's avatar
weishb committed
40

weishb's avatar
weishb committed
41
42
43
44
## 预训练权重
**请根据`支持的DCU型号`选择对应模型下载,FP8模型仅在BW1100/BW1101上支持,其他型号请勿使用!**
|  模型名称  | 权重大小 | 数据类型 |支持的DCU型号  | 最低卡数需求 |         下载地址          |
|:------:|:----:|:----:|:----------:|:------:|:---------------------:|
weishb's avatar
weishb committed
45
46
47
| Spark-Formalizer-X1-7B | 7B | BF16 | BW1000 |   1   | [ModelScope](https://modelscope.cn/models/iflytek/Spark-Formalizer-X1-7B) |
| Spark-Chemistry-X1-13B | 13B | BF16 | BW1000 |   1   | [ModelScope](https://modelscope.cn/models/iflytek/Spark-Chemistry-X1-13B) |
| Spark-Scilit-X1-13B| 13B | BF16 | BW1000 |   1   | [ModelScope](https://modelscope.cn/models/iflytek/Spark-Scilit-X1-13B) |
weishb's avatar
weishb committed
48
49
50
51
52
53
54
55
56
57
58
59

## 数据集
暂无

## 训练
暂无

## 推理
### Transformers
#### 单机推理

**以`Spark-Chemistry-X1-13B`为例**
weishb's avatar
weishb committed
60
61
```bash
cd /path/to/model/Spark-Chemistry-X1-13B #进入模型目录内
weishb's avatar
weishb committed
62
python transformers_run.py
weishb's avatar
weishb committed
63
64
65
```

**transformers_run.py参考:**
weishb's avatar
weishb committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "/path/to/Spark-Chemistry-X1-13B"
tokenizer = AutoTokenizer.from_pretrained(model_name,trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float32,
    device_map="auto",
    trust_remote_code=True
)
# Reactive
chat_history = [
  {
    "role" : "user",
    "content" : "请回答下列问题:高分子材料是否具有柔顺性主要决定于()的运动能力。\nA、主链链节\nB、侧基\nC、侧基内的官能团或原子?"
  }]

inputs = tokenizer.apply_chat_template(
    chat_history,
    tokenize=True,
    return_tensors="pt",
    add_generation_prompt=True
).to(model.device)

outputs = model.generate(
    inputs,
    max_new_tokens=8192,
    top_k=1,
    do_sample=True,
    repetition_penalty=1.02,
    temperature=0.7,
    eos_token_id=5,
    pad_token_id=0,
)

response = tokenizer.decode(
    outputs[0][inputs.shape[1] :],
    skip_special_tokens=True
)
print(response)
```

weishb's avatar
weishb committed
110
111
**如果用transformers推理Spark-Scilit-X1-13B,需要额外修改模型的config.json文件,将"_attn_implementation":"flash_attention_2"改成"_attn_implementation":"eager"**

weishb's avatar
weishb committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
### vLLM
#### 单机推理
```bash
# serve启动
# 以Spark-Scilit-X1-13B为例
vllm serve /path/to/Spark-Scilit-X1-13B \
    --generation-config vllm \
    --trust-remote-code \
    --dtype bfloat16 \
    --max-model-len 16384 \
    --served-model-name Spark-Scilit-X1-13B

# client访问
curl http://127.0.0.1:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
weishb's avatar
weishb committed
128
      "model": "/path/to/Spark-Scilit-X1-13B",
weishb's avatar
weishb committed
129
130
131
132
133
134
135
136
137
138
139
      "messages": [
        {
          "role": "user",
          "content": "请回答下列问题:高分子材料是否具有柔顺性主要决定于()的运动能力。\nA、主链链节\nB、侧基\nC、侧基内的官能团或原子?"
        }
      ],
      "temperature": 0,
      "top_p": 1,
      "max_tokens": 512
    }'
```
weishb's avatar
weishb committed
140
141
142
143
144
145
146

## 效果展示
<div align=center>
    <img src="./doc/01.png"/>
</div>

### 精度
weishb's avatar
weishb committed
147
DCU与GPU精度一致,推理框架:transformers,vllm
weishb's avatar
weishb committed
148
149
150
151
152
153
154
155
156

## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/spark-x1

## 参考资料
- https://arxiv.org/pdf/2408.06574
- https://modelscope.cn/models/iflytek/Spark-Formalizer-X1-7B
- https://modelscope.cn/models/iflytek/Spark-Scilit-X1-13B
- https://gitcode.com/ifly_opensource