X-zy-0816/CoT-Malicious-Fine-tuning

CoT fine-tuning attack

19

stars

3

commits

Jupyter Notebook

primary language

Aug 31, 2026

updated

dl.acm.org/doi/10.1145/3779208.3785271

README

[ASIACCS 2026]Artefact for 'Paper Reasoning That Leaks, Fine-Tuning That Amplifies: Exposing the Hidden Threats of Chain-of-Thought Models'

This repository includes scripts for dataset preparation, evaluation & fine-tuning (10, 20, 50, 200) datasets, model fine-tuning using PEFT techniques (like LoRA), and tools for generating and evaluating potentially harmful outputs from language models.


📁 Repository Structure

🔧 Core Scripts

  • prepDataset.py Preprocesses raw datasets into instruction-style formats tailored for specific model architectures (e.g., Mistral, DeepSeek-R1). Easily customizable.

  • harmfulLora.py Fine-tunes models based on config.json using:

    • LoRA / PEFT (Parameter-Efficient Fine-Tuning)
    • Prefix tuning
    • Full SFT (Supervised Fine-Tuning)
      Outputs can be:
    • Uploaded to the Hugging Face Hub
    • Saved locally
  • loadModel.py Loads and tests inference of fine-tuned models in server environments. Useful for deployment validation.

  • config.json (user-provided)
    Central configuration file defining:

    • Model path or name
    • Dataset paths
    • Training hyperparameters
    • PEFT configs

🛠️ Utility Tools

  • convertGGUF.py Converts fine-tuned models to GGUF format (e.g., for use with llama.cpp) via the unsloth library.

  • configuation.py Reads and parses the central config.json into usable Python objects.

  • dataSampling.py Used to generate fine-tuning and evaluation subsets from raw datasets.

  • responseSeparation.py Splits generated responses into reasoning steps (e.g., "think") and final answers, saving them into distinct columns.

  • scoreExtraction.py Parses judgment scores from LLM evaluators and saves structured results.

  • datacleaning.py Temporary cleaning utility – not directly related to the main pipeline.


⚠️ Harmfulness Evaluation

  • textCompletetionHarmful.py Uses the fine-tuned (attacked) model to generate potentially harmful outputs. Helps evaluate adversarial vulnerability.

  • textCompletetionHarmless.py Uses the base (unmodified) model to generate outputs for comparison in safety benchmarking.

  • outputClassifyHarmBench.py Applies HarmBench classifiers to generated outputs to determine harmfulness and attack success rates.

  • gptJudger.py Uses OpenAI APIs to assign harmfulness scores via LLM-based judging (Gemini, Gork, Chatgpt, DeepSeekV3, DeepSeeekR1).


🚀 Usage Instructions

  1. Create a config.json file with all required settings (see template or examples).
  2. Run prepDataset.py to format your dataset.
  3. Fine-tune with harmfulLora.py.
  4. Evaluate safety using harmfulness generation and judgment scripts.

📝 Citation

If you find this repository or our paper useful in your research, please consider citing our work:

@inproceedings{xu2026reasoning,
  title={Reasoning That Leaks, Fine-Tuning That Amplifies: Exposing the Hidden Threats of Chain-of-Thought Models},
  author={Xu, Zhiyuan and Gardiner, Joseph and Belguith, Sana},
  booktitle={Proceedings of the ACM Asia Conference on Computer and Communications Security},
  pages={439--455},
  year={2026}
}

Contributors

X-zy-0816

3 commits

X-zy-0816/CoT-Malicious-Fine-tuning

CoT fine-tuning attack

19

stars

3

commits

Jupyter Notebook

primary language

Aug 31, 2026

updated

dl.acm.org/doi/10.1145/3779208.3785271

README

[ASIACCS 2026]Artefact for 'Paper Reasoning That Leaks, Fine-Tuning That Amplifies: Exposing the Hidden Threats of Chain-of-Thought Models'

This repository includes scripts for dataset preparation, evaluation & fine-tuning (10, 20, 50, 200) datasets, model fine-tuning using PEFT techniques (like LoRA), and tools for generating and evaluating potentially harmful outputs from language models.


📁 Repository Structure

🔧 Core Scripts

  • prepDataset.py Preprocesses raw datasets into instruction-style formats tailored for specific model architectures (e.g., Mistral, DeepSeek-R1). Easily customizable.

  • harmfulLora.py Fine-tunes models based on config.json using:

    • LoRA / PEFT (Parameter-Efficient Fine-Tuning)
    • Prefix tuning
    • Full SFT (Supervised Fine-Tuning)
      Outputs can be:
    • Uploaded to the Hugging Face Hub
    • Saved locally
  • loadModel.py Loads and tests inference of fine-tuned models in server environments. Useful for deployment validation.

  • config.json (user-provided)
    Central configuration file defining:

    • Model path or name
    • Dataset paths
    • Training hyperparameters
    • PEFT configs

🛠️ Utility Tools

  • convertGGUF.py Converts fine-tuned models to GGUF format (e.g., for use with llama.cpp) via the unsloth library.

  • configuation.py Reads and parses the central config.json into usable Python objects.

  • dataSampling.py Used to generate fine-tuning and evaluation subsets from raw datasets.

  • responseSeparation.py Splits generated responses into reasoning steps (e.g., "think") and final answers, saving them into distinct columns.

  • scoreExtraction.py Parses judgment scores from LLM evaluators and saves structured results.

  • datacleaning.py Temporary cleaning utility – not directly related to the main pipeline.


⚠️ Harmfulness Evaluation

  • textCompletetionHarmful.py Uses the fine-tuned (attacked) model to generate potentially harmful outputs. Helps evaluate adversarial vulnerability.

  • textCompletetionHarmless.py Uses the base (unmodified) model to generate outputs for comparison in safety benchmarking.

  • outputClassifyHarmBench.py Applies HarmBench classifiers to generated outputs to determine harmfulness and attack success rates.

  • gptJudger.py Uses OpenAI APIs to assign harmfulness scores via LLM-based judging (Gemini, Gork, Chatgpt, DeepSeekV3, DeepSeeekR1).


🚀 Usage Instructions

  1. Create a config.json file with all required settings (see template or examples).
  2. Run prepDataset.py to format your dataset.
  3. Fine-tune with harmfulLora.py.
  4. Evaluate safety using harmfulness generation and judgment scripts.

📝 Citation

If you find this repository or our paper useful in your research, please consider citing our work:

@inproceedings{xu2026reasoning,
  title={Reasoning That Leaks, Fine-Tuning That Amplifies: Exposing the Hidden Threats of Chain-of-Thought Models},
  author={Xu, Zhiyuan and Gardiner, Joseph and Belguith, Sana},
  booktitle={Proceedings of the ACM Asia Conference on Computer and Communications Security},
  pages={439--455},
  year={2026}
}

Contributors

X-zy-0816

3 commits

Languages

Jupyter Notebook

81.7%

Python

18.3%