models: 新增 Qwen3-8B-guard LoRA 适配器(LFS)

A6000 上 8005 端口服务的 Qwen3-8B-guard-same 对应的 PEFT 适配器:
r=16 / alpha=32 / 7 个投影层,可训练参数 43,646,976(0.5301%);
adapter_model.safetensors 174,655,536 字节,md5 307b3d8a1a7d5d420b9ef43620f70492。

只提交增量(175MB),不含 16GB 基座与合并权重;模型说明.md 记录训练参数、
评测口径、合并脚本,并注明它不能直接作为 response_guard 的守卫后端
(输出是拒答文本而非 Safety/Categories/Refusal)。
This commit is contained in:
agcl committed 2026-11-27 20:48:09 +08:00
1 parent d51b69c0df
commit 594dc0f6b2
5 files changed
+331

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* text=auto eol=lf
models/guard_model/*.safetensors filter=lfs diff=lfs merge=lfs -text
models/guard_model/tokenizer.json filter=lfs diff=lfs merge=lfs -text
models/qwen3-8b-guard-lora/*.safetensors filter=lfs diff=lfs merge=lfs -text
+207
View File
@@ -0,0 +1,207 @@
---
base_model: /home/chenleixu/models/Qwen3-8B
library_name: peft
pipeline_tag: text-generation
tags:
- base_model:adapter:/home/chenleixu/models/Qwen3-8B
- lora
- transformers
---
# Model Card for Model ID
<!-- Provide a quick summary of what the model is/does. -->
## Model Details
### Model Description
<!-- Provide a longer summary of what this model is. -->
- **Developed by:** [More Information Needed]
- **Funded by [optional]:** [More Information Needed]
- **Shared by [optional]:** [More Information Needed]
- **Model type:** [More Information Needed]
- **Language(s) (NLP):** [More Information Needed]
- **License:** [More Information Needed]
- **Finetuned from model [optional]:** [More Information Needed]
### Model Sources [optional]
<!-- Provide the basic links for the model. -->
- **Repository:** [More Information Needed]
- **Paper [optional]:** [More Information Needed]
- **Demo [optional]:** [More Information Needed]
## Uses
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
### Direct Use
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
[More Information Needed]
### Downstream Use [optional]
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
[More Information Needed]
### Out-of-Scope Use
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
[More Information Needed]
## Bias, Risks, and Limitations
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
[More Information Needed]
### Recommendations
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
## How to Get Started with the Model
Use the code below to get started with the model.
[More Information Needed]
## Training Details
### Training Data
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
[More Information Needed]
### Training Procedure
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
#### Preprocessing [optional]
[More Information Needed]
#### Training Hyperparameters
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
#### Speeds, Sizes, Times [optional]
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
[More Information Needed]
## Evaluation
<!-- This section describes the evaluation protocols and provides the results. -->
### Testing Data, Factors & Metrics
#### Testing Data
<!-- This should link to a Dataset Card if possible. -->
[More Information Needed]
#### Factors
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
[More Information Needed]
#### Metrics
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
[More Information Needed]
### Results
[More Information Needed]
#### Summary
## Model Examination [optional]
<!-- Relevant interpretability work for the model goes here -->
[More Information Needed]
## Environmental Impact
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
- **Hardware Type:** [More Information Needed]
- **Hours used:** [More Information Needed]
- **Cloud Provider:** [More Information Needed]
- **Compute Region:** [More Information Needed]
- **Carbon Emitted:** [More Information Needed]
## Technical Specifications [optional]
### Model Architecture and Objective
[More Information Needed]
### Compute Infrastructure
[More Information Needed]
#### Hardware
[More Information Needed]
#### Software
[More Information Needed]
## Citation [optional]
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
**BibTeX:**
[More Information Needed]
**APA:**
[More Information Needed]
## Glossary [optional]
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
[More Information Needed]
## More Information [optional]
[More Information Needed]
## Model Card Authors [optional]
[More Information Needed]
## Model Card Contact
[More Information Needed]
### Framework versions
- PEFT 0.21.3
@@ -0,0 +1,51 @@
{
"alora_invocation_tokens": null,
"alpha_pattern": {},
"arrow_config": null,
"auto_mapping": null,
"base_model_name_or_path": "/home/chenleixu/models/Qwen3-8B",
"bias": "none",
"corda_config": null,
"ensure_weight_tying": false,
"eva_config": null,
"exclude_modules": null,
"fan_in_fan_out": false,
"inference_mode": true,
"init_lora_weights": true,
"kasa_config": null,
"layer_replication": null,
"layers_pattern": null,
"layers_to_transform": null,
"loftq_config": {},
"lora_alpha": 32,
"lora_bias": false,
"lora_dropout": 0.05,
"lora_ga_config": null,
"megatron_config": null,
"megatron_core": "megatron.core",
"modules_to_save": null,
"monteclora_config": null,
"peft_type": "LORA",
"peft_version": "0.21.3",
"qalora_group_size": 16,
"r": 16,
"rank_pattern": {},
"revision": null,
"target_modules": [
"down_proj",
"o_proj",
"v_proj",
"q_proj",
"up_proj",
"k_proj",
"gate_proj"
],
"target_parameters": null,
"task_type": "CAUSAL_LM",
"trainable_token_indices": null,
"use_bdlora": null,
"use_dora": false,
"use_qalora": false,
"use_rslora": false,
"velora_config": null
}
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:86adb4a9182d9ed1704be60ce79b6db751653f6c8c6f7c128785af5c9c40932d
size 174655536
@@ -0,0 +1,69 @@
# Qwen3-8B-guard LoRA(same 变体)
内容安全判定用的 LoRA 适配器,基座为 Qwen3-8B。本目录只放**适配器增量**(175MB),
不含基座权重;基座请自行从 Qwen3-8B 官方仓库获取。
## 文件
| 文件 | 说明 |
|---|---|
| `adapter_model.safetensors` | LoRA 权重,174,655,536 字节,md5 `307b3d8a1a7d5d420b9ef43620f70492` |
| `adapter_config.json` | PEFT 配置,`r=16`、`lora_alpha=32`、7 个投影层 |
| `README.md` | PEFT 自动生成的 Model Card 模板(未填写) |
## 训练参数
- 基座:`Qwen3-8B`(bf16)
- LoRA:`r=16`、`alpha=32`、`target_modules = q/k/v/o/gate/up/down_proj`,可训练参数 43,646,976(占 0.5301%)
- 数据:1658 条攻击样本 + 200 条良性样本 × 4 次重复,2 epoch
- 耗时:单卡 A6000,1267 s(约 21 分钟)
- 变体:`same`(保持基座原有的拒答行为);另有 `unseat` 变体(解除拒答),不在此目录
## 评测口径(历史记录,非本目录复现)
| 指标 | 值 | 口径 |
|---|---|---|
| AUC | 0.9989 | 同一分布留出集,n_pos 398 / n_neg 200 |
| 阈值 | 0.99999 | 按该阈值取 P(unsafe) |
| 召回 / 误拦 | 94.97% / 0.00% | 同一阈值下 |
| vLLM 复验 | 94.47%~94.72%,误拦 0~1 条 | 阈值 0.99999,延迟 0.08~0.11 s |
结果随阈值与机器负载浮动,重跑请以实际输出为准。
## 与 Qwen3-8B 合并
```python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B", torch_dtype="bfloat16")
model = PeftModel.from_pretrained(base, "./qwen3-8b-guard-lora")
model = model.merge_and_unload()
model.save_pretrained("./Qwen3-8B-guard-same")
tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
tok.save_pretrained("./Qwen3-8B-guard-same")
```
合并后约 16GB(5 个 safetensors 分片),即 A6000 上 `8005` 端口服务的 `Qwen3-8B-guard-same`。
## 注意:不能直接当 response_guard 的守卫后端
宿主的 `parse_guard_output` 要求模型输出
```
Safety: Safe | Unsafe | Controversial
Categories: <固定枚举>
Refusal: Yes | No
```
这个适配器训练成的是**拒答/打分**形态:给它一段待判文本,它会像助手一样回答
(例如“我不能提供任何机密文件……”),不产生 `Safety:` 行。直接接到
`response_guard.lua` 的 `host.llm.call` 上,每次判定都会因 `InvalidModelOutput`
fail-closed 成 503。
要用它做判定,需要二选一:
1. 走打分路径:取 `P(unsafe)` 的 logprob,按阈值(如 0.99999)映射成 safety 标签,
在宿主侧新增一个 adapter,而不是复用生成式契约;
2. 换用原生按 `Safety:/Categories:/Refusal:` 输出的 Qwen3Guard-Gen(0.6B/4B/8B)。