Instructions to use ericyinyzy/SafeMLLM-LLaVA-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ericyinyzy/SafeMLLM-LLaVA-7B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("/data/ziyi/LLaVA15/LLaVA/checkpoints/llava-v1.5-7b") model = PeftModel.from_pretrained(base_model, "ericyinyzy/SafeMLLM-LLaVA-7B") - Notebooks
- Google Colab
- Kaggle
Add proper README
Browse files
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
library_name: peft
|
| 5 |
+
base_model: liuhaotian/llava-v1.5-7b
|
| 6 |
+
tags:
|
| 7 |
+
- llava
|
| 8 |
+
- multimodal
|
| 9 |
+
- adversarial-robustness
|
| 10 |
+
- jailbreak-defense
|
| 11 |
+
- safemllm
|
| 12 |
+
- lora
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# SafeMLLM-LLaVA-7B
|
| 16 |
+
|
| 17 |
+
LoRA adapter that turns **[liuhaotian/llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b)**
|
| 18 |
+
into a jailbreak-robust multimodal model, trained with the **SafeMLLM** framework
|
| 19 |
+
described in:
|
| 20 |
+
|
| 21 |
+
> **Towards Robust Multimodal Large Language Models Against Jailbreak Attacks**
|
| 22 |
+
> Ziyi Yin, Yuanpu Cao, Han Liu, Ting Wang, Jinghui Chen, Fenglong Ma — arXiv:[2502.00653](https://arxiv.org/abs/2502.00653) (2025).
|
| 23 |
+
|
| 24 |
+
## What is in this repo
|
| 25 |
+
|
| 26 |
+
A standard LoRA + projector adapter:
|
| 27 |
+
|
| 28 |
+
| File | What it is |
|
| 29 |
+
| -------------------------- | ---------------------------------------------------------- |
|
| 30 |
+
| `adapter_config.json` | PEFT LoRA config |
|
| 31 |
+
| `adapter_model.bin` | LoRA weights (rank-r updates on attention/MLP layers) |
|
| 32 |
+
| `non_lora_trainables.bin` | Vision-language projector weights (always trainable) |
|
| 33 |
+
| `config.json` | LLaVA model config snapshot |
|
| 34 |
+
| `trainer_state.json` | Training-time logs (steps / loss curve) |
|
| 35 |
+
|
| 36 |
+
To use it you also need the LLaVA-1.5-7B base weights from
|
| 37 |
+
[`liuhaotian/llava-v1.5-7b`](https://huggingface.co/liuhaotian/llava-v1.5-7b).
|
| 38 |
+
|
| 39 |
+
## Quick start
|
| 40 |
+
|
| 41 |
+
Clone the matching evaluation code:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
git clone https://github.com/ericyinyzy/SafeMLLM.git
|
| 45 |
+
cd SafeMLLM
|
| 46 |
+
conda env create -f environment.yml && conda activate safemllm-llava
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
Download both checkpoints:
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
mkdir -p checkpoints
|
| 53 |
+
huggingface-cli download liuhaotian/llava-v1.5-7b --local-dir checkpoints/llava-v1.5-7b
|
| 54 |
+
huggingface-cli download ericyinyzy/SafeMLLM-LLaVA-7B --local-dir checkpoints/SafeMLLM-LLaVA-7B
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Run any of the four evaluations (full pipeline shown):
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
export LLAVA7B_BASE=$PWD/checkpoints/llava-v1.5-7b
|
| 61 |
+
export SAFEMLLM_L7B=$PWD/checkpoints/SafeMLLM-LLaVA-7B
|
| 62 |
+
bash scripts/run_L7B.sh 0 # GPU id
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Programmatic loading (PEFT-style):
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from llava.model.builder import load_pretrained_model
|
| 69 |
+
from llava.mm_utils import get_model_name_from_path
|
| 70 |
+
|
| 71 |
+
tokenizer, model, image_processor, _ = load_pretrained_model(
|
| 72 |
+
model_path="ericyinyzy/SafeMLLM-LLaVA-7B",
|
| 73 |
+
model_base="liuhaotian/llava-v1.5-7b",
|
| 74 |
+
model_name=get_model_name_from_path("ericyinyzy/SafeMLLM-LLaVA-7B"),
|
| 75 |
+
)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Evaluation results (paper, Table 2 / Table 3)
|
| 79 |
+
|
| 80 |
+
This adapter — when paired with LLaVA-1.5-7B — substantially improves robustness
|
| 81 |
+
against ImgJP, FigStep and MM-SafetyBench attacks while preserving general
|
| 82 |
+
multimodal capability on MM-Vet. Refer to the paper for full numbers.
|
| 83 |
+
|
| 84 |
+
## Hardware requirements
|
| 85 |
+
|
| 86 |
+
| Use case | VRAM |
|
| 87 |
+
| ------------------- | ------ |
|
| 88 |
+
| Inference (fp16) | ~18 GB |
|
| 89 |
+
| ImgJP attack (PGD) | ~26 GB |
|
| 90 |
+
|
| 91 |
+
## License
|
| 92 |
+
|
| 93 |
+
Apache-2.0 for the adapter weights. The underlying LLaVA-1.5 base model retains
|
| 94 |
+
its own license; please check
|
| 95 |
+
[`liuhaotian/llava-v1.5-7b`](https://huggingface.co/liuhaotian/llava-v1.5-7b) for
|
| 96 |
+
those terms.
|
| 97 |
+
|
| 98 |
+
## Citation
|
| 99 |
+
|
| 100 |
+
```bibtex
|
| 101 |
+
@article{yin2025safemllm,
|
| 102 |
+
title = {Towards Robust Multimodal Large Language Models Against Jailbreak Attacks},
|
| 103 |
+
author = {Yin, Ziyi and Cao, Yuanpu and Liu, Han and Wang, Ting and Chen, Jinghui and Ma, Fenglong},
|
| 104 |
+
journal = {arXiv preprint arXiv:2502.00653},
|
| 105 |
+
year = {2025}
|
| 106 |
+
}
|
| 107 |
+
```
|