This guide provides detailed steps for fully fine-tuning the AVLLM model using the LLaMA Factory framework.
Follow these instructions to set up your environment, prepare your model and datasets, and perform fine-tuning and evaluations.
-
Clone the LLaMA Factory Repository
Clone the repository to your home directory:
git clone https://github.com/hiyouga/LLaMA-Factory.git
-
Create and Activate a Conda Environment
Create a new Conda environment named AVLLM and activate it:
conda create -n AVLLM python=3.10 conda activate AVLLM
-
Install Dependencies
Navigate to the LLaMA-Factory directory and install the required dependencies:
cd LLaMA-Factory pip install -r requirements.txt
-
Download the Model
Download the TinyLlama model from Hugging Face and place it in the
model_path
directory:- Model URL: TinyLlama-1.1B-intermediate-step-1431k-3T
-
Prepare the Datasets
Download your fine-tuning dataset
AVLLM_train.json
and testing datasetAVLLM_test.json
. Load these datasets into theLLaMA-Factory/data
directory and update thedataset_info.json
file to include:"AVLLM-train": { "file_name": "AVLLM_train.json" }, "AVLLM-test": { "file_name": "AVLLM_test.json" }
-
Configure the Fine-Tuning Script
In the
llama_factory
directory, create or modify thefull-ft.sh
script. -
Configure DeepSpeed
Create or modify thedeepspeed.json
file. -
Execute the Fine-Tuning Script
Run the fine-tuning script:sh full-ft.sh
-
Install TextAttack
Install TextAttack for generating adversarial examples:pip install textattack
-
Generate Adversarial Examples
Use the following command to generate adversarial examples for evaluation:sh generate_example.sh
-
Prepare Evaluation Data
-Store the generated adversarial examples as
attack_example.csv
.
-Process this file using data_processing.py to format it for AVLLM inference.
-Load the resultingevaluation.json
into theLLaMA-Factory/data directory
and updatedataset_info.json
:"AVLLM-evaluation": { "file_name": "evaluation.json" }
-
Run Inference and Evaluation
Use the
predict.sh
script for inference, and then evaluate the ASR withevaluation.py
.sh predict.sh python evaluation.py
- Add Custom Module
Place your module intextattack/constraints/semantics/tinyllama.py
and updatetextattack/attack_args.py
to include your module in theCONSTRAINT_CLASS_NAMES
:"tinyllama": "textattack.constraints.semantics.Tinyllama"
- API Call Setup
Set up an API call by runningserver.py
and adjust the address intinyllama.py
accordingly.python server.py
- Run Attack Command
Execute the following command to run your attack module:sh patch.sh