commit 5d5f90bf9805ee6a089d638a8337223bb1e92cfe Author: ModelHub XC Date: Wed Jun 17 13:06:18 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: Alindstroem89/Llama-3.2-1B-Instruct_guardrail Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..55814d2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,39 @@ +*.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.F16.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-1B-Instruct.F16.gguf filter=lfs diff=lfs merge=lfs -text +Llama-3.2-1B-Instruct.Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text diff --git a/Llama-3.2-1B-Instruct.F16.gguf b/Llama-3.2-1B-Instruct.F16.gguf new file mode 100644 index 0000000..d67942e --- /dev/null +++ b/Llama-3.2-1B-Instruct.F16.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08846ba6f08669e931e810f642949e4bfd24cb5d097f6f7c07ce71d1489c5274 +size 2479596032 diff --git a/Llama-3.2-1B-Instruct.Q4_K_M.gguf b/Llama-3.2-1B-Instruct.Q4_K_M.gguf new file mode 100644 index 0000000..3250d59 --- /dev/null +++ b/Llama-3.2-1B-Instruct.Q4_K_M.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a68a68de09b996bb9b4fb4616de3e494ffd384096c5f47b5322c466f2464fc93 +size 807694848 diff --git a/Modelfile b/Modelfile new file mode 100644 index 0000000..5414c7b --- /dev/null +++ b/Modelfile @@ -0,0 +1,57 @@ + +FROM Llama-3.2-1B-Instruct.Q4_K_M.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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1dc8a08 --- /dev/null +++ b/README.md @@ -0,0 +1,100 @@ +--- +datasets: +- Alindstroem89/guardrail-training-dataset +language: +- en +base_model: +- unsloth/Llama-3.2-1B-Instruct-GGUF +pipeline_tag: text-generation +tags: +- gguf +- llama.cpp +- unsloth +--- + +# Llama-3.2-1B-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-1B-Instruct](https://huggingface.co/unsloth/Llama-3.2-1B-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-1B-Instruct_guardrail:F16 --jinja +``` + +### Download with Hugging Face CLI + +```bash +# Download all GGUF files +hf download Alindstroem89/Llama-3.2-1B-Instruct_guardrail --include "*.gguf" --local-dir ./models + +# Download specific quantization +hf download Alindstroem89/Llama-3.2-1B-Instruct_guardrail --include "Llama-3.2-1B-Instruct.Q4_K_M.gguf" --local-dir ./models +``` + +### Ollama + +An Ollama Modelfile is included for easy deployment. + +## Available Model Files + +- Llama-3.2-1B-Instruct.Q4_K_M.gguf +- Llama-3.2-1B-Instruct.F16.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. \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..6ada842 --- /dev/null +++ b/config.json @@ -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": 64, + "hidden_act": "silu", + "hidden_size": 2048, + "initializer_range": 0.02, + "intermediate_size": 8192, + "max_position_embeddings": 131072, + "mlp_bias": false, + "model_type": "llama", + "num_attention_heads": 32, + "num_hidden_layers": 16, + "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 +} \ No newline at end of file