From cff32ad9fc26b4661836de690337bd5f4b2abc57 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Tue, 17 Nov 2026 03:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: EverywhereSafety/SEAD-SAGE-4B Source: Original Platform --- .gitattributes | 2 + README.md | 100 +++++++++++++++++++++++++++++++++++++++++ chat_template.jinja | 61 +++++++++++++++++++++++++ config.json | 71 +++++++++++++++++++++++++++++ generation_config.json | 13 ++++++ model.safetensors | 3 ++ tokenizer.json | 3 ++ tokenizer_config.json | 30 +++++++++++++ 8 files changed, 283 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 chat_template.jinja create mode 100644 config.json create mode 100644 generation_config.json create mode 100644 model.safetensors create mode 100644 tokenizer.json create mode 100644 tokenizer_config.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..79b9f70 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +model.safetensors filter=lfs diff=lfs merge=lfs -text +tokenizer.json filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a3ec14 --- /dev/null +++ b/README.md @@ -0,0 +1,100 @@ +--- +license: apache-2.0 +language: +- en +library_name: transformers +pipeline_tag: text-generation +base_model: Qwen/Qwen3-4B-Instruct-2507 +datasets: +- EverywhereSafety/SEAD-SFT-v1 +tags: +- agentic-defense +- tool-using-agents +- state-aware-safety +- qwen3 +- sead +--- + +# SEAD-SAGE-4B + +Agentic defense model for deciding whether a pending tool action should pass or be blocked. SAGE can use bounded, read-only state queries before submitting its decision. + +Paper: [SEAD](https://arxiv.org/abs/2609.34518) · Code: [EverywhereSafety/SEAD](https://github.com/EverywhereSafety/SEAD) · Project: [everywheresafety.github.io/sead](https://everywheresafety.github.io/sead/) · [Everywhere Safety](https://everywheresafety.github.io/) + +## Checkpoint + +| Property | Value | +|---|---| +| Base model | [Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) | +| Fine-tuning | Full SFT, cumulative epoch 2 | +| Precision | BF16 | +| Context budget | 65,536 tokens | +| Defender steps | 6 maximum | +| Generation budget | 1,024 tokens per step | +| Temperature | 0.0 | +| Thinking | Disabled | + +## Paper-format offline metrics + +The full comparison below reproduces the paper's frozen cohort (55 harmful and 95 benign trajectories) and adds the two released epoch-2 checkpoints. `B` is benign all-pass; `H1` is exact closure interception; `H2` is timing-aware interception; `F1/F2` are the paper's harmonic safety–utility summaries. All values are percentages. Technical/unresolved harmful cases count as Miss for the released checkpoints. + +| Defender | B↑ | H1↑ | F1↑ | H2↑ | F2↑ | +|---|---:|---:|---:|---:|---:| +| No defense (paper) | 100.00 | 0.00 | 0.00 | 0.00 | 0.00 | +| Base Binary (paper) | 51.58 | 0.00 | 0.00 | 17.03 | 25.61 | +| Fine-tuned Binary (paper) | 100.00 | 18.18 | 30.77 | 22.05 | 36.13 | +| StepGuard (paper) | 51.58 | 12.73 | 20.42 | 27.77 | 36.11 | +| TS-Guard (paper) | 71.58 | 7.27 | 13.20 | 38.14 | 49.76 | +| Safiron (paper) | 0.00 | 3.64 | 0.00 | 33.65 | 0.00 | +| SEAD-SAGE (Base, paper) | 62.11 | 10.91 | 18.56 | 39.20 | 48.06 | +| SEAD-SAGE (paper) | 95.79 | 34.55 | 50.78 | 58.79 | 72.86 | +| SEAD-SAGE-4B (released) | 100.00 | 47.27 | 64.20 | 66.43 | 79.83 | +| SEAD-SAGE-4B-FP8 (released) | 100.00 | 45.45 | 62.50 | 65.84 | 79.40 | + +| First-block timing | Early | Exact↑ | Late | Miss↓ | +|---|---:|---:|---:|---:| +| No defense (paper) | 0.00 | 0.00 | 0.00 | 100.00 | +| Base Binary (paper) | 63.64 | 0.00 | 1.82 | 34.55 | +| Fine-tuned Binary (paper) | 5.45 | 18.18 | 3.64 | 72.73 | +| StepGuard (paper) | 41.82 | 12.73 | 1.82 | 43.64 | +| TS-Guard (paper) | 78.18 | 7.27 | 0.00 | 14.55 | +| Safiron (paper) | 85.45 | 3.64 | 0.00 | 10.91 | +| SEAD-SAGE (Base, paper) | 80.00 | 10.91 | 0.00 | 9.09 | +| SEAD-SAGE (paper) | 58.18 | 34.55 | 0.00 | 7.27 | +| SEAD-SAGE-4B (released) | 29.09 | 47.27 | 3.64 | 20.00 | +| SEAD-SAGE-4B-FP8 (released) | 30.91 | 45.45 | 1.82 | 21.82 | + +## Serving benchmark + +OpenAI-compatible vLLM endpoint, 16 prompts, request counts 64/64/128/256 for concurrency 1/8/64/128, zero request errors. + +| Concurrency | Requests | P50 | P95 | Throughput | +|---:|---:|---:|---:|---:| +| 1 | 64 | 376 ms | 511 ms | 2.53 req/s | +| 8 | 64 | 491 ms | 654 ms | 14.80 req/s | +| 64 | 128 | 1.322 s | 1.871 s | 40.03 req/s | +| 128 | 256 | 2.160 s | 3.296 s | 49.00 req/s | + +## Usage + +Use the prompt construction, investigation loop, JSON extraction, and validation in the SEAD repository. The model emits one structured action per step, ending with `{"action":"submit","decision":"pass|block",...}`. Ordinary text generation is used; provider JSON mode is not required. + +```bash +vllm serve EverywhereSafety/SEAD-SAGE-4B \ + --served-model-name SEAD-SAGE-4B \ + --dtype bfloat16 +``` + +## Citation + +```bibtex +@misc{shen2026sead, + title={SEAD: A State-Based Perspective on Attack and Defense in Tool-Using Agents}, + author={Xinjie Shen and Junran Wang and Rongzhe Wei and Pan Li}, + year={2026}, + eprint={2609.34518}, + archivePrefix={arXiv}, + primaryClass={cs.CR}, + url={https://arxiv.org/abs/2609.34518} +} +``` diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..70adff8 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,61 @@ +{%- if tools %} + {{- '<|im_start|>system\n' }} + {%- if messages[0].role == 'system' %} + {{- messages[0].content + '\n\n' }} + {%- endif %} + {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within XML tags:\n" }} + {%- for tool in tools %} + {{- "\n" }} + {{- tool | tojson }} + {%- endfor %} + {{- "\n\n\nFor each function call, return a json object with function name and arguments within XML tags:\n\n{\"name\": , \"arguments\": }\n<|im_end|>\n" }} +{%- else %} + {%- if messages[0].role == 'system' %} + {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }} + {%- endif %} +{%- endif %} +{%- for message in messages %} + {%- if message.content is string %} + {%- set content = message.content %} + {%- else %} + {%- set content = '' %} + {%- endif %} + {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} + {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }} + {%- elif message.role == "assistant" %} + {{- '<|im_start|>' + message.role + '\n' + content }} + {%- if message.tool_calls %} + {%- for tool_call in message.tool_calls %} + {%- if (loop.first and content) or (not loop.first) %} + {{- '\n' }} + {%- endif %} + {%- if tool_call.function %} + {%- set tool_call = tool_call.function %} + {%- endif %} + {{- '\n{"name": "' }} + {{- tool_call.name }} + {{- '", "arguments": ' }} + {%- if tool_call.arguments is string %} + {{- tool_call.arguments }} + {%- else %} + {{- tool_call.arguments | tojson }} + {%- endif %} + {{- '}\n' }} + {%- endfor %} + {%- endif %} + {{- '<|im_end|>\n' }} + {%- elif message.role == "tool" %} + {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %} + {{- '<|im_start|>user' }} + {%- endif %} + {{- '\n\n' }} + {{- content }} + {{- '\n' }} + {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} + {{- '<|im_end|>\n' }} + {%- endif %} + {%- endif %} +{%- endfor %} +{%- if add_generation_prompt %} + {{- '<|im_start|>assistant\n' }} +{%- endif %} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..2a12768 --- /dev/null +++ b/config.json @@ -0,0 +1,71 @@ +{ + "architectures": [ + "Qwen3ForCausalLM" + ], + "attention_bias": false, + "attention_dropout": 0.0, + "bos_token_id": 151643, + "dtype": "float32", + "eos_token_id": 151645, + "head_dim": 128, + "hidden_act": "silu", + "hidden_size": 2560, + "initializer_range": 0.02, + "intermediate_size": 9728, + "layer_types": [ + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention" + ], + "max_position_embeddings": 262144, + "max_window_layers": 36, + "model_type": "qwen3", + "num_attention_heads": 32, + "num_hidden_layers": 36, + "num_key_value_heads": 8, + "pad_token_id": null, + "rms_norm_eps": 1e-06, + "rope_parameters": { + "rope_theta": 5000000, + "rope_type": "default" + }, + "sliding_window": null, + "tie_word_embeddings": true, + "transformers_version": "5.17.0", + "use_cache": false, + "use_sliding_window": false, + "vocab_size": 151936 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..c608c0e --- /dev/null +++ b/generation_config.json @@ -0,0 +1,13 @@ +{ + "bos_token_id": 151643, + "do_sample": true, + "eos_token_id": [ + 151645, + 151643 + ], + "pad_token_id": 151643, + "temperature": 0.7, + "top_k": 20, + "top_p": 0.8, + "transformers_version": "5.17.0" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..72de69b --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbbacc2895a7e5fe621259596697d9a12d11551ef317ab61492a3b4485e62e4a +size 17645743048 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..c7afbed --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506 +size 11422650 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..c77896b --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,30 @@ +{ + "add_prefix_space": false, + "backend": "tokenizers", + "bos_token": null, + "clean_up_tokenization_spaces": false, + "eos_token": "<|im_end|>", + "errors": "replace", + "extra_special_tokens": [ + "<|im_start|>", + "<|im_end|>", + "<|object_ref_start|>", + "<|object_ref_end|>", + "<|box_start|>", + "<|box_end|>", + "<|quad_start|>", + "<|quad_end|>", + "<|vision_start|>", + "<|vision_end|>", + "<|vision_pad|>", + "<|image_pad|>", + "<|video_pad|>" + ], + "is_local": true, + "local_files_only": false, + "model_max_length": 1010000, + "pad_token": "<|endoftext|>", + "split_special_tokens": false, + "tokenizer_class": "Qwen2Tokenizer", + "unk_token": null +}