初始化项目,由ModelHub XC社区提供模型
Model: Alindstroem89/Llama-3.2-3B-Instruct_guardrail Source: Original Platform
This commit is contained in:
40
.gitattributes
vendored
Normal file
40
.gitattributes
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Llama-3.2-3B-Instruct.Q3_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Llama-3.2-3B-Instruct.Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Llama-3.2-3B-Instruct.F16.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Llama-3.2-3B-Instruct.BF16.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Guardrail-Llama-3.2-3B-Instruct.BF16.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
3
Llama-3.2-3B-Instruct.F16.gguf
Normal file
3
Llama-3.2-3B-Instruct.F16.gguf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:2aaaf20b7af7af225cf8d3f7b3a02daf5d23dd5f92a0f39a99dbf872e6e80bb2
|
||||||
|
size 6433688512
|
||||||
3
Llama-3.2-3B-Instruct.Q3_K_M.gguf
Normal file
3
Llama-3.2-3B-Instruct.Q3_K_M.gguf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:b28a1edffa6d79ab81adda275996c8b7bfd473c61544bdc64e9f816bac2ff568
|
||||||
|
size 1687159744
|
||||||
3
Llama-3.2-3B-Instruct.Q4_K_M.gguf
Normal file
3
Llama-3.2-3B-Instruct.Q4_K_M.gguf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:8ace48b24e16e768fefcf798d67a5da4f8e7ae09321a6adcdc09a24c67d19f0a
|
||||||
|
size 2019378112
|
||||||
57
Modelfile
Normal file
57
Modelfile
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
FROM Llama-3.2-3B-Instruct.BF16.gguf
|
||||||
|
TEMPLATE """{{ if .Messages }}
|
||||||
|
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
|
||||||
|
{{- if .System }}
|
||||||
|
|
||||||
|
{{ .System }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Tools }}
|
||||||
|
|
||||||
|
You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the original use question.
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}<|eot_id|>
|
||||||
|
{{- range $i, $_ := .Messages }}
|
||||||
|
{{- $last := eq (len (slice $.Messages $i)) 1 }}
|
||||||
|
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
|
||||||
|
{{- if and $.Tools $last }}
|
||||||
|
|
||||||
|
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
|
||||||
|
|
||||||
|
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.
|
||||||
|
|
||||||
|
{{ $.Tools }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
|
{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
{{- if .ToolCalls }}
|
||||||
|
|
||||||
|
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
|
||||||
|
{{- else }}
|
||||||
|
|
||||||
|
{{ .Content }}{{ if not $last }}<|eot_id|>{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if eq .Role "tool" }}<|start_header_id|>ipython<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- if .System }}<|start_header_id|>system<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}{{ .Response }}{{ if .Response }}<|eot_id|>{{ end }}"""
|
||||||
|
PARAMETER stop "<|start_header_id|>"
|
||||||
|
PARAMETER stop "<|end_header_id|>"
|
||||||
|
PARAMETER stop "<|eot_id|>"
|
||||||
|
PARAMETER stop "<|eom_id|>"
|
||||||
|
PARAMETER temperature 1.5
|
||||||
|
PARAMETER min_p 0.1
|
||||||
103
README.md
Normal file
103
README.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
---
|
||||||
|
datasets:
|
||||||
|
- Alindstroem89/guardrail-training-dataset
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
base_model:
|
||||||
|
- unsloth/Llama-3.2-3B-Instruct
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
tags:
|
||||||
|
- gguf
|
||||||
|
- llama.cpp
|
||||||
|
- unsloth
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
# Llama-3.2-3B-Instruct_guardrail : GGUF
|
||||||
|
|
||||||
|
A fine-tuned Llama 3.2 model trained to resist prompt injection attacks. This model was created for the [Prompt Injection Challenge](https://github.com/Alexanderl89/Guardrail_finetuning) - an AI security challenge where users attempt to extract a hidden flag from a chatbot using prompt injection and social engineering techniques.
|
||||||
|
|
||||||
|
This model was fine-tuned and converted to GGUF format using [Unsloth](https://github.com/unslothai/unsloth).
|
||||||
|
|
||||||
|
## Model Description
|
||||||
|
|
||||||
|
Fine-tuned to:
|
||||||
|
- Recognize and resist prompt injection techniques
|
||||||
|
- Maintain boundaries and refuse to reveal protected information
|
||||||
|
- Remain helpful and friendly for legitimate conversations
|
||||||
|
- Politely explain refusals without being unnecessarily rigid
|
||||||
|
|
||||||
|
## Training Details
|
||||||
|
|
||||||
|
**Base Model:** [unsloth/Llama-3.2-3B-Instruct](https://huggingface.co/unsloth/Llama-3.2-3B-Instruct)
|
||||||
|
|
||||||
|
**Training Configuration:**
|
||||||
|
- LoRA Rank (r): 32
|
||||||
|
- LoRA Alpha: 32
|
||||||
|
- Target Modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
|
||||||
|
- Use RSLoRA: True
|
||||||
|
- Optimizer: adamw_8bit
|
||||||
|
- Learning Rate: 1e-4
|
||||||
|
- Batch Size: 2 per device
|
||||||
|
- Gradient Accumulation: 8 steps
|
||||||
|
- Epochs: 1
|
||||||
|
- Max Sequence Length: 8192
|
||||||
|
|
||||||
|
**Dataset:** Custom dataset with guardrail conversations (prompt injection attempts with refusals) and normal helpful conversations.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### With llama-cli
|
||||||
|
|
||||||
|
```bash
|
||||||
|
llama-cli -hf Alindstroem89/Llama-3.2-3B-Instruct_guardrail:F16 --jinja
|
||||||
|
```
|
||||||
|
|
||||||
|
### Download with Hugging Face CLI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Download all GGUF files
|
||||||
|
hf download Alindstroem89/Llama-3.2-3B-Instruct_guardrail --include "*.gguf" --local-dir ./models
|
||||||
|
|
||||||
|
# Download specific quantization
|
||||||
|
hf download Alindstroem89/Llama-3.2-3B-Instruct_guardrail --include "Llama-3.2-3B-Instruct.Q4_K_M.gguf" --local-dir ./models
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ollama
|
||||||
|
|
||||||
|
An Ollama Modelfile is included for easy deployment.
|
||||||
|
|
||||||
|
## Available Model Files
|
||||||
|
|
||||||
|
- Llama-3.2-3B-Instruct.Q3_K_M.gguf
|
||||||
|
- Llama-3.2-3B-Instruct.Q4_K_M.gguf
|
||||||
|
- Llama-3.2-3B-Instruct.F16.gguf
|
||||||
|
- Llama-3.2-3B-Instruct.BF16.gguf
|
||||||
|
|
||||||
|
## Use Cases
|
||||||
|
|
||||||
|
- Chatbots requiring prompt injection resistance
|
||||||
|
- AI assistants handling sensitive information
|
||||||
|
- AI security research and education
|
||||||
|
- Testing guardrail implementations
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- Primarily tested on English language
|
||||||
|
- Not a comprehensive security solution
|
||||||
|
- May occasionally be overly cautious
|
||||||
|
- Should not be the sole defense mechanism in production
|
||||||
|
|
||||||
|
## Training Infrastructure
|
||||||
|
|
||||||
|
- Framework: [Unsloth](https://github.com/unslothai/unsloth) (2x faster training)
|
||||||
|
- Method: LoRA (Low-Rank Adaptation) with rank-stabilized optimization
|
||||||
|
- Conversion: GGUF format for efficient inference
|
||||||
|
|
||||||
|
## Finetuning repo
|
||||||
|
|
||||||
|
[Guardrail_finetuning](https://github.com/Alexanderl89/Guardrail_finetuning)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This model follows the license of the base Llama 3.2 model.
|
||||||
37
config.json
Normal file
37
config.json
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"architectures": [
|
||||||
|
"LlamaForCausalLM"
|
||||||
|
],
|
||||||
|
"attention_bias": false,
|
||||||
|
"attention_dropout": 0.0,
|
||||||
|
"bos_token_id": 128000,
|
||||||
|
"torch_dtype": "bfloat16",
|
||||||
|
"eos_token_id": 128009,
|
||||||
|
"head_dim": 128,
|
||||||
|
"hidden_act": "silu",
|
||||||
|
"hidden_size": 3072,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 8192,
|
||||||
|
"max_position_embeddings": 131072,
|
||||||
|
"mlp_bias": false,
|
||||||
|
"model_type": "llama",
|
||||||
|
"num_attention_heads": 24,
|
||||||
|
"num_hidden_layers": 28,
|
||||||
|
"num_key_value_heads": 8,
|
||||||
|
"pad_token_id": 128004,
|
||||||
|
"pretraining_tp": 1,
|
||||||
|
"rms_norm_eps": 1e-05,
|
||||||
|
"rope_scaling": {
|
||||||
|
"factor": 32.0,
|
||||||
|
"high_freq_factor": 4.0,
|
||||||
|
"low_freq_factor": 1.0,
|
||||||
|
"original_max_position_embeddings": 8192,
|
||||||
|
"rope_type": "llama3"
|
||||||
|
},
|
||||||
|
"rope_theta": 500000.0,
|
||||||
|
"tie_word_embeddings": true,
|
||||||
|
"unsloth_fixed": true,
|
||||||
|
"unsloth_version": "2026.3.8",
|
||||||
|
"use_cache": true,
|
||||||
|
"vocab_size": 128256
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user